Skip to content

Add to_underlying To utility.h #1037

@drewr95

Description

@drewr95

I think it would be nice to add the to_underlying function that was added C++23. I've implemented it locally on my C++14 codebase and figured it could be useful here.

#include <type_traits>

/**
 * @brief Converts an enum class value to it's underlying type'd value.
 *
 * @tparam Enum: Enum class type.
 * @param e: Enum class value.
 * @return constexpr auto
 */
template <typename Enum>
constexpr auto to_underlying(const Enum e) noexcept ->
    typename std::underlying_type_t<Enum>
{
    return static_cast<typename std::underlying_type_t<Enum>>(e);
}

Metadata

Metadata

Assignees

No one assigned

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions