C++ Logo

std-proposals

Advanced search

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

From: Thiago Macieira <thiago_at_[hidden]>
Date: Tue, 20 May 2025 16:54:06 -0700
On Tuesday, 20 May 2025 15:17:41 Pacific Daylight Time Frederick Virchanza
Gotham via Std-Proposals wrote:
> A few changes need to be made to template metaprogramming in C++.

That statement is probably true in general terms, but not for the reasons in
your email.

> template<typename T>
> decltype(auto) Func(void)
> {
> return std::declval<T&>().begin();
> }

    return decltype(std::declval<T &>().begin()){};

Assuming it is constructible and copyable/movable. It probably is, because
otherwise your proposed solution wouldn't have worked.

If it isn't, then you can return it as part of a type_identity.

  return std::type_identity<decltype(std::declval<T&>().begin())>{};

Then extract that one's ::type where needed. Which is something Jonathan
already suggested.

> The next thing to address is that 'declval' isn't good enough. It can
> make an Lvalue or an Xvalue, but it can't make a PRvalue. Making a
> change to 'declval' in C++29 would break existing code, so I propose
>
> the introduction of a new standard library function:
> template<typename T>
> [[unevaluated]] consteval remove_cvref_t<T> prvalue(void) noexcept
>
> This function will return a PRvalue for any type T (removing the
> reference from T if necessary).

I don't know this is needed. Maybe it is, I've seen code like:

  decltype(std::declval<T (*)()>()())

If you have a use-case for this library addition, write a paper.

> Programmers can continue to use "declval" if they want to (or maybe
> deprecate it at some point).

Explain that in your paper.
-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Principal Engineer - Intel DCAI Platform & System Engineering

Received on 2025-05-20 23:54:13