C++ Logo

std-proposals

Advanced search

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

From: Muhammad <mail_at_[hidden]>
Date: Sun, 26 Oct 2025 19:59:46 +0000
Is the expression [: select_type(1) :] allowed any where a type is
expected (for instance as a default value for template parameter). If so
then yes this is what I was proposing.

------ Original Message ------
>From "Matthew Taylor" <mjtaylor214_at_[hidden]>
To "std-proposals_at_[hidden]" <std-proposals_at_[hidden]>
Cc "Muhammad" <mail_at_[hidden]>
Date 10/26/2025 10:52:47 PM
Subject Re: [std-proposals] consteval typename auto - type-returning
immediate functions

>Hi there Muhammad,
>
>What you're looking for is already possible in the reflection
>capabilities added in C++26 - you can return a std::meta::info which
>represents the reflection of a type and splice it to use that type.
>
>To rewrite one of your examples:
>
>consteval auto select_type(int n) {
> return n == 0 ? ^^int : ^^double;
>}
>
>Which can then be accessed in non-reflection code via
>
>using T = [: select_type(1) :];
>
>And this is just the tip of the iceberg in terms of what is possible
>with reflection and rewriting template patterns into something which
>more resembles typical C++ code.
>
>Does this about cover what you were wanting to make possible, or is
>there some extra layer to it which I've missed?
>

Received on 2025-10-26 19:59:52