Literal classes as non-type template parameters in C++20 -- Kevin Hartman

Using user-defined literal classes as non-type template parameters in C++20.

Literal classes as non-type template parameters in C++20

by Kevin Hartman

 

From the article:

/**
* Prints whether or not a value was provided for "maybe" WITHOUT branching smile
*/
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

You must sign in or register to add a comment.

Comments (0)

There are currently no comments on this entry.