// random number generation (out of line) -*- C++ -*-
-// Copyright (C) 2009-2021 Free Software Foundation, Inc.
+// Copyright (C) 2009-2023 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
{
_GLIBCXX_BEGIN_NAMESPACE_VERSION
- /*
- * (Further) implementation-space details.
- */
+ /// @cond undocumented
+ // (Further) implementation-space details.
namespace __detail
{
// General case for x = (ax + c) mod m -- use Schrage's algorithm
}
} // namespace __detail
+ /// @endcond
+#if ! __cpp_inline_variables
template<typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
constexpr _UIntType
linear_congruential_engine<_UIntType, __a, __c, __m>::multiplier;
template<typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
constexpr _UIntType
linear_congruential_engine<_UIntType, __a, __c, __m>::default_seed;
+#endif
/**
* Seeds the LCR with integral value @p __s, adjusted so that the
return __is;
}
-
+#if ! __cpp_inline_variables
template<typename _UIntType,
size_t __w, size_t __n, size_t __m, size_t __r,
_UIntType __a, size_t __u, _UIntType __d, size_t __s,
constexpr _UIntType
mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
__s, __b, __t, __c, __l, __f>::default_seed;
+#endif
template<typename _UIntType,
size_t __w, size_t __n, size_t __m, size_t __r,
return __is;
}
-
+#if ! __cpp_inline_variables
template<typename _UIntType, size_t __w, size_t __s, size_t __r>
constexpr size_t
subtract_with_carry_engine<_UIntType, __w, __s, __r>::word_size;
subtract_with_carry_engine<_UIntType, __w, __s, __r>::long_lag;
template<typename _UIntType, size_t __w, size_t __s, size_t __r>
- constexpr _UIntType
+ constexpr uint_least32_t
subtract_with_carry_engine<_UIntType, __w, __s, __r>::default_seed;
+#endif
template<typename _UIntType, size_t __w, size_t __s, size_t __r>
void
subtract_with_carry_engine<_UIntType, __w, __s, __r>::
seed(result_type __value)
{
- std::linear_congruential_engine<result_type, 40014u, 0u, 2147483563u>
+ std::linear_congruential_engine<uint_least32_t, 40014u, 0u, 2147483563u>
__lcg(__value == 0u ? default_seed : __value);
const size_t __n = (__w + 31) / 32;
return __is;
}
-
+#if ! __cpp_inline_variables
template<typename _RandomNumberEngine, size_t __p, size_t __r>
constexpr size_t
discard_block_engine<_RandomNumberEngine, __p, __r>::block_size;
template<typename _RandomNumberEngine, size_t __p, size_t __r>
constexpr size_t
discard_block_engine<_RandomNumberEngine, __p, __r>::used_block;
+#endif
template<typename _RandomNumberEngine, size_t __p, size_t __r>
typename discard_block_engine<_RandomNumberEngine,
return __sum;
}
-
+#if ! __cpp_inline_variables
template<typename _RandomNumberEngine, size_t __k>
constexpr size_t
shuffle_order_engine<_RandomNumberEngine, __k>::table_size;
+#endif
namespace __detail
{
constexpr bool
__representable_as_double(_Tp __x) noexcept
{
- static_assert(numeric_limits<_Tp>::is_integer);
- static_assert(!numeric_limits<_Tp>::is_signed);
+ static_assert(numeric_limits<_Tp>::is_integer, "");
+ static_assert(!numeric_limits<_Tp>::is_signed, "");
// All integers <= 2^53 are representable.
return (__x <= (1ull << __DBL_MANT_DIG__))
// Between 2^53 and 2^54 only even numbers are representable.
constexpr bool
__p1_representable_as_double(_Tp __x) noexcept
{
- static_assert(numeric_limits<_Tp>::is_integer);
- static_assert(!numeric_limits<_Tp>::is_signed);
+ static_assert(numeric_limits<_Tp>::is_integer, "");
+ static_assert(!numeric_limits<_Tp>::is_signed, "");
return numeric_limits<_Tp>::digits < __DBL_MANT_DIG__
|| (bool(__x + 1u) // return false if x+1 wraps around to zero
&& __detail::__representable_as_double(__x + 1u));
{
if (__d1._M_param == __d2._M_param
&& __d1._M_saved_available == __d2._M_saved_available)
- {
- if (__d1._M_saved_available
- && __d1._M_saved == __d2._M_saved)
- return true;
- else if(!__d1._M_saved_available)
- return true;
- else
- return false;
- }
+ return __d1._M_saved_available ? __d1._M_saved == __d2._M_saved : true;
else
return false;
}
bool __saved_avail;
if (__is >> __mean >> __stddev >> __saved_avail)
{
- if (__saved_avail && (__is >> __x._M_saved))
+ if (!__saved_avail || (__is >> __x._M_saved))
{
__x._M_saved_available = __saved_avail;
__x.param(param_type(__mean, __stddev));
}
- template<typename _IntType>
+ template<typename _IntType, typename>
seed_seq::seed_seq(std::initializer_list<_IntType> __il)
{
+ _M_v.reserve(__il.size());
for (auto __iter = __il.begin(); __iter != __il.end(); ++__iter)
_M_v.push_back(__detail::__mod<result_type,
__detail::_Shift<result_type, 32>::__value>(*__iter));
template<typename _InputIterator>
seed_seq::seed_seq(_InputIterator __begin, _InputIterator __end)
{
+ if _GLIBCXX17_CONSTEXPR (__is_random_access_iter<_InputIterator>::value)
+ _M_v.reserve(std::distance(__begin, __end));
+
for (_InputIterator __iter = __begin; __iter != __end; ++__iter)
_M_v.push_back(__detail::__mod<result_type,
__detail::_Shift<result_type, 32>::__value>(*__iter));