atomgalaxy / isocpp-universal-template-param

We propose a way to spell a universal template parameter kind. This would allow for a generic apply and other higher-order template metafunctions, and certain typetraits.
https://atomgalaxy.github.io/isocpp-universal-template-param/d1985r0.pdf
2 stars 2 forks source link

Add example involving if constexpr (with braces!) #13

Closed BengtGustafsson closed 1 year ago

BengtGustafsson commented 1 year ago

Something like:

template<anyname P> void f()
{
    if constexpr (std::is_value_v<P>) {
         std::cout << P;                            // Default interpretation is value as P is a dependent name.
    }
    else if constexpr (std::is_typename_v<P>) {
         std::cout << ”A type of size” << sizeof(typename P);
    }
    else {
         std::cout << ”P is a template”;     // Note for future: Can’t know if P is a class or variable template.
    }
}
mpusz commented 1 year ago

I am not sure about the braces. I think they are not mandatory for if constexpr? They are mandatory for if consteval though as there is no parenthesis in the syntax.

BengtGustafsson commented 1 year ago

You're right. At least none of the compilers complain.