1 //===----------------------------------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #ifndef _LIBCPP___CXX03___UTILITY_CONVERT_TO_INTEGRAL_H 10 #define _LIBCPP___CXX03___UTILITY_CONVERT_TO_INTEGRAL_H 11 12 #include <__cxx03/__config> 13 #include <__cxx03/__type_traits/enable_if.h> 14 #include <__cxx03/__type_traits/is_enum.h> 15 #include <__cxx03/__type_traits/is_floating_point.h> 16 #include <__cxx03/__type_traits/underlying_type.h> 17 18 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 19 # pragma GCC system_header 20 #endif 21 22 _LIBCPP_BEGIN_NAMESPACE_STD 23 __convert_to_integral(int __val)24inline _LIBCPP_HIDE_FROM_ABI int __convert_to_integral(int __val) { return __val; } 25 __convert_to_integral(unsigned __val)26inline _LIBCPP_HIDE_FROM_ABI unsigned __convert_to_integral(unsigned __val) { return __val; } 27 __convert_to_integral(long __val)28inline _LIBCPP_HIDE_FROM_ABI long __convert_to_integral(long __val) { return __val; } 29 __convert_to_integral(unsigned long __val)30inline _LIBCPP_HIDE_FROM_ABI unsigned long __convert_to_integral(unsigned long __val) { return __val; } 31 __convert_to_integral(long long __val)32inline _LIBCPP_HIDE_FROM_ABI long long __convert_to_integral(long long __val) { return __val; } 33 __convert_to_integral(unsigned long long __val)34inline _LIBCPP_HIDE_FROM_ABI unsigned long long __convert_to_integral(unsigned long long __val) { return __val; } 35 36 template <typename _Fp, __enable_if_t<is_floating_point<_Fp>::value, int> = 0> __convert_to_integral(_Fp __val)37inline _LIBCPP_HIDE_FROM_ABI long long __convert_to_integral(_Fp __val) { 38 return __val; 39 } 40 41 #ifndef _LIBCPP_HAS_NO_INT128 __convert_to_integral(__int128_t __val)42inline _LIBCPP_HIDE_FROM_ABI __int128_t __convert_to_integral(__int128_t __val) { return __val; } 43 __convert_to_integral(__uint128_t __val)44inline _LIBCPP_HIDE_FROM_ABI __uint128_t __convert_to_integral(__uint128_t __val) { return __val; } 45 #endif 46 47 template <class _Tp, bool = is_enum<_Tp>::value> 48 struct __sfinae_underlying_type { 49 typedef typename underlying_type<_Tp>::type type; 50 typedef decltype(((type)1) + 0) __promoted_type; 51 }; 52 53 template <class _Tp> 54 struct __sfinae_underlying_type<_Tp, false> {}; 55 56 template <class _Tp> 57 inline _LIBCPP_HIDE_FROM_ABI typename __sfinae_underlying_type<_Tp>::__promoted_type __convert_to_integral(_Tp __val) { 58 return __val; 59 } 60 61 _LIBCPP_END_NAMESPACE_STD 62 63 #endif // _LIBCPP___CXX03___UTILITY_CONVERT_TO_INTEGRAL_H 64