Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add to_underlying To utility.h #1037

Open
drewr95 opened this issue Feb 28, 2025 · 2 comments
Open

Add to_underlying To utility.h #1037

drewr95 opened this issue Feb 28, 2025 · 2 comments

Comments

@drewr95
Copy link
Contributor

drewr95 commented Feb 28, 2025

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);
}
@jwellbelove
Copy link
Contributor

jwellbelove commented Mar 1, 2025

An etl::underlying_type, that doesn't reference the STL would need to be created to allow the use of no-STL platforms.

@drewr95
Copy link
Contributor Author

drewr95 commented Mar 10, 2025

Related PR: #1045

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants