Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-03 08:13:38

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___CXX03___RANDOM_IS_VALID_H
0010 #define _LIBCPP___CXX03___RANDOM_IS_VALID_H
0011 
0012 #include <__cxx03/__config>
0013 #include <__cxx03/__type_traits/enable_if.h>
0014 #include <__cxx03/__type_traits/integral_constant.h>
0015 #include <__cxx03/__type_traits/is_same.h>
0016 #include <__cxx03/__type_traits/is_unsigned.h>
0017 #include <__cxx03/__utility/declval.h>
0018 #include <__cxx03/cstdint>
0019 
0020 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0021 #  pragma GCC system_header
0022 #endif
0023 
0024 _LIBCPP_BEGIN_NAMESPACE_STD
0025 
0026 // [rand.req.genl]/1.4:
0027 // The effect of instantiating a template that has a template type parameter
0028 // named RealType is undefined unless the corresponding template argument is
0029 // cv-unqualified and is one of float, double, or long double.
0030 
0031 template <class>
0032 struct __libcpp_random_is_valid_realtype : false_type {};
0033 template <>
0034 struct __libcpp_random_is_valid_realtype<float> : true_type {};
0035 template <>
0036 struct __libcpp_random_is_valid_realtype<double> : true_type {};
0037 template <>
0038 struct __libcpp_random_is_valid_realtype<long double> : true_type {};
0039 
0040 // [rand.req.genl]/1.5:
0041 // The effect of instantiating a template that has a template type parameter
0042 // named IntType is undefined unless the corresponding template argument is
0043 // cv-unqualified and is one of short, int, long, long long, unsigned short,
0044 // unsigned int, unsigned long, or unsigned long long.
0045 
0046 template <class>
0047 struct __libcpp_random_is_valid_inttype : false_type {};
0048 template <>
0049 struct __libcpp_random_is_valid_inttype<int8_t> : true_type {}; // extension
0050 template <>
0051 struct __libcpp_random_is_valid_inttype<short> : true_type {};
0052 template <>
0053 struct __libcpp_random_is_valid_inttype<int> : true_type {};
0054 template <>
0055 struct __libcpp_random_is_valid_inttype<long> : true_type {};
0056 template <>
0057 struct __libcpp_random_is_valid_inttype<long long> : true_type {};
0058 template <>
0059 struct __libcpp_random_is_valid_inttype<uint8_t> : true_type {}; // extension
0060 template <>
0061 struct __libcpp_random_is_valid_inttype<unsigned short> : true_type {};
0062 template <>
0063 struct __libcpp_random_is_valid_inttype<unsigned int> : true_type {};
0064 template <>
0065 struct __libcpp_random_is_valid_inttype<unsigned long> : true_type {};
0066 template <>
0067 struct __libcpp_random_is_valid_inttype<unsigned long long> : true_type {};
0068 
0069 #ifndef _LIBCPP_HAS_NO_INT128
0070 template <>
0071 struct __libcpp_random_is_valid_inttype<__int128_t> : true_type {}; // extension
0072 template <>
0073 struct __libcpp_random_is_valid_inttype<__uint128_t> : true_type {}; // extension
0074 #endif                                                               // _LIBCPP_HAS_NO_INT128
0075 
0076 // [rand.req.urng]/3:
0077 // A class G meets the uniform random bit generator requirements if G models
0078 // uniform_random_bit_generator, invoke_result_t<G&> is an unsigned integer type,
0079 // and G provides a nested typedef-name result_type that denotes the same type
0080 // as invoke_result_t<G&>.
0081 // (In particular, reject URNGs with signed result_types; our distributions cannot
0082 // handle such generator types.)
0083 
0084 template <class, class = void>
0085 struct __libcpp_random_is_valid_urng : false_type {};
0086 template <class _Gp>
0087 struct __libcpp_random_is_valid_urng<
0088     _Gp,
0089     __enable_if_t< is_unsigned<typename _Gp::result_type>::value &&
0090                    _IsSame<decltype(std::declval<_Gp&>()()), typename _Gp::result_type>::value > > : true_type {};
0091 
0092 _LIBCPP_END_NAMESPACE_STD
0093 
0094 #endif // _LIBCPP___CXX03___RANDOM_IS_VALID_H