C++ Logo

std-proposals

Advanced search

Re: [std-proposals] consteval typename auto - type-returning immediate functions

From: Thiago Macieira <thiago_at_[hidden]>
Date: Sun, 26 Oct 2025 15:14:40 -0700
On Sunday, 26 October 2025 12:43:54 Pacific Daylight Time Muhammad via Std-
Proposals wrote:
> consteval typename auto select_type(int n) {
> return n == 0 ? int : double;
> }

Already possible:

template<int N> constexpr auto select_type()
{
    if constexpr (n == 0)
        return int{};
    else
        return double{}
}

using T = decltype(select_type<1>());

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Principal Engineer - Intel Data Center Group

Received on 2025-10-26 22:14:50