to_underlying.hpp 562 B

1234567891011121314151617181920212223
  1. #ifndef BOOST_COMPAT_TO_UNDERLYING_HPP_INCLUDED
  2. #define BOOST_COMPAT_TO_UNDERLYING_HPP_INCLUDED
  3. // Copyright 2025 Braden Ganetsky
  4. // Distributed under the Boost Software License, Version 1.0.
  5. // https://www.boost.org/LICENSE_1_0.txt
  6. #include <type_traits>
  7. namespace boost {
  8. namespace compat {
  9. template <class E>
  10. constexpr typename std::underlying_type<E>::type to_underlying(E e) noexcept
  11. {
  12. return static_cast<typename std::underlying_type<E>::type>(e);
  13. }
  14. } // namespace compat
  15. } // namespace boost
  16. #endif // BOOST_COMPAT_TO_UNDERLYING_HPP_INCLUDED