C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Explicit template parameters

From: Bo Persson <bo_at_[hidden]>
Date: Sun, 3 Jul 2022 14:49:13 +0200
On 2022-07-03 at 14:02, Frederick Virchanza Gotham via Std-Proposals wrote:
>
> Earlier this year on 25 March, I shared my idea to this mailing list of
> using the 'explicit' keyword on template parameters as follows:
>
> template<explicit class T>
> void Func(T &arg)
> {
> /* Do Something */
> }
>
> The idea was that you would have to write:
>
> int main(void)
> {
> int i;
>
> Func<int>(i);
> }
>
> because the 'explicit' keyword would prevent automatic deduction of the
> type T.
>
> You can see my original post archived here:
>
> https://lists.isocpp.org/std-proposals/2022/03/3721.php
> <https://lists.isocpp.org/std-proposals/2022/03/3721.php>
>
> That same week, another contributor made another suggestion that looked
> similar to what I was suggesting, but which was very different in
> functionality. My own suggestion I think got lost in the paperwork back
> and forth, and so I would like to bring it to people's attention again
> now, as I've shared the idea elsewhere and people seeming to be
> overwhelming in support of it.
>

The standard already has type_identity, added specifically for this purpose.

https://en.cppreference.com/w/cpp/types/type_identity

template<class T>
void func(std::type_identity_t<T>& arg);

Do we really need one more way to do this?

Received on 2022-07-03 12:49:45