Allow consteval functions to return types by using the declarator typename auto. These functions would be evaluated at compile time and usable anywhere a type is expected.

Motivation

Rules (proposal)

Why


Current syntax:

template<int N>
struct select_type {
    using type = std::conditional_t<N == 0, int, double>;
};

using T = typename select_type<1>::type; // T == double

Proposed syntax:

consteval typename auto select_type(int n) {
    return n == 0 ? int : double;
}

or using the trailing type syntax

consteval auto select_type(int n) -> typename auto {
    return n == 0 ? int : double;
}

using T = select_type(1); // T == double

More examples

template<typename T>
consteval typename auto make_pointer_if(bool b) { 
    return b ? T* : T;
}

using A = make_pointer_if<int>(true);   // int*
using B = make_pointer_if<int>(false);  // int

tell me what you think.