// Copyright 2022 Peter Dimov // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt #include #include #include template struct fmt::formatter::value>> { private: using U = std::underlying_type_t; fmt::formatter sf_; fmt::formatter nf_; public: constexpr auto parse( format_parse_context& ctx ) { auto i1 = sf_.parse( ctx ); auto i2 = nf_.parse( ctx ); if( i1 != i2 ) { throw_format_error( "invalid format" ); } return i1; } auto format( T const& t, format_context& ctx ) const { char const * s = boost::describe::enum_to_string( t, 0 ); if( s ) { return sf_.format( s, ctx ); } else { return nf_.format( static_cast( t ), ctx ); } } }; enum E1 { v1, v2, v3 = 11 }; BOOST_DESCRIBE_ENUM( E1, v1, v2, v3 ) int main() { fmt::print( "{:_^10}\n", E1::v1 ); fmt::print( "{:_^10}\n", (E1)7 ); }