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