Date: Mon, 27 Oct 2025 10:33:25 +0000
On Sun, Oct 26, 2025 at 10:14 PM Thiago Macieira wrote:
>
> template<int N> constexpr auto select_type()
> {
> if constexpr (n == 0)
> return int{};
> else
> return double{}
> }
>
> using T = decltype(select_type<1>());
With regard to making this possible with consteval functions, I can't
get the following to compile, but I think I'm close:
https://godbolt.org/z/vd9f6jnTh
Ivan Lazaric introduced me to the "EDG - experimental reflection"
compiler up on GodBolt on this mailing list earlier in the year. Ivan,
are you able to get the above GodBolt to compile?
And here it is copy-pasted:
#include <experimental/meta>
#include <type_traits>
#include <iostream>
#include <typeinfo>
template<int N> constexpr auto select_type(void)
{
if constexpr ( 0 == N )
return int{};
else
return double{};
}
consteval auto Func(int const arg_n)
{
auto const value_reflection = std::meta::reflect_value(arg_n);
auto const fn_inst = std::meta::substitute(^select_type, {
value_reflection });
auto const ret_info = std::meta::return_type_of(fn_inst);
// The following line should work?
using T = :meta(std::meta::type_of(ret_info));
return T{};
}
int main(void)
{
typedef decltype(Func(7)) Type;
Type var;
var = 0;
}
>
> template<int N> constexpr auto select_type()
> {
> if constexpr (n == 0)
> return int{};
> else
> return double{}
> }
>
> using T = decltype(select_type<1>());
With regard to making this possible with consteval functions, I can't
get the following to compile, but I think I'm close:
https://godbolt.org/z/vd9f6jnTh
Ivan Lazaric introduced me to the "EDG - experimental reflection"
compiler up on GodBolt on this mailing list earlier in the year. Ivan,
are you able to get the above GodBolt to compile?
And here it is copy-pasted:
#include <experimental/meta>
#include <type_traits>
#include <iostream>
#include <typeinfo>
template<int N> constexpr auto select_type(void)
{
if constexpr ( 0 == N )
return int{};
else
return double{};
}
consteval auto Func(int const arg_n)
{
auto const value_reflection = std::meta::reflect_value(arg_n);
auto const fn_inst = std::meta::substitute(^select_type, {
value_reflection });
auto const ret_info = std::meta::return_type_of(fn_inst);
// The following line should work?
using T = :meta(std::meta::type_of(ret_info));
return T{};
}
int main(void)
{
typedef decltype(Func(7)) Type;
Type var;
var = 0;
}
Received on 2025-10-27 10:33:04
