Backport fmt::underlying
Summary: Backport `fmt::underlying` to `third-party/fmt` so that it can be used for migration to fmt 8.x. This function can be used to format enum classes as underlying type and is similar to existing `fmt::ptr` for pointers.
@@ -3352,6 +3352,20 @@ template <> struct formatter<bytes> {
detail::dynamic_format_specs<char> specs_;
};
+/**
+ \rst
+ Converts ``e`` to the underlying type.
+ **Example**::
+ enum class color { red, green, blue };
+ auto s = fmt::format("{}", fmt::underlying(color::red));
+ \endrst
+ */
+template <typename Enum>
+constexpr auto underlying(Enum e) noexcept ->
+ typename std::underlying_type<Enum>::type {
+ return static_cast<typename std::underlying_type<Enum>::type>(e);
+}
+
template <typename It, typename Sentinel, typename Char>
struct arg_join : detail::view {
It begin;
