Path: blob/main/contrib/llvm-project/libcxx/include/__utility/convert_to_integral.h
35236 views
//===----------------------------------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#ifndef _LIBCPP___UTILITY_CONVERT_TO_INTEGRAL_H9#define _LIBCPP___UTILITY_CONVERT_TO_INTEGRAL_H1011#include <__config>12#include <__type_traits/enable_if.h>13#include <__type_traits/is_enum.h>14#include <__type_traits/is_floating_point.h>15#include <__type_traits/underlying_type.h>1617#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)18# pragma GCC system_header19#endif2021_LIBCPP_BEGIN_NAMESPACE_STD2223inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __convert_to_integral(int __val) { return __val; }2425inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR unsigned __convert_to_integral(unsigned __val) { return __val; }2627inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR long __convert_to_integral(long __val) { return __val; }2829inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR unsigned long __convert_to_integral(unsigned long __val) {30return __val;31}3233inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR long long __convert_to_integral(long long __val) { return __val; }3435inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR unsigned long long __convert_to_integral(unsigned long long __val) {36return __val;37}3839template <typename _Fp, __enable_if_t<is_floating_point<_Fp>::value, int> = 0>40inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR long long __convert_to_integral(_Fp __val) {41return __val;42}4344#ifndef _LIBCPP_HAS_NO_INT12845inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __int128_t __convert_to_integral(__int128_t __val) { return __val; }4647inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __uint128_t __convert_to_integral(__uint128_t __val) { return __val; }48#endif4950template <class _Tp, bool = is_enum<_Tp>::value>51struct __sfinae_underlying_type {52typedef typename underlying_type<_Tp>::type type;53typedef decltype(((type)1) + 0) __promoted_type;54};5556template <class _Tp>57struct __sfinae_underlying_type<_Tp, false> {};5859template <class _Tp>60inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR typename __sfinae_underlying_type<_Tp>::__promoted_type61__convert_to_integral(_Tp __val) {62return __val;63}6465_LIBCPP_END_NAMESPACE_STD6667#endif // _LIBCPP___UTILITY_CONVERT_TO_INTEGRAL_H686970