1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef _LIBCPP___CXX03___RANDOM_IS_VALID_H
10 #define _LIBCPP___CXX03___RANDOM_IS_VALID_H
12 #include <__cxx03/__config>
13 #include <__cxx03/__type_traits/enable_if.h>
14 #include <__cxx03/__type_traits/integral_constant.h>
15 #include <__cxx03/__type_traits/is_same.h>
16 #include <__cxx03/__type_traits/is_unsigned.h>
17 #include <__cxx03/__utility/declval.h>
18 #include <__cxx03/cstdint>
20 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
21 # pragma GCC system_header
24 _LIBCPP_BEGIN_NAMESPACE_STD
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.
32 struct __libcpp_random_is_valid_realtype
: false_type
{};
34 struct __libcpp_random_is_valid_realtype
<float> : true_type
{};
36 struct __libcpp_random_is_valid_realtype
<double> : true_type
{};
38 struct __libcpp_random_is_valid_realtype
<long double> : true_type
{};
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.
47 struct __libcpp_random_is_valid_inttype
: false_type
{};
49 struct __libcpp_random_is_valid_inttype
<int8_t> : true_type
{}; // extension
51 struct __libcpp_random_is_valid_inttype
<short> : true_type
{};
53 struct __libcpp_random_is_valid_inttype
<int> : true_type
{};
55 struct __libcpp_random_is_valid_inttype
<long> : true_type
{};
57 struct __libcpp_random_is_valid_inttype
<long long> : true_type
{};
59 struct __libcpp_random_is_valid_inttype
<uint8_t> : true_type
{}; // extension
61 struct __libcpp_random_is_valid_inttype
<unsigned short> : true_type
{};
63 struct __libcpp_random_is_valid_inttype
<unsigned int> : true_type
{};
65 struct __libcpp_random_is_valid_inttype
<unsigned long> : true_type
{};
67 struct __libcpp_random_is_valid_inttype
<unsigned long long> : true_type
{};
69 #ifndef _LIBCPP_HAS_NO_INT128
71 struct __libcpp_random_is_valid_inttype
<__int128_t
> : true_type
{}; // extension
73 struct __libcpp_random_is_valid_inttype
<__uint128_t
> : true_type
{}; // extension
74 #endif // _LIBCPP_HAS_NO_INT128
77 // A class G meets the uniform random bit generator requirements if G models
78 // uniform_random_bit_generator, invoke_result_t<G&> is an unsigned integer type,
79 // and G provides a nested typedef-name result_type that denotes the same type
80 // as invoke_result_t<G&>.
81 // (In particular, reject URNGs with signed result_types; our distributions cannot
82 // handle such generator types.)
84 template <class, class = void>
85 struct __libcpp_random_is_valid_urng
: false_type
{};
87 struct __libcpp_random_is_valid_urng
<
89 __enable_if_t
< is_unsigned
<typename
_Gp::result_type
>::value
&&
90 _IsSame
<decltype(std::declval
<_Gp
&>()()), typename
_Gp::result_type
>::value
> > : true_type
{};
92 _LIBCPP_END_NAMESPACE_STD
94 #endif // _LIBCPP___CXX03___RANDOM_IS_VALID_H