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___RANDOM_IS_VALID_H 10 #define _LIBCPP___RANDOM_IS_VALID_H 11 12 #include <__config> 13 #include <__type_traits/enable_if.h> 14 #include <__type_traits/integral_constant.h> 15 #include <__type_traits/is_same.h> 16 #include <__type_traits/is_unsigned.h> 17 #include <__utility/declval.h> 18 #include <cstdint> 19 20 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 21 # pragma GCC system_header 22 #endif 23 24 _LIBCPP_BEGIN_NAMESPACE_STD 25 26 // [rand.req.genl]/1.4: 27 // The effect of instantiating a template that has a template type parameter 28 // named RealType is undefined unless the corresponding template argument is 29 // cv-unqualified and is one of float, double, or long double. 30 31 template <class> 32 struct __libcpp_random_is_valid_realtype : false_type {}; 33 template <> 34 struct __libcpp_random_is_valid_realtype<float> : true_type {}; 35 template <> 36 struct __libcpp_random_is_valid_realtype<double> : true_type {}; 37 template <> 38 struct __libcpp_random_is_valid_realtype<long double> : true_type {}; 39 40 // [rand.req.genl]/1.5: 41 // The effect of instantiating a template that has a template type parameter 42 // named IntType is undefined unless the corresponding template argument is 43 // cv-unqualified and is one of short, int, long, long long, unsigned short, 44 // unsigned int, unsigned long, or unsigned long long. 45 46 template<class> struct __libcpp_random_is_valid_inttype : false_type {}; 47 template<> struct __libcpp_random_is_valid_inttype<int8_t> : true_type {}; // extension 48 template<> struct __libcpp_random_is_valid_inttype<short> : true_type {}; 49 template<> struct __libcpp_random_is_valid_inttype<int> : true_type {}; 50 template<> struct __libcpp_random_is_valid_inttype<long> : true_type {}; 51 template<> struct __libcpp_random_is_valid_inttype<long long> : true_type {}; 52 template<> struct __libcpp_random_is_valid_inttype<uint8_t> : true_type {}; // extension 53 template<> struct __libcpp_random_is_valid_inttype<unsigned short> : true_type {}; 54 template<> struct __libcpp_random_is_valid_inttype<unsigned int> : true_type {}; 55 template<> struct __libcpp_random_is_valid_inttype<unsigned long> : true_type {}; 56 template<> struct __libcpp_random_is_valid_inttype<unsigned long long> : true_type {}; 57 58 #ifndef _LIBCPP_HAS_NO_INT128 59 template<> struct __libcpp_random_is_valid_inttype<__int128_t> : true_type {}; // extension 60 template<> struct __libcpp_random_is_valid_inttype<__uint128_t> : true_type {}; // extension 61 #endif // _LIBCPP_HAS_NO_INT128 62 63 // [rand.req.urng]/3: 64 // A class G meets the uniform random bit generator requirements if G models 65 // uniform_random_bit_generator, invoke_result_t<G&> is an unsigned integer type, 66 // and G provides a nested typedef-name result_type that denotes the same type 67 // as invoke_result_t<G&>. 68 // (In particular, reject URNGs with signed result_types; our distributions cannot 69 // handle such generator types.) 70 71 template<class, class = void> struct __libcpp_random_is_valid_urng : false_type {}; 72 template<class _Gp> struct __libcpp_random_is_valid_urng<_Gp, __enable_if_t< 73 is_unsigned<typename _Gp::result_type>::value && 74 _IsSame<decltype(std::declval<_Gp&>()()), typename _Gp::result_type>::value 75 > > : true_type {}; 76 77 _LIBCPP_END_NAMESPACE_STD 78 79 #endif // _LIBCPP___RANDOM_IS_VALID_H 80