brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.6 KiB · f6679b3 Raw
95 lines · c
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-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef _LIBCPP___RANDOM_IS_VALID_H10#define _LIBCPP___RANDOM_IS_VALID_H11 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_header22#endif23 24_LIBCPP_BEGIN_NAMESPACE_STD25 26// [rand.req.genl]/1.4:27// The effect of instantiating a template that has a template type parameter28// named RealType is undefined unless the corresponding template argument is29// cv-unqualified and is one of float, double, or long double.30 31template <class>32struct __libcpp_random_is_valid_realtype : false_type {};33template <>34struct __libcpp_random_is_valid_realtype<float> : true_type {};35template <>36struct __libcpp_random_is_valid_realtype<double> : true_type {};37template <>38struct __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 parameter42// named IntType is undefined unless the corresponding template argument is43// cv-unqualified and is one of short, int, long, long long, unsigned short,44// unsigned int, unsigned long, or unsigned long long.45 46template <class>47struct __libcpp_random_is_valid_inttype : false_type {};48template <>49struct __libcpp_random_is_valid_inttype<int8_t> : true_type {}; // extension50template <>51struct __libcpp_random_is_valid_inttype<short> : true_type {};52template <>53struct __libcpp_random_is_valid_inttype<int> : true_type {};54template <>55struct __libcpp_random_is_valid_inttype<long> : true_type {};56template <>57struct __libcpp_random_is_valid_inttype<long long> : true_type {};58template <>59struct __libcpp_random_is_valid_inttype<uint8_t> : true_type {}; // extension60template <>61struct __libcpp_random_is_valid_inttype<unsigned short> : true_type {};62template <>63struct __libcpp_random_is_valid_inttype<unsigned int> : true_type {};64template <>65struct __libcpp_random_is_valid_inttype<unsigned long> : true_type {};66template <>67struct __libcpp_random_is_valid_inttype<unsigned long long> : true_type {};68 69#if _LIBCPP_HAS_INT12870template <>71struct __libcpp_random_is_valid_inttype<__int128_t> : true_type {}; // extension72template <>73struct __libcpp_random_is_valid_inttype<__uint128_t> : true_type {}; // extension74#endif                                                               // _LIBCPP_HAS_INT12875 76// [rand.req.urng]/3:77// A class G meets the uniform random bit generator requirements if G models78// 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 type80// as invoke_result_t<G&>.81// (In particular, reject URNGs with signed result_types; our distributions cannot82// handle such generator types.)83 84template <class, class = void>85struct __libcpp_random_is_valid_urng : false_type {};86template <class _Gp>87struct __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_STD93 94#endif // _LIBCPP___RANDOM_IS_VALID_H95