C++ Logo

std-proposals

Advanced search

Re: [std-proposals] [[unevaluated]]

From: Jonathan Wakely <cxx_at_[hidden]>
Date: Thu, 21 May 2026 11:28:00 +0100
On Thu, 21 May 2026 at 05:13, Thiago Macieira via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> On Wednesday, 20 May 2026 12:45:01 Pacific Daylight Time Jonathan Wakely
> via
> Std-Proposals wrote:
> > It's been clear for years that he has no intention of doing anything
> except
> > wasting this list's time, and people are too tolerant of it IMHO.
>
> That doesn't mean all ideas are meritless. So other people can look at the
> half-baked proposal and come up with their own motivations and use-cases
> (which may end up bearing no relationship to what was the original intent)
> and
> take the proposal further.
>
> In this particular case, I think there's an extremely weak but non-zero
> motivation. There is one function in the standard library that would use
> it:
> std::declval. But the problem is already solved for that one, so the
> solution
> is available for other functions like it.
>

And you can compose other such functions out of decltype and declval.

The problem of not being able to call non-consteval functions in a
consteval function can be solved by calling them in an unevaluated context,
e.g. inside a decltype expression.

You can also write such a function so that it returns std::type_identity<T>
instead of T. That allows such functions to be used for non-copyable types,
or allows you to return a reference which would need to be bound to
something in the function body, requiring a static storage duration object
that you can bind a non-dangling reference to.

Adapting an example given:

consteval auto Func()
{
      if constexpr ( is_hosted ) return type_identity<GetHost>{};
      else if constexpr ( mylicense > max_licenses ) return
type_identity<GetRestrictedHost>{};
      else return type_identity<MonitoredHost&>{};
}

using Host_type = typename decltype(Func())::type;

This would work fine if you wanted one of the branches to make use of a
non-consteval function:

  return type_identity<decltype(gimmeHostPlz())>{};

Received on 2026-05-21 10:28:21