Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-03 08:14:06

0001 //===----------------------------------------------------------------------===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef _LIBCPP___UTILITY_CONVERT_TO_INTEGRAL_H
0010 #define _LIBCPP___UTILITY_CONVERT_TO_INTEGRAL_H
0011 
0012 #include <__config>
0013 #include <__type_traits/enable_if.h>
0014 #include <__type_traits/is_enum.h>
0015 #include <__type_traits/is_floating_point.h>
0016 #include <__type_traits/underlying_type.h>
0017 
0018 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0019 #  pragma GCC system_header
0020 #endif
0021 
0022 _LIBCPP_BEGIN_NAMESPACE_STD
0023 
0024 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __convert_to_integral(int __val) { return __val; }
0025 
0026 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR unsigned __convert_to_integral(unsigned __val) { return __val; }
0027 
0028 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR long __convert_to_integral(long __val) { return __val; }
0029 
0030 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR unsigned long __convert_to_integral(unsigned long __val) {
0031   return __val;
0032 }
0033 
0034 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR long long __convert_to_integral(long long __val) { return __val; }
0035 
0036 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR unsigned long long __convert_to_integral(unsigned long long __val) {
0037   return __val;
0038 }
0039 
0040 template <typename _Fp, __enable_if_t<is_floating_point<_Fp>::value, int> = 0>
0041 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR long long __convert_to_integral(_Fp __val) {
0042   return __val;
0043 }
0044 
0045 #if _LIBCPP_HAS_INT128
0046 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __int128_t __convert_to_integral(__int128_t __val) { return __val; }
0047 
0048 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __uint128_t __convert_to_integral(__uint128_t __val) { return __val; }
0049 #endif
0050 
0051 template <class _Tp, bool = is_enum<_Tp>::value>
0052 struct __sfinae_underlying_type {
0053   typedef typename underlying_type<_Tp>::type type;
0054   typedef decltype(((type)1) + 0) __promoted_type;
0055 };
0056 
0057 template <class _Tp>
0058 struct __sfinae_underlying_type<_Tp, false> {};
0059 
0060 template <class _Tp>
0061 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR typename __sfinae_underlying_type<_Tp>::__promoted_type
0062 __convert_to_integral(_Tp __val) {
0063   return __val;
0064 }
0065 
0066 _LIBCPP_END_NAMESPACE_STD
0067 
0068 #endif // _LIBCPP___UTILITY_CONVERT_TO_INTEGRAL_H