Using user-defined literal classes as non-type template parameters in C++20.
Literal classes as non-type template parameters in C++20
From the article:
/** * Prints whether or not a value was provided for "maybe" WITHOUT branching */ template<OptionalInt maybe> void Print() { if constexpr(maybe.has_value) { std::cout << "Value is: " << maybe.value << std::endl; } else { std::cout << "No value." << std::endl; } }
[intermediate][C++20]
Add a Comment