C++ Logo


Advanced search

Re: [std-proposals] Explicit keyword for template parameters

From: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>
Date: Sat, 30 Apr 2022 11:04:17 +0100
On Saturday, April 30, 2022, Jens Maurer <Jens.Maurer_at_[hidden]> wrote:

> If you want to disable template argument deduction for a function
> parameter,
> just do it (see [meta.trans.other]):
> template<class T>
> /* whatever */ Add_Or_Max(std::type_identity_t<T> const a,
> std::type_identity_t<T> const b);
> Since T only appears in non-deduced contexts, a user needs to specify
> it explicitly in the template-argument-list of the function call.

Nobody wants to open up a colleague's SVN commit and scroll down through
code that looks like that. It isn't streamlined to read, especially when
you're thinking about 2 or 3 things at once, and then you have to think "oh
I know that trick there with type_identity_t". The following is much more
minimalist and easy to understand at a glance:

    template<explicit class T>
    T Add_Or_Max(T a, T b);

We designers of computer programming languages (or we hobbyists with an
interest in designing computer programming languages), must empower the
programmer to write minimal clean code to get the job done well -- such as
when 'virtual' methods were invented so that we could have abstract base

I know that we can use 'type_identity_t' here but it's clunky syntax which
interrupts the reader's train of thought. Also it involves including a
standard header file <type_traits> simply just to declare a function.

Received on 2022-04-30 10:04:18