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>
14 
15 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16 #  pragma GCC system_header
17 #endif
18 
19 _LIBCPP_BEGIN_NAMESPACE_STD
20 
21 // [rand.req.genl]/1.5:
22 // The effect of instantiating a template that has a template type parameter
23 // named IntType is undefined unless the corresponding template argument is
24 // cv-unqualified and is one of short, int, long, long long, unsigned short,
25 // unsigned int, unsigned long, or unsigned long long.
26 
27 template<class> struct __libcpp_random_is_valid_inttype : false_type {};
28 template<> struct __libcpp_random_is_valid_inttype<short> : true_type {};
29 template<> struct __libcpp_random_is_valid_inttype<int> : true_type {};
30 template<> struct __libcpp_random_is_valid_inttype<long> : true_type {};
31 template<> struct __libcpp_random_is_valid_inttype<long long> : true_type {};
32 template<> struct __libcpp_random_is_valid_inttype<unsigned short> : true_type {};
33 template<> struct __libcpp_random_is_valid_inttype<unsigned int> : true_type {};
34 template<> struct __libcpp_random_is_valid_inttype<unsigned long> : true_type {};
35 template<> struct __libcpp_random_is_valid_inttype<unsigned long long> : true_type {};
36 
37 #ifndef _LIBCPP_HAS_NO_INT128
38 template<> struct __libcpp_random_is_valid_inttype<__int128_t> : true_type {};
39 template<> struct __libcpp_random_is_valid_inttype<__uint128_t> : true_type {};
40 #endif // _LIBCPP_HAS_NO_INT128
41 
42 // [rand.req.urng]/3:
43 // A class G meets the uniform random bit generator requirements if G models
44 // uniform_random_bit_generator, invoke_result_t<G&> is an unsigned integer type,
45 // and G provides a nested typedef-name result_type that denotes the same type
46 // as invoke_result_t<G&>.
47 // (In particular, reject URNGs with signed result_types; our distributions cannot
48 // handle such generator types.)
49 
50 template<class, class = void> struct __libcpp_random_is_valid_urng : false_type {};
51 template<class _Gp> struct __libcpp_random_is_valid_urng<_Gp, __enable_if_t<
52     is_unsigned<typename _Gp::result_type>::value &&
53     _IsSame<decltype(declval<_Gp&>()()), typename _Gp::result_type>::value
54 > > : true_type {};
55 
56 _LIBCPP_END_NAMESPACE_STD
57 
58 #endif // _LIBCPP___RANDOM_IS_VALID_H
59