From 15a3369740c4e9f4cb5440ffa4f57d6f20abdd47 Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Tue, 17 Oct 2023 18:52:35 -0700 Subject: [PATCH 1/2] Conformance: `base_type` in `` is a non-Standard typedef. Remove it outright for Standard `discard_block_engine` (via the new base class `_Discard_block_base`), `independent_bits_engine`, and `shuffle_order_engine`. For `discard_block`, which is usually the base class for Standard `discard_block_engine`, we can guard the typedef with TR1's availability, and deprecate it. We should then avoid using it ourselves. --- stl/inc/random | 16 ++++++++-------- tests/tr1/tests/random1/test.cpp | 2 ++ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/stl/inc/random b/stl/inc/random index 377d5cb8095..7e0859f52f1 100644 --- a/stl/inc/random +++ b/stl/inc/random @@ -1349,7 +1349,10 @@ public: template class discard_block { // discard_block compound engine public: - using base_type = _Engine; +#if _HAS_TR1_NAMESPACE + using base_type _DEPRECATE_TR1_NAMESPACE = _Engine; // TR1-only typedef +#endif // _HAS_TR1_NAMESPACE + using result_type = typename _Engine::result_type; static constexpr int block_size = _Px; @@ -1380,7 +1383,7 @@ public: _Nx = 0; } - _NODISCARD const base_type& base() const noexcept { + _NODISCARD const _Engine& base() const noexcept { return _Eng; } @@ -1433,14 +1436,13 @@ public: } private: - base_type _Eng; + _Engine _Eng; int _Nx; }; template class _Discard_block_base { // TRANSITION, ABI, should be merged into discard_block_engine public: - using base_type = _Engine; using result_type = typename _Engine::result_type; _Discard_block_base() : _Eng(), _Nx(0) {} @@ -1468,7 +1470,7 @@ public: _Nx = 0; } - _NODISCARD const base_type& base() const noexcept { + _NODISCARD const _Engine& base() const noexcept { return _Eng; } @@ -1513,7 +1515,7 @@ public: } private: - base_type _Eng; + _Engine _Eng; size_t _Nx; }; @@ -1559,7 +1561,6 @@ public: static_assert( 0 < _Wx && _Wx <= numeric_limits<_UIntType>::digits, "invalid template argument for independent_bits_engine"); - using base_type = _Engine; using result_type = _UIntType; using _Eres = typename _Engine::result_type; @@ -1707,7 +1708,6 @@ class shuffle_order_engine { // shuffle_order_engine compound engine public: static_assert(0 < _Kx, "invalid template argument for shuffle_order_engine"); - using base_type = _Engine; using result_type = typename _Engine::result_type; static constexpr size_t table_size = _Kx; diff --git a/tests/tr1/tests/random1/test.cpp b/tests/tr1/tests/random1/test.cpp index 49c4cfefb9b..90eb1e90e4e 100644 --- a/tests/tr1/tests/random1/test.cpp +++ b/tests/tr1/tests/random1/test.cpp @@ -466,9 +466,11 @@ static void tdiscard() { typedef STD discard_block rng_t; CHECK_INT(rng_t::block_size, 223); CHECK_INT(rng_t::used_block, 24); +#if _HAS_TR1_NAMESPACE CHECK_INT(rng_t::base_type::modulus, 1 << 24); CHECK_INT(rng_t::base_type::long_lag, 24); CHECK_INT(rng_t::base_type::short_lag, 10); +#endif // _HAS_TR1_NAMESPACE bool st = STD is_same::value; CHECK(st); From a6fbc9688951d69efdc01b1e7dc39efc27547517 Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Tue, 17 Oct 2023 19:29:27 -0700 Subject: [PATCH 2/2] Conformance: Add `_Engine&&` constructors to `discard_block` and `_Discard_block_base`. `discard_block_engine` had an `_Engine&&` constructor but its base classes didn't, so it was always copying. --- stl/inc/random | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/stl/inc/random b/stl/inc/random index 7e0859f52f1..04a9bf2c628 100644 --- a/stl/inc/random +++ b/stl/inc/random @@ -1362,6 +1362,8 @@ public: explicit discard_block(const _Engine& _Ex) : _Eng(_Ex), _Nx(0) {} + explicit discard_block(_Engine&& _Ex) : _Eng(_STD move(_Ex)), _Nx(0) {} + explicit discard_block(result_type _Seed) : _Eng(_Seed), _Nx(0) {} template = 0> @@ -1449,6 +1451,8 @@ public: explicit _Discard_block_base(const _Engine& _Ex) : _Eng(_Ex), _Nx(0) {} + explicit _Discard_block_base(_Engine&& _Ex) : _Eng(_STD move(_Ex)), _Nx(0) {} + explicit _Discard_block_base(result_type _Seed) : _Eng(_Seed), _Nx(0) {} template = 0>