C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Explicitly specifying default arguments

From: Bo Persson <bo_at_[hidden]>
Date: Wed, 1 Feb 2023 14:19:17 +0100
On 2023-02-01 at 13:56, Andrey Semashev via Std-Proposals wrote:
> Hi,
>
> Would it be possible to be able to explicitly specify default arguments
> for template specializations and function calls?
>
> void foo(int x, int y = 10, int z = 20);
>
> foo(1, default, 3); // == foo(1, 10, 3);
>
>
> // Use default ordering function
> typedef std::set< int, default, my_alloc > my_set;
>
> // Use default compare and hash functions
> typedef std::unordered_set< int, default, default, my_alloc > my_uset;
>
>
> template<
> typename T,
> typename = whatever,
> bool = is_special< T >::value
> >
> struct trait {};
>
> // Specialization: trait< T, whatever, true >
> template< typename T >
> struct trait< T, default, true > {};
>
> This syntax is currently invalid, so the extension would be pretty
> harmless. This would allow to avoid code duplication, where the user of
> the function or template, or the one who specializes the template, has
> to duplicate the default argument when he only needs to specify the
> arguments after that.

This seems to have been proposed 20 years ago.

https://wg21.link/N1466

Didn't go anywhere.

Received on 2023-02-01 13:19:28