Skip to content
This repository has been archived by the owner on May 1, 2023. It is now read-only.

Commit

Permalink
Backport fmt::underlying
Browse files Browse the repository at this point in the history
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.

Reviewed By: h-friederich

Differential Revision: D33744056

fbshipit-source-id: c17797d37e955892f3c9c44d2e590f227e4e401c
  • Loading branch information
vitaut authored and facebook-github-bot committed Jan 25, 2022
1 parent 96353d0 commit acc8bc0
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions deps/fmt/include/fmt/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit acc8bc0

Please sign in to comment.