| 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___CXX03___RANDOM_IS_VALID_H |
| 10 |
#define _LIBCPP___CXX03___RANDOM_IS_VALID_H |
| 11 |
|
| 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> |
| 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> |
| 47 |
struct __libcpp_random_is_valid_inttype : false_type {}; |
| 48 |
template <> |
| 49 |
struct __libcpp_random_is_valid_inttype<int8_t> : true_type {}; // extension |
| 50 |
template <> |
| 51 |
struct __libcpp_random_is_valid_inttype<short> : true_type {}; |
| 52 |
template <> |
| 53 |
struct __libcpp_random_is_valid_inttype<int> : true_type {}; |
| 54 |
template <> |
| 55 |
struct __libcpp_random_is_valid_inttype<long> : true_type {}; |
| 56 |
template <> |
| 57 |
struct __libcpp_random_is_valid_inttype<long long> : true_type {}; |
| 58 |
template <> |
| 59 |
struct __libcpp_random_is_valid_inttype<uint8_t> : true_type {}; // extension |
| 60 |
template <> |
| 61 |
struct __libcpp_random_is_valid_inttype<unsigned short> : true_type {}; |
| 62 |
template <> |
| 63 |
struct __libcpp_random_is_valid_inttype<unsigned int> : true_type {}; |
| 64 |
template <> |
| 65 |
struct __libcpp_random_is_valid_inttype<unsigned long> : true_type {}; |
| 66 |
template <> |
| 67 |
struct __libcpp_random_is_valid_inttype<unsigned long long> : true_type {}; |
| 68 |
|
| 69 |
#ifndef _LIBCPP_HAS_NO_INT128 |
| 70 |
template <> |
| 71 |
struct __libcpp_random_is_valid_inttype<__int128_t> : true_type {}; // extension |
| 72 |
template <> |
| 73 |
struct __libcpp_random_is_valid_inttype<__uint128_t> : true_type {}; // extension |
| 74 |
#endif // _LIBCPP_HAS_NO_INT128 |
| 75 |
|
| 76 |
// [rand.req.urng]/3: |
| 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.) |
| 83 |
|
| 84 |
template <class, class = void> |
| 85 |
struct __libcpp_random_is_valid_urng : false_type {}; |
| 86 |
template <class _Gp> |
| 87 |
struct __libcpp_random_is_valid_urng< |
| 88 |
_Gp, |
| 89 |
__enable_if_t< is_unsigned<typename _Gp::result_type>::value && |
| 90 |
_IsSame<decltype(std::declval<_Gp&>()()), typename _Gp::result_type>::value > > : true_type {}; |
| 91 |
|
| 92 |
_LIBCPP_END_NAMESPACE_STD |
| 93 |
|
| 94 |
#endif // _LIBCPP___CXX03___RANDOM_IS_VALID_H |