xso::generator — Custom Formatting

We specialize the std::formatter class to connect any xso::generator, State, or Scrambler class to std::format and friends.

All of our classes have a class method xso_name() that returns a suitable name string.

We define a C++ concept to capture that common feature:

template<typename T>
concept has_xso_name_class_method = requires {
    { T::xso_name() } -> std::convertible_to<std::string>;
};

We use that concept to specialize the template [std::formatter] struct appropriately:

template<has_xso_name_class_method T>
struct std::formatter<T> {
    ...
};

We can also define the usual output stream operator:

template<has_xso_name_class_method T>
std::ostream &
operator<<(std::ostream &s, const T& rhs);

See Also

xso_name
std::formatter

Back to top