39 lines · c
1// -*- C++ -*-2//===----------------------------------------------------------------------===//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-exception7//8//===----------------------------------------------------------------------===//9 10#ifndef _LIBCPP___UTILITY_TO_UNDERLYING_H11#define _LIBCPP___UTILITY_TO_UNDERLYING_H12 13#include <__config>14#include <__type_traits/underlying_type.h>15 16#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)17# pragma GCC system_header18#endif19 20_LIBCPP_BEGIN_NAMESPACE_STD21 22#ifndef _LIBCPP_CXX03_LANG23template <class _Tp>24[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI constexpr __underlying_type_t<_Tp> __to_underlying(_Tp __val) noexcept {25 return static_cast<__underlying_type_t<_Tp>>(__val);26}27#endif // !_LIBCPP_CXX03_LANG28 29#if _LIBCPP_STD_VER >= 2330template <class _Tp>31[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr underlying_type_t<_Tp> to_underlying(_Tp __val) noexcept {32 return std::__to_underlying(__val);33}34#endif35 36_LIBCPP_END_NAMESPACE_STD37 38#endif // _LIBCPP___UTILITY_TO_UNDERLYING_H39