C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Default parameters should work with auto

From: Ell <ell.ell.se_at_[hidden]>
Date: Sun, 22 Mar 2026 11:50:04 +0000
On Sunday, March 22nd, 2026 at 10:25 AM, Ivan Lazaric via Std-Proposals
<std-proposals_at_[hidden]> wrote:

> Would it be possible/make sense/be better to default the template
> parameter to decltype of expression when possible?
>
> void func(auto arg = 0) { }
>
> // equivalent to:
>
> template<typename Arg = decltype(0)>
> void func(Arg arg = 0) { }

That's a nice way to specify it. It works for cases where the type of
the default argument depends on other template parameters, and even
cases where the arguments aren't being type-deduced, like:

    void func(auto arg = 0);
    auto p = func<>;

You just need some wording to allow the previous function parameters to
appear in (an unevaluated context of) the default argument, so you can
write:

    void func(auto x, auto y = decltype(x){});

even though `decltype(x){}` can't technically appear in the template head.

Received on 2026-03-22 11:50:14