]> git.ipfire.org Git - thirdparty/gcc.git/blobdiff - libstdc++-v3/include/bits/random.tcc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / include / bits / random.tcc
index bf4397045ef230b8967cd1e4469f21e3f02d4ce1..f092b5cd4cbcd29c360c6c10c0284a63b94e9fb3 100644 (file)
@@ -1,6 +1,6 @@
 // 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
@@ -36,9 +36,8 @@ namespace std _GLIBCXX_VISIBILITY(default)
 {
 _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
@@ -90,7 +89,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       }
 
   } // 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;
@@ -106,6 +107,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   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
@@ -186,7 +188,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       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,
@@ -313,6 +315,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     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,
@@ -515,7 +518,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       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;
@@ -529,15 +532,16 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     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;
@@ -666,7 +670,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       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;
@@ -674,6 +678,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   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,
@@ -799,10 +804,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       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
   {
@@ -811,8 +817,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       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.
@@ -824,8 +830,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       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));
@@ -1901,15 +1907,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     {
       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;
     }
@@ -1955,7 +1953,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       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));
@@ -3231,9 +3229,10 @@ namespace __detail
     }
 
 
-  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));
@@ -3242,6 +3241,9 @@ namespace __detail
   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));