aboutsummaryrefslogtreecommitdiff
path: root/libcxx/include/__random/uniform_int_distribution.h
diff options
context:
space:
mode:
Diffstat (limited to 'libcxx/include/__random/uniform_int_distribution.h')
-rw-r--r--libcxx/include/__random/uniform_int_distribution.h83
1 files changed, 43 insertions, 40 deletions
diff --git a/libcxx/include/__random/uniform_int_distribution.h b/libcxx/include/__random/uniform_int_distribution.h
index b7db8a3f9cbb..3a2b95c035b3 100644
--- a/libcxx/include/__random/uniform_int_distribution.h
+++ b/libcxx/include/__random/uniform_int_distribution.h
@@ -9,15 +9,16 @@
#ifndef _LIBCPP___RANDOM_UNIFORM_INT_DISTRIBUTION_H
#define _LIBCPP___RANDOM_UNIFORM_INT_DISTRIBUTION_H
+#include <__bit/countl.h>
#include <__config>
#include <__random/is_valid.h>
#include <__random/log2.h>
-#include <bit>
+#include <__type_traits/conditional.h>
+#include <__type_traits/make_unsigned.h>
#include <cstddef>
#include <cstdint>
#include <iosfwd>
#include <limits>
-#include <type_traits>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
@@ -63,14 +64,14 @@ private:
public:
// constructors and seeding functions
- __independent_bits_engine(_Engine& __e, size_t __w);
+ _LIBCPP_HIDE_FROM_ABI __independent_bits_engine(_Engine& __e, size_t __w);
// generating functions
- result_type operator()() {return __eval(integral_constant<bool, _Rp != 0>());}
+ _LIBCPP_HIDE_FROM_ABI result_type operator()() {return __eval(integral_constant<bool, _Rp != 0>());}
private:
- result_type __eval(false_type);
- result_type __eval(true_type);
+ _LIBCPP_HIDE_FROM_ABI result_type __eval(false_type);
+ _LIBCPP_HIDE_FROM_ABI result_type __eval(true_type);
};
template<class _Engine, class _UIntType>
@@ -120,8 +121,8 @@ template<class _Engine, class _UIntType>
_UIntType
__independent_bits_engine<_Engine, _UIntType>::__eval(true_type)
{
- const size_t _WRt = numeric_limits<result_type>::digits;
- result_type _Sp = 0;
+ const size_t __w_rt = numeric_limits<result_type>::digits;
+ result_type __sp = 0;
for (size_t __k = 0; __k < __n0_; ++__k)
{
_Engine_result_type __u;
@@ -129,11 +130,11 @@ __independent_bits_engine<_Engine, _UIntType>::__eval(true_type)
{
__u = __e_() - _Engine::min();
} while (__u >= __y0_);
- if (__w0_ < _WRt)
- _Sp <<= __w0_;
+ if (__w0_ < __w_rt)
+ __sp <<= __w0_;
else
- _Sp = 0;
- _Sp += __u & __mask0_;
+ __sp = 0;
+ __sp += __u & __mask0_;
}
for (size_t __k = __n0_; __k < __n_; ++__k)
{
@@ -142,13 +143,13 @@ __independent_bits_engine<_Engine, _UIntType>::__eval(true_type)
{
__u = __e_() - _Engine::min();
} while (__u >= __y1_);
- if (__w0_ < _WRt - 1)
- _Sp <<= __w0_ + 1;
+ if (__w0_ < __w_rt - 1)
+ __sp <<= __w0_ + 1;
else
- _Sp = 0;
- _Sp += __u & __mask1_;
+ __sp = 0;
+ __sp += __u & __mask1_;
}
- return _Sp;
+ return __sp;
}
template<class _IntType = int>
@@ -166,12 +167,12 @@ public:
public:
typedef uniform_int_distribution distribution_type;
- explicit param_type(result_type __a = 0,
+ _LIBCPP_HIDE_FROM_ABI explicit param_type(result_type __a = 0,
result_type __b = numeric_limits<result_type>::max())
: __a_(__a), __b_(__b) {}
- result_type a() const {return __a_;}
- result_type b() const {return __b_;}
+ _LIBCPP_HIDE_FROM_ABI result_type a() const {return __a_;}
+ _LIBCPP_HIDE_FROM_ABI result_type b() const {return __b_;}
_LIBCPP_HIDE_FROM_ABI
friend bool operator==(const param_type& __x, const param_type& __y)
@@ -187,8 +188,8 @@ private:
public:
// constructors and reset functions
#ifndef _LIBCPP_CXX03_LANG
- uniform_int_distribution() : uniform_int_distribution(0) {}
- explicit uniform_int_distribution(
+ _LIBCPP_HIDE_FROM_ABI uniform_int_distribution() : uniform_int_distribution(0) {}
+ _LIBCPP_HIDE_FROM_ABI explicit uniform_int_distribution(
result_type __a, result_type __b = numeric_limits<result_type>::max())
: __p_(param_type(__a, __b)) {}
#else
@@ -197,23 +198,25 @@ public:
result_type __b = numeric_limits<result_type>::max())
: __p_(param_type(__a, __b)) {}
#endif
- explicit uniform_int_distribution(const param_type& __p) : __p_(__p) {}
- void reset() {}
+ _LIBCPP_HIDE_FROM_ABI explicit uniform_int_distribution(const param_type& __p) : __p_(__p) {}
+ _LIBCPP_HIDE_FROM_ABI void reset() {}
// generating functions
- template<class _URNG> result_type operator()(_URNG& __g)
+ template<class _URNG>
+ _LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g)
{return (*this)(__g, __p_);}
- template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
+ template<class _URNG>
+ _LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g, const param_type& __p);
// property functions
- result_type a() const {return __p_.a();}
- result_type b() const {return __p_.b();}
+ _LIBCPP_HIDE_FROM_ABI result_type a() const {return __p_.a();}
+ _LIBCPP_HIDE_FROM_ABI result_type b() const {return __p_.b();}
- param_type param() const {return __p_;}
- void param(const param_type& __p) {__p_ = __p;}
+ _LIBCPP_HIDE_FROM_ABI param_type param() const {return __p_;}
+ _LIBCPP_HIDE_FROM_ABI void param(const param_type& __p) {__p_ = __p;}
- result_type min() const {return a();}
- result_type max() const {return b();}
+ _LIBCPP_HIDE_FROM_ABI result_type min() const {return a();}
+ _LIBCPP_HIDE_FROM_ABI result_type max() const {return b();}
_LIBCPP_HIDE_FROM_ABI
friend bool operator==(const uniform_int_distribution& __x,
@@ -234,22 +237,22 @@ _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
static_assert(__libcpp_random_is_valid_urng<_URNG>::value, "");
typedef __conditional_t<sizeof(result_type) <= sizeof(uint32_t), uint32_t, __make_unsigned_t<result_type> >
_UIntType;
- const _UIntType _Rp = _UIntType(__p.b()) - _UIntType(__p.a()) + _UIntType(1);
- if (_Rp == 1)
+ const _UIntType __rp = _UIntType(__p.b()) - _UIntType(__p.a()) + _UIntType(1);
+ if (__rp == 1)
return __p.a();
- const size_t _Dt = numeric_limits<_UIntType>::digits;
+ const size_t __dt = numeric_limits<_UIntType>::digits;
typedef __independent_bits_engine<_URNG, _UIntType> _Eng;
- if (_Rp == 0)
- return static_cast<result_type>(_Eng(__g, _Dt)());
- size_t __w = _Dt - std::__countl_zero(_Rp) - 1;
- if ((_Rp & (numeric_limits<_UIntType>::max() >> (_Dt - __w))) != 0)
+ if (__rp == 0)
+ return static_cast<result_type>(_Eng(__g, __dt)());
+ size_t __w = __dt - std::__countl_zero(__rp) - 1;
+ if ((__rp & (numeric_limits<_UIntType>::max() >> (__dt - __w))) != 0)
++__w;
_Eng __e(__g, __w);
_UIntType __u;
do
{
__u = __e();
- } while (__u >= _Rp);
+ } while (__u >= __rp);
return static_cast<result_type>(__u + __p.a());
}