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