1 1.1 joerg // -*- C++ -*- 2 1.1 joerg //===----------------- __utility/to_underlying.h --------------------------===// 3 1.1 joerg // 4 1.1 joerg // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 5 1.1 joerg // See https://llvm.org/LICENSE.txt for license information. 6 1.1 joerg // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7 1.1 joerg // 8 1.1 joerg //===----------------------------------------------------------------------===// 9 1.1 joerg 10 1.1 joerg #ifndef _LIBCPP___UTILITY_TO_UNDERLYING_H 11 1.1 joerg #define _LIBCPP___UTILITY_TO_UNDERLYING_H 12 1.1 joerg 13 1.1 joerg #include <__config> 14 1.1 joerg #include <type_traits> 15 1.1 joerg 16 1.1 joerg #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 17 1.1 joerg #pragma GCC system_header 18 1.1 joerg #endif 19 1.1 joerg 20 1.1 joerg _LIBCPP_PUSH_MACROS 21 1.1 joerg #include <__undef_macros> 22 1.1 joerg 23 1.1 joerg _LIBCPP_BEGIN_NAMESPACE_STD 24 1.1 joerg 25 1.1 joerg #ifndef _LIBCPP_CXX03_LANG 26 1.1 joerg template <class _Tp> 27 1.1 joerg _LIBCPP_INLINE_VISIBILITY constexpr typename underlying_type<_Tp>::type 28 1.1 joerg __to_underlying(_Tp __val) noexcept { 29 1.1 joerg return static_cast<typename underlying_type<_Tp>::type>(__val); 30 1.1 joerg } 31 1.1 joerg #endif // !_LIBCPP_CXX03_LANG 32 1.1 joerg 33 1.1 joerg #if _LIBCPP_STD_VER > 20 34 1.1 joerg template <class _Tp> 35 1.1 joerg _LIBCPP_NODISCARD_EXT _LIBCPP_INLINE_VISIBILITY constexpr underlying_type_t<_Tp> 36 1.1 joerg to_underlying(_Tp __val) noexcept { 37 1.1 joerg return _VSTD::__to_underlying(__val); 38 1.1 joerg } 39 1.1 joerg #endif 40 1.1 joerg 41 1.1 joerg _LIBCPP_END_NAMESPACE_STD 42 1.1 joerg 43 1.1 joerg _LIBCPP_POP_MACROS 44 1.1 joerg 45 1.1 joerg #endif // _LIBCPP___UTILITY_TO_UNDERLYING_H 46