diff --git a/benchmarks/src/random_integer_generation.cpp b/benchmarks/src/random_integer_generation.cpp index 7a65f2b1f2e..dcc441fa7a4 100644 --- a/benchmarks/src/random_integer_generation.cpp +++ b/benchmarks/src/random_integer_generation.cpp @@ -46,7 +46,7 @@ BENCHMARK(BM_discard)->Range(0, 1 << 18); BENCHMARK(BM_discard)->Range(0, 1 << 18); BENCHMARK(BM_discard)->Range(0, 1 << 18); -/// Support machinery for testing _Rng_from_urng and _Rng_from_urng_v2 +/// Support machinery for testing _Rng_from_urng_v2 std::uint32_t GetMax() { std::mt19937 gen; @@ -58,15 +58,6 @@ const std::uint32_t maximum = GetMax(); // random divisor to prevent strength re /// Test mt19937 -void BM_raw_mt19937_old(benchmark::State& state) { - std::mt19937 gen; - std::_Rng_from_urng rng(gen); - for (auto _ : state) { - benchmark::DoNotOptimize(rng(maximum)); - } -} -BENCHMARK(BM_raw_mt19937_old); - void BM_raw_mt19937_new(benchmark::State& state) { std::mt19937 gen; std::_Rng_from_urng_v2 rng(gen); @@ -78,15 +69,6 @@ BENCHMARK(BM_raw_mt19937_new); /// Test mt19937_64 -void BM_raw_mt19937_64_old(benchmark::State& state) { - std::mt19937_64 gen; - std::_Rng_from_urng rng(gen); - for (auto _ : state) { - benchmark::DoNotOptimize(rng(maximum)); - } -} -BENCHMARK(BM_raw_mt19937_64_old); - void BM_raw_mt19937_64_new(benchmark::State& state) { std::mt19937_64 gen; std::_Rng_from_urng_v2 rng(gen); @@ -98,15 +80,6 @@ BENCHMARK(BM_raw_mt19937_64_new); /// Test minstd_rand -void BM_raw_lcg_old(benchmark::State& state) { - std::minstd_rand gen; - std::_Rng_from_urng rng(gen); - for (auto _ : state) { - benchmark::DoNotOptimize(rng(maximum)); - } -} -BENCHMARK(BM_raw_lcg_old); - void BM_raw_lcg_new(benchmark::State& state) { std::minstd_rand gen; std::_Rng_from_urng_v2 rng(gen); diff --git a/stl/inc/algorithm b/stl/inc/algorithm index 85c0a14b7dd..1ceda78079b 100644 --- a/stl/inc/algorithm +++ b/stl/inc/algorithm @@ -5953,73 +5953,6 @@ namespace ranges { #endif // _HAS_CXX20 #endif // _HAS_CXX17 -template -class _Rng_from_urng { // wrap a URNG as an RNG -public: - using _Ty0 = make_unsigned_t<_Diff>; - using _Ty1 = _Invoke_result_t<_Urng&>; - - using _Udiff = conditional_t; - - explicit _Rng_from_urng(_Urng& _Func) - : _Ref(_Func), _Bits(CHAR_BIT * sizeof(_Udiff)), _Bmask(static_cast<_Udiff>(-1)) { - for (; static_cast<_Udiff>((_Urng::max) () - (_Urng::min) ()) < _Bmask; _Bmask >>= 1) { - --_Bits; - } - } - - _Diff operator()(_Diff _Index) { // adapt _Urng closed range to [0, _Index) - for (;;) { // try a sample random value - _Udiff _Ret = 0; // random bits - _Udiff _Mask = 0; // 2^N - 1, _Ret is within [0, _Mask] - - while (_Mask < static_cast<_Udiff>(_Index - 1)) { // need more random bits - _Ret <<= _Bits - 1; // avoid full shift - _Ret <<= 1; - _Ret |= _Get_bits(); - _Mask <<= _Bits - 1; // avoid full shift - _Mask <<= 1; - _Mask |= _Bmask; - } - - // _Ret is [0, _Mask], _Index - 1 <= _Mask, return if unbiased - if (_Ret / _Index < _Mask / _Index || _Mask % _Index == static_cast<_Udiff>(_Index - 1)) { - return static_cast<_Diff>(_Ret % _Index); - } - } - } - - _Udiff _Get_all_bits() { - _Udiff _Ret = 0; - - for (size_t _Num = 0; _Num < CHAR_BIT * sizeof(_Udiff); _Num += _Bits) { // don't mask away any bits - _Ret <<= _Bits - 1; // avoid full shift - _Ret <<= 1; - _Ret |= _Get_bits(); - } - - return _Ret; - } - - _Rng_from_urng(const _Rng_from_urng&) = delete; - _Rng_from_urng& operator=(const _Rng_from_urng&) = delete; - -private: - _Udiff _Get_bits() { // return a random value within [0, _Bmask] - for (;;) { // repeat until random value is in range - const _Udiff _Val = static_cast<_Udiff>(_Ref() - (_Urng::min) ()); - - if (_Val <= _Bmask) { - return _Val; - } - } - } - - _Urng& _Ref; // reference to URNG - size_t _Bits; // number of random bits generated by _Get_bits() - _Udiff _Bmask; // 2^_Bits - 1 -}; - template class _Rng_from_urng_v2 { // wrap a URNG as an RNG public: @@ -6142,19 +6075,6 @@ private: static constexpr _Udiff _Bmask = static_cast<_Udiff>(-1) >> (_Udiff_bits - _Bits); // 2^_Bits - 1 }; -template -constexpr bool _Has_static_min_max = false; - -// This checks a requirement of N4981 [rand.req.urng] `concept uniform_random_bit_generator` but doesn't attempt -// to implement the whole concept - we just need to distinguish Standard machinery from tr1 machinery. -template -constexpr bool _Has_static_min_max<_Gen, void_t::value)>> = - true; - -template -using _Rng_from_urng_v1_or_v2 = - conditional_t<_Has_static_min_max<_Urng>, _Rng_from_urng_v2<_Diff, _Urng>, _Rng_from_urng<_Diff, _Urng>>; - #if _HAS_CXX17 template _SampleIt _Sample_reservoir_unchecked( @@ -6212,7 +6132,7 @@ _SampleIt sample(_PopIt _First, _PopIt _Last, _SampleIt _Dest, _Diff _Count, _Ur auto _UFirst = _STD _Get_unwrapped(_First); auto _ULast = _STD _Get_unwrapped(_Last); using _PopDiff = _Iter_diff_t<_PopIt>; - _Rng_from_urng_v1_or_v2<_PopDiff, remove_reference_t<_Urng>> _RngFunc(_Func); + _Rng_from_urng_v2<_PopDiff, remove_reference_t<_Urng>> _RngFunc(_Func); if constexpr (_Is_ranges_fwd_iter_v<_PopIt>) { // source is forward: use selection sampling (stable) using _CT = common_type_t<_Diff, _PopDiff>; @@ -6255,7 +6175,7 @@ namespace ranges { return _Output; } - _Rng_from_urng_v1_or_v2, remove_reference_t<_Urng>> _RngFunc(_Func); + _Rng_from_urng_v2, remove_reference_t<_Urng>> _RngFunc(_Func); if constexpr (forward_iterator<_It>) { auto _UFirst = _RANGES _Unwrap_iter<_Se>(_STD move(_First)); auto _Pop_size = _RANGES distance(_UFirst, _RANGES _Unwrap_sent<_It>(_STD move(_Last))); @@ -6276,7 +6196,7 @@ namespace ranges { return _Output; } - _Rng_from_urng_v1_or_v2, remove_reference_t<_Urng>> _RngFunc(_Func); + _Rng_from_urng_v2, remove_reference_t<_Urng>> _RngFunc(_Func); if constexpr (forward_range<_Rng>) { auto _UFirst = _Ubegin(_Range); auto _Pop_size = _RANGES distance(_UFirst, _Uend(_Range)); @@ -6379,7 +6299,7 @@ void _Random_shuffle1(_RanIt _First, _RanIt _Last, _RngFn& _RngFunc) { _EXPORT_STD template void shuffle(_RanIt _First, _RanIt _Last, _Urng&& _Func) { // shuffle [_First, _Last) using URNG _Func using _Urng0 = remove_reference_t<_Urng>; - _Rng_from_urng_v1_or_v2<_Iter_diff_t<_RanIt>, _Urng0> _RngFunc(_Func); + _Rng_from_urng_v2<_Iter_diff_t<_RanIt>, _Urng0> _RngFunc(_Func); _STD _Random_shuffle1(_First, _Last, _RngFunc); } @@ -6392,7 +6312,7 @@ namespace ranges { _STATIC_CALL_OPERATOR _It operator()(_It _First, _Se _Last, _Urng&& _Func) _CONST_CALL_OPERATOR { _STD _Adl_verify_range(_First, _Last); - _Rng_from_urng_v1_or_v2, remove_reference_t<_Urng>> _RngFunc(_Func); + _Rng_from_urng_v2, remove_reference_t<_Urng>> _RngFunc(_Func); auto _UResult = _Shuffle_unchecked( _RANGES _Unwrap_iter<_Se>(_STD move(_First)), _RANGES _Unwrap_sent<_It>(_STD move(_Last)), _RngFunc); @@ -6403,7 +6323,7 @@ namespace ranges { template requires permutable> && uniform_random_bit_generator> _STATIC_CALL_OPERATOR borrowed_iterator_t<_Rng> operator()(_Rng&& _Range, _Urng&& _Func) _CONST_CALL_OPERATOR { - _Rng_from_urng_v1_or_v2, remove_reference_t<_Urng>> _RngFunc(_Func); + _Rng_from_urng_v2, remove_reference_t<_Urng>> _RngFunc(_Func); return _RANGES _Rewrap_iterator(_Range, _Shuffle_unchecked(_Ubegin(_Range), _Uend(_Range), _RngFunc)); } diff --git a/stl/inc/array b/stl/inc/array index 09bf8820073..da5e5afa751 100644 --- a/stl/inc/array +++ b/stl/inc/array @@ -420,12 +420,6 @@ public: using _Library_defined = array; -#if _HAS_TR1_NAMESPACE - _DEPRECATE_TR1_NAMESPACE void assign(const _Ty& _Value) { - _STD fill_n(_Elems, _Size, _Value); - } -#endif // _HAS_TR1_NAMESPACE - _CONSTEXPR20 void fill(const _Ty& _Value) { _STD fill_n(_Elems, _Size, _Value); } @@ -610,10 +604,6 @@ public: using _Library_defined = array; -#if _HAS_TR1_NAMESPACE - _DEPRECATE_TR1_NAMESPACE void assign(const _Ty&) {} -#endif // _HAS_TR1_NAMESPACE - _CONSTEXPR20 void fill(const _Ty&) {} _CONSTEXPR20 void swap(array&) noexcept {} @@ -896,13 +886,6 @@ _NODISCARD constexpr const _Ty&& get(const array<_Ty, _Size>&& _Arr) noexcept { return _STD move(_Arr[_Idx]); } } - -#if _HAS_TR1_NAMESPACE -namespace _DEPRECATE_TR1_NAMESPACE tr1 { - using _STD array; - using _STD get; -} // namespace _DEPRECATE_TR1_NAMESPACE tr1 -#endif // _HAS_TR1_NAMESPACE _STD_END #pragma pop_macro("new") diff --git a/stl/inc/cstdint b/stl/inc/cstdint index d7810fe28c1..0ec169a4526 100644 --- a/stl/inc/cstdint +++ b/stl/inc/cstdint @@ -49,42 +49,6 @@ _EXPORT_STD using _CSTD intmax_t; _EXPORT_STD using _CSTD intptr_t; _EXPORT_STD using _CSTD uintmax_t; _EXPORT_STD using _CSTD uintptr_t; - -#if _HAS_TR1_NAMESPACE -namespace _DEPRECATE_TR1_NAMESPACE tr1 { - using _CSTD int8_t; - using _CSTD int16_t; - using _CSTD int32_t; - using _CSTD int64_t; - using _CSTD uint8_t; - using _CSTD uint16_t; - using _CSTD uint32_t; - using _CSTD uint64_t; - - using _CSTD int_least8_t; - using _CSTD int_least16_t; - using _CSTD int_least32_t; - using _CSTD int_least64_t; - using _CSTD uint_least8_t; - using _CSTD uint_least16_t; - using _CSTD uint_least32_t; - using _CSTD uint_least64_t; - - using _CSTD int_fast8_t; - using _CSTD int_fast16_t; - using _CSTD int_fast32_t; - using _CSTD int_fast64_t; - using _CSTD uint_fast8_t; - using _CSTD uint_fast16_t; - using _CSTD uint_fast32_t; - using _CSTD uint_fast64_t; - - using _CSTD intmax_t; - using _CSTD intptr_t; - using _CSTD uintmax_t; - using _CSTD uintptr_t; -} // namespace _DEPRECATE_TR1_NAMESPACE tr1 -#endif // _HAS_TR1_NAMESPACE _STD_END #pragma pop_macro("new") diff --git a/stl/inc/functional b/stl/inc/functional index 71cc7d7f3a0..04fa643e51f 100644 --- a/stl/inc/functional +++ b/stl/inc/functional @@ -3148,22 +3148,6 @@ namespace ranges { }; } // namespace ranges #endif // _HAS_CXX20 - -#if _HAS_TR1_NAMESPACE -namespace _DEPRECATE_TR1_NAMESPACE tr1 { - using _STD bad_function_call; - using _STD bind; - using _STD function; - using _STD is_bind_expression; - using _STD is_placeholder; - using _STD mem_fn; - using _STD swap; - namespace placeholders { - using namespace _STD placeholders; - } -} // namespace _DEPRECATE_TR1_NAMESPACE tr1 -#endif // _HAS_TR1_NAMESPACE - _STD_END // TRANSITION, non-_Ugly attribute tokens diff --git a/stl/inc/ios b/stl/inc/ios index 24353546712..4b7aca1a802 100644 --- a/stl/inc/ios +++ b/stl/inc/ios @@ -300,13 +300,6 @@ _EXPORT_STD inline ios_base& __CLRCALL_OR_CDECL uppercase(ios_base& _Iosbase) { _Iosbase.setf(ios_base::uppercase); return _Iosbase; } - -#if _HAS_TR1_NAMESPACE -namespace _DEPRECATE_TR1_NAMESPACE tr1 { - using _STD hexfloat; -} -#endif // _HAS_TR1_NAMESPACE - _STD_END #pragma pop_macro("new") diff --git a/stl/inc/memory b/stl/inc/memory index 531faba69f6..d527ead02b3 100644 --- a/stl/inc/memory +++ b/stl/inc/memory @@ -4528,23 +4528,6 @@ _NODISCARD auto inout_ptr(_SmartPtr& _Smart_ptr, _ArgsT&&... _Args) { } } #endif // _HAS_CXX23 - -#if _HAS_TR1_NAMESPACE -namespace _DEPRECATE_TR1_NAMESPACE tr1 { - using _STD allocate_shared; - using _STD bad_weak_ptr; - using _STD const_pointer_cast; - using _STD dynamic_pointer_cast; - using _STD enable_shared_from_this; - using _STD get_deleter; - using _STD make_shared; - using _STD shared_ptr; - using _STD static_pointer_cast; - using _STD swap; - using _STD weak_ptr; -} // namespace _DEPRECATE_TR1_NAMESPACE tr1 -#endif // _HAS_TR1_NAMESPACE - _STD_END // TRANSITION, non-_Ugly attribute tokens diff --git a/stl/inc/random b/stl/inc/random index 5939523b8e2..7f0a0e1ca5d 100644 --- a/stl/inc/random +++ b/stl/inc/random @@ -24,22 +24,6 @@ _STL_DISABLE_CLANG_WARNINGS #pragma push_macro("new") #undef new -#if _HAS_TR1_NAMESPACE -// TRANSITION, GH-183 -#pragma push_macro("discard_block") -#pragma push_macro("linear_congruential") -#pragma push_macro("mersenne_twister") -#pragma push_macro("subtract_with_carry") -#pragma push_macro("uniform_int") -#pragma push_macro("uniform_real") -#undef discard_block -#undef linear_congruential -#undef mersenne_twister -#undef subtract_with_carry -#undef uniform_int -#undef uniform_real -#endif // _HAS_TR1_NAMESPACE - #ifdef _ALLOW_RANDOM_DISTRIBUTION_CONST_OPERATOR #define _DISTRIBUTION_CONST const #else @@ -359,100 +343,13 @@ _NODISCARD _Real generate_canonical(_Gen& _Gx) { // build a floating-point value } } -template -bool _Nrand_for_tr1( - const uint64_t _Rd, const uint64_t _Rx, _Gen& _Gx, _Real& _Val, uint64_t& _Sx_init, uint64_t& _Factor_init) { - // Minimally-constexpr generate_canonical algorithm. Will save work and exit if _Factor would overflow. - _Uint_type _Sx = _Sx_init; - _Uint_type _Factor = _Factor_init; - const auto _Gxmin = (_Gx.min)(); - const auto _Overflow_limit = UINT64_MAX / _Rx; - - _Uint_type _Xx = 0; - _Uint_type _Limit = 0; - bool _Init = false; - for (;;) { - while (_Factor < _Rd) { - if constexpr (is_same_v<_Uint_type, uint64_t>) { - if (_Factor > _Overflow_limit) { - _Sx_init = _Sx; - _Factor_init = _Factor; - return true; - } - } - - _Sx += (_Gx() - _Gxmin) * _Factor; - _Factor *= _Rx; - } - - if (!_Init) { - _Init = true; - _Xx = _Factor / _Rd; - _Limit = _Xx * _Rd; - } - - if (_Sx < _Limit) { - break; - } else { - _Sx = 0; - _Factor = 1; - } - } - - _Val = static_cast<_Real>(static_cast(_Sx / _Xx)); - return false; -} - template _NODISCARD _Real _Nrand_impl(_Gen& _Gx) { // build a floating-point value from random sequence _RNG_REQUIRE_REALTYPE(_Nrand_impl, _Real); constexpr auto _Digits = static_cast(numeric_limits<_Real>::digits); - if constexpr (_Has_static_min_max<_Gen>) { - return _STD generate_canonical<_Real, _Digits>(_Gx); - } else if constexpr (is_integral_v) { - // TRANSITION, for integral tr1 machinery only; Standard machinery can call generate_canonical directly - const auto _Gxmax = (_Gx.max)(); - const auto _Gxmin = (_Gx.min)(); - _Real _Val{0}; - - if (_Gxmax == UINT64_MAX && _Gxmin == 0) { - // special case when uint64_t can't hold the full URBG range - _Val = static_cast<_Real>(static_cast(_Gx()) >> (64 - _Digits)); - } else { - constexpr auto _Rd = 1ULL << _Digits; - const auto _Rx = static_cast(_Gxmax - _Gxmin) + 1; - uint64_t _Sx = 0; - uint64_t _Factor = 1; - - // Try with 64 bits first, upgrade to 128 if necessary. - const bool _Would_overflow = _Nrand_for_tr1(_Rd, _Rx, _Gx, _Val, _Sx, _Factor); - if (_Would_overflow) { - _Nrand_for_tr1<_Unsigned128>(_Rd, _Rx, _Gx, _Val, _Sx, _Factor); - } - } - - return _STD ldexp(_Val, -static_cast(_Digits)); - } else { - // TRANSITION, the pre-P0952R2 algorithm, for non-integral tr1 machinery only (e.g. subtract_with_carry_01) - const _Real _Gxmin = static_cast<_Real>((_Gx.min)()); - const _Real _Gxmax = static_cast<_Real>((_Gx.max)()); - const _Real _Rx = (_Gxmax - _Gxmin) + _Real{1}; - - const int _Ceil = static_cast(_STD ceil(static_cast<_Real>(_Digits) / _STD log2(_Rx))); - const int _Kx = _Ceil < 1 ? 1 : _Ceil; - - _Real _Ans{0}; - _Real _Factor{1}; - - for (int _Idx = 0; _Idx < _Kx; ++_Idx) { // add in another set of bits - _Ans += (static_cast<_Real>(_Gx()) - _Gxmin) * _Factor; - _Factor *= _Rx; - } - - return _Ans / _Factor; - } + return _STD generate_canonical<_Real, _Digits>(_Gx); } template @@ -664,96 +561,6 @@ private: result_type _Prev; }; -#if _HAS_TR1_NAMESPACE -template -class _DEPRECATE_TR1_RANDOM linear_congruential { // linear congruential random engine -public: - _RNG_REQUIRE_UINTTYPE(linear_congruential, _Uint); - - static_assert(0 == _Mx || (_Ax < _Mx && _Cx < _Mx), "invalid template argument for linear_congruential"); - - using result_type = _Uint; - - static constexpr _Uint multiplier = _Ax; - static constexpr _Uint increment = _Cx; - static constexpr _Uint modulus = _Mx; - - linear_congruential() noexcept // strengthened - : _Prev(_Get_linear_congruential_seed<_Uint, _Cx, _Mx>(1u)) {} - - explicit linear_congruential(_Uint _Xx0) noexcept // strengthened - : _Prev(_Get_linear_congruential_seed<_Uint, _Cx, _Mx>(_Xx0)) {} - - template = 0> - linear_congruential(_Gen& _Seq) : _Prev(_Get_linear_congruential_seed<_Uint, _Cx, _Mx>(_Seq())) {} - - void seed(_Uint _Xx0 = 1u) noexcept /* strengthened */ { - // reset sequence from numeric value - _Prev = _Get_linear_congruential_seed<_Uint, _Cx, _Mx>(_Xx0); - } - - template = 0> - void seed(_Gen& _Seq) { // reset sequence from generator - _Prev = _Get_linear_congruential_seed<_Uint, _Cx, _Mx>(_Seq()); - } - - _NODISCARD _Uint(min)() const noexcept /* strengthened */ { - // return minimum possible generated value - return _Cx == 0; - } - -#pragma warning(push) -#pragma warning(disable : 4309) // truncation of constant value - _NODISCARD _Uint(max)() const noexcept /* strengthened */ { - // return maximum possible generated value - return static_cast<_Uint>(_Mx - 1u); // note 0 wraps around to max - } -#pragma warning(pop) - - _NODISCARD _Uint operator()() noexcept /* strengthened */ { - // return next value - _Prev = _Next_linear_congruential_value<_Uint, _Ax, _Cx, _Mx>(_Prev); - return _Prev; - } - - void discard(unsigned long long _Nskip) noexcept /* strengthened */ { - // discard _Nskip elements - auto _Temp = _Prev; - for (; 0 < _Nskip; --_Nskip) { - _Temp = _Next_linear_congruential_value<_Uint, _Ax, _Cx, _Mx>(_Temp); - } - - _Prev = _Temp; - } - - _NODISCARD friend bool operator==(const linear_congruential& _Lhs, const linear_congruential& _Rhs) noexcept - /* strengthened */ { - return _Lhs._Prev == _Rhs._Prev; - } - -#if !_HAS_CXX20 - _NODISCARD friend bool operator!=(const linear_congruential& _Lhs, const linear_congruential& _Rhs) noexcept - /* strengthened */ { - return _Lhs._Prev != _Rhs._Prev; - } -#endif // !_HAS_CXX20 - - template - friend basic_istream<_Elem, _Traits>& operator>>(basic_istream<_Elem, _Traits>& _Istr, linear_congruential& _Eng) { - return _Istr >> _Eng._Prev; - } - - template - friend basic_ostream<_Elem, _Traits>& operator<<( - basic_ostream<_Elem, _Traits>& _Ostr, const linear_congruential& _Eng) { - return _Ostr << _Eng._Prev; - } - -private: - _Uint _Prev; -}; -#endif // _HAS_TR1_NAMESPACE - template struct _Circ_buf { // holds historical values for generators _Ty _At(size_t _Ix) const noexcept { @@ -816,245 +623,13 @@ struct _Circ_buf { // holds historical values for generators _Ty _Ax[2 * _Nw]; }; -template -class _Swc_base : public _Circ_buf<_Ty, _Rx> { // common bits of subtract_with_carry/_01 -public: - using result_type = _Ty; - using _Traits = _Swc_Traits; - using _Mybase = _Circ_buf<_Ty, _Rx>; - using _Seed_t = typename _Swc_Traits::_Seed_t; - - static constexpr size_t short_lag = _Sx; - static constexpr size_t long_lag = _Rx; - static constexpr uint_least32_t default_seed = 19780503u; - - _Swc_base() { - seed(); - } - - _Swc_base(_Seed_t _Xx0) { - seed(_Xx0); - } - - template = 0> - _Swc_base(_Gen& _Gx) { - seed(_Gx); - } - - void seed(_Seed_t _Value = 0u, bool _Readcy = false) { // set initial values from specified seed value - linear_congruential_engine _Lc{ - _Value == 0U ? default_seed : static_cast(_Value % 2147483563U)}; - _Reset(_Lc, _Readcy); - } - - template , int> = 0> - void seed(_Gen& _Gx, bool _Readcy = false) { // set initial values from range - _Reset(_Gx, _Readcy); - } - - _NODISCARD result_type(min)() const noexcept /* strengthened */ { - return 0; - } - - _NODISCARD result_type(max)() const noexcept /* strengthened */ { - return _Swc_Traits::_Max; - } - - _NODISCARD result_type operator()() noexcept /* strengthened */ { - const auto _Ix = 2 * _Rx <= this->_Idx ? 0 : this->_Idx; - if (_Ix < _Sx) { - _Setx(_Ix, this->_Ax[_Ix + 2 * _Rx - _Sx], this->_Ax[_Ix + _Rx]); - } else if (_Ix < _Rx) { - _Setx(_Ix, this->_Ax[_Ix - _Sx], this->_Ax[_Ix + _Rx]); - } else { - _Setx(_Ix, this->_Ax[_Ix - _Sx], this->_Ax[_Ix - _Rx]); - } - - this->_Idx = _Ix + 1; - return this->_Ax[_Ix]; - } - - void discard(unsigned long long _Nskip) { // discard _Nskip elements - for (; 0 < _Nskip; --_Nskip) { - (void) (*this)(); - } - } - - _NODISCARD friend bool operator==(const _Swc_base& _Left, const _Swc_base& _Right) noexcept /* strengthened */ { - return static_cast(_Left)._Equals(_Right) && _Left._Carry == _Right._Carry; - } - -#if !_HAS_CXX20 - _NODISCARD friend bool operator!=(const _Swc_base& _Left, const _Swc_base& _Right) noexcept /* strengthened */ { - return !(_Left == _Right); - } -#endif // !_HAS_CXX20 - - template - friend basic_istream<_Elem, _Traits>& operator>>( - basic_istream<_Elem, _Traits>& _Istr, _Swc_base& _Eng) { // read state from _Istr - _Wrap_istream<_Elem, _Traits, typename _Swc_Traits::_Seed_t> _Gen(_Istr); - _Eng.seed(_Gen, true); - return _Istr; - } - - template - friend basic_ostream<_Elem, _Traits>& operator<<(basic_ostream<_Elem, _Traits>& _Ostr, - const _Swc_base& _Eng) { // write state to _Ostr - _Swc_base::_Traits::_Write(_Ostr, _Eng, _Eng._Carry); - return _Ostr; - } - - template - basic_ostream<_Elem, _Traits>& _Write_full(basic_ostream<_Elem, _Traits>& _Ostr) const { // write state to _Ostr - _Swc_Traits::_Write_full(_Ostr, *this, _Carry); - return _Ostr; - } - -protected: - template - void _Reset(_Gen& _Gx, bool _Readcy) { // reset sequence - _Carry = _Swc_Traits::_Reset(_Gx, this->_Ax, _Readcy); - this->_Idx = _Rx; - } - - void _Setx(size_t _Ix, _Ty _Xis, _Ty _Xir) noexcept { // update _Ax[_Ix] and _Carry - bool _Underflowed = false; - _Ty _Newx = _Xis; - if (_Newx < _Xir) { - _Underflowed = true; - } - - _Newx -= _Xir; - if (_Newx < static_cast(_Carry)) { - _Underflowed = true; - } - - _Newx -= _Carry; - if (_Underflowed) { // underflowed, so add _Mod - _Newx += _Swc_Traits::_Mod; - _Carry = _Swc_Traits::_Cy; - } else { - _Carry = 0; - } - - this->_Ax[_Ix] = _Newx; - } - - typename _Swc_Traits::_Cy_t _Carry; -}; - -template -struct _Swc_traits { // traits for subtract_with_carry generator - using _Cy_t = int; - using _UCy_t = unsigned int; - using _Mod_t = _Ty; - using _Seed_t = _Ty; - - static constexpr _Cy_t _Cy = 1; - static constexpr _Mod_t _Mod = _Mx; - static constexpr _Ty _Max = static_cast<_Ty>(_Mx - 1); - -private: - static constexpr int _Get_wc() noexcept { // compute number of 32-bit words per element - if constexpr (_Mx == 0) { - return (8 * sizeof(_Ty) + 31) / 32; - } else if constexpr (_Mx > (1ULL << 32)) { - return 2; - } else { - return 1; - } - } - -public: - template - static _Cy_t _Reset(_Gen& _Gx, _Ty* _Ax, bool _Readcy) { // set initial values of _Ax from generator _Gx - // return value of _Cy from range if _Readcy is true, - // otherwise compute from last value - constexpr int _Kx = _Get_wc(); - - for (size_t _Ix = 0; _Ix < _Nw; ++_Ix) { // pack _Kx words - _Ax[_Ix] = _Gx(); - for (int _Jx = 1; _Jx < _Kx; ++_Jx) { - _Ax[_Ix] |= static_cast<_Ty>(_Gx()) << (32 * _Jx); - } - } - - _Cy_t _Ans = _Reduce(_Ax); - if (!_Readcy) { - return _Ans; - } else { - return static_cast<_Cy_t>(_Gx()); // TRANSITION, investigate this conversion - } - } - -#pragma warning(push) -#pragma warning(disable : 4724) // potential mod by 0 - static _Cy_t _Reduce(_Ty* _Ax) noexcept { // reduce values to allowed range - if constexpr (_Mx != 0) { - for (size_t _Ix = 0; _Ix < _Nw; ++_Ix) { - _Ax[_Ix] = _Ax[_Ix] % _Mx; - } - } - - return _Ax[_Nw - 1] == 0; - } -#pragma warning(pop) - - template - static void _Write( - basic_ostream<_Elem, _Traits>& _Ostr, const _Circ_buf<_Ty, _Nw>& _Buf, _Cy_t _Cy) { // write state to _Ostr - constexpr int _Kx = _Get_wc(); - - for (size_t _Ix = 0; _Ix < _Nw; ++_Ix) { - for (int _Jx = 0; _Jx < _Kx; ++_Jx) { // unpack into _Kx words - const unsigned int _Word = static_cast(_Buf._At(_Ix) >> (_Jx * 32)); - _Ostr << _Word << ' '; - } - } - - _Ostr << _Cy; - } - - template - static void _Write_full( - basic_ostream<_Elem, _Traits>& _Ostr, const _Circ_buf<_Ty, _Nw>& _Buf, _Cy_t _Cy) { // write state to _Ostr - for (size_t _Ix = 0; _Ix < _Nw; ++_Ix) { - _Ostr << _Buf._At(_Ix) << ' '; - } - - _Ostr << _Cy; - } -}; - -#if _HAS_TR1_NAMESPACE -template -class _DEPRECATE_TR1_RANDOM subtract_with_carry - : public _Swc_base<_Ty, _Sx, _Rx, _Swc_traits<_Ty, _Mx, _Rx>> { // subtract_with_carry generator -public: - using _Mybase = _Swc_base<_Ty, _Sx, _Rx, _Swc_traits<_Ty, _Mx, _Rx>>; - - static constexpr _Ty modulus = _Mx; - - using _Mybase::default_seed; - - subtract_with_carry() : _Mybase(0u) {} - - explicit subtract_with_carry(_Ty _Xx0) : _Mybase(_Xx0) {} - - template = 0> - subtract_with_carry(_Gen& _Gx) : _Mybase(_Gx) {} -}; -#endif // _HAS_TR1_NAMESPACE - _EXPORT_STD template -class subtract_with_carry_engine - : private _Swc_base<_Ty, _Sx, _Rx, _Swc_traits<_Ty, static_cast<_Ty>((_Ty{1} << (_Wx - 1)) << 1), _Rx>> { +class subtract_with_carry_engine : private _Circ_buf<_Ty, _Rx> { private: static constexpr _Ty _Mx = static_cast<_Ty>((_Ty{1} << (_Wx - 1)) << 1); - using _Traits = _Swc_traits<_Ty, _Mx, _Rx>; - using _Mybase = _Swc_base<_Ty, _Sx, _Rx, _Traits>; + using _Cy_t = int; + using _UCy_t = unsigned int; public: _RNG_REQUIRE_UINTTYPE(subtract_with_carry_engine, _Ty); @@ -1068,19 +643,36 @@ public: using result_type = _Ty; - using _Mybase::default_seed; + static constexpr uint_least32_t default_seed = 19780503u; - subtract_with_carry_engine() : _Mybase(0u) {} + subtract_with_carry_engine() { + seed(0u); + } - explicit subtract_with_carry_engine(_Ty _Xx0) : _Mybase(_Xx0) {} + explicit subtract_with_carry_engine(_Ty _Xx0) { + seed(_Xx0); + } template = 0> - explicit subtract_with_carry_engine(_Seed_seq& _Seq) : _Mybase(0u) { + explicit subtract_with_carry_engine(_Seed_seq& _Seq) { seed(_Seq); } void seed(_Ty _Value = 0u) { // set initial values from specified seed value - _Mybase::seed(_Value); + linear_congruential_engine _Lc{ + _Value == 0U ? default_seed : static_cast(_Value % 2147483563U)}; + + constexpr int _Kx = _Get_wc(); + + for (size_t _Ix = 0; _Ix < _Rx; ++_Ix) { // pack _Kx words + this->_Ax[_Ix] = _Lc(); + for (int _Jx = 1; _Jx < _Kx; ++_Jx) { + this->_Ax[_Ix] |= static_cast<_Ty>(_Lc()) << (32 * _Jx); + } + } + + _Carry = _Reduce(); + this->_Idx = _Rx; } template = 0> @@ -1096,13 +688,13 @@ public: this->_Ax[_Ix] |= static_cast<_Ty>(_Arr[_Idx0 + _Jx]) << (32 * _Jx); } - if constexpr (_Traits::_Mod != 0) { - this->_Ax[_Ix] %= _Traits::_Mod; + if constexpr (_Mx != 0) { + this->_Ax[_Ix] %= _Mx; } } - this->_Carry = _Traits::_Reduce(this->_Ax); - this->_Idx = _Rx; + _Carry = _Reduce(); + this->_Idx = _Rx; } _NODISCARD static constexpr _Ty(min)() noexcept /* strengthened */ { @@ -1115,7 +707,7 @@ public: _NODISCARD friend bool operator==( const subtract_with_carry_engine& _Left, const subtract_with_carry_engine& _Right) noexcept /* strengthened */ { - return static_cast(_Left) == static_cast(_Right); + return _Left._Equals(_Right) && _Left._Carry == _Right._Carry; } #if !_HAS_CXX20 @@ -1125,12 +717,24 @@ public: } #endif // !_HAS_CXX20 - _NODISCARD result_type operator()() { - return _Mybase::operator()(); + _NODISCARD result_type operator()() noexcept /* strengthened */ { + const auto _Ix = 2 * _Rx <= this->_Idx ? 0 : this->_Idx; + if (_Ix < _Sx) { + _Setx(_Ix, this->_Ax[_Ix + 2 * _Rx - _Sx], this->_Ax[_Ix + _Rx]); + } else if (_Ix < _Rx) { + _Setx(_Ix, this->_Ax[_Ix - _Sx], this->_Ax[_Ix + _Rx]); + } else { + _Setx(_Ix, this->_Ax[_Ix - _Sx], this->_Ax[_Ix - _Rx]); + } + + this->_Idx = _Ix + 1; + return this->_Ax[_Ix]; } void discard(unsigned long long _Nskip) { - _Mybase::discard(_Nskip); + for (; 0 < _Nskip; --_Nskip) { + (void) (*this)(); + } } template @@ -1138,7 +742,13 @@ public: basic_ostream<_Elem, _Traits>& _Ostr, const subtract_with_carry_engine& _Eng) { const auto _Save_flags = _Ostr.flags(ios_base::dec | ios_base::left); const auto _Save_fill = _Ostr.fill(' '); - _Eng._Write_full(_Ostr); + + for (size_t _Ix = 0; _Ix < _Rx; ++_Ix) { + _Ostr << _Eng._At(_Ix) << ' '; + } + + _Ostr << _Eng._Carry; + _Ostr.flags(_Save_flags); _Ostr.fill(_Save_fill); return _Ostr; @@ -1149,7 +759,7 @@ public: basic_istream<_Elem, _Traits>& _Istr, subtract_with_carry_engine& _Eng) { constexpr auto _Nx = long_lag; result_type _Buffer[_Nx]; - typename _Mybase::_Traits::_Cy_t _Carry_buf; + _Cy_t _Carry_buf; const auto _Save_flags = _Istr.flags(ios_base::dec | ios_base::skipws); for (auto& _Val : _Buffer) { _Istr >> _Val; @@ -1170,265 +780,56 @@ public: _Istr.flags(_Save_flags); return _Istr; } -}; - -#if _HAS_TR1_NAMESPACE -constexpr double _Cx_exp2(const int _Exp) noexcept { - double _Ret = 1.0; - for (int _Count = _Exp; _Count > 0; --_Count) { - _Ret *= 2.0; - } - for (int _Count = _Exp; _Count < 0; ++_Count) { - _Ret *= 0.5; - } - - return _Ret; -} - -template -struct _Swc_01_traits { // traits for subtract_with_carry_01 generator - using _Cy_t = _Ty; - using _UCy_t = _Ty; - using _Mod_t = _Ty; - using _Seed_t = unsigned int; - - static constexpr _Cy_t _Cy = static_cast<_Cy_t>(_Cx_exp2(static_cast(-static_cast(_Wx)))); - static constexpr _Mod_t _Mod = 1; - static constexpr _Ty _Max = 1; - static constexpr int _Nwords = (_Wx + 31) / 32; - - template - static _Cy_t _Reset(_Gen& _Gx, _Ty* _Ax, bool _Readcy) { // set initial values of _Ax from generator _Gx - // return value of _Cy from range if _Readcy is true, - // otherwise from last value - for (size_t _Ix = 0; _Ix < _Rx; ++_Ix) { // read values - _Ty _Factor = 1; - _Ty _Val = 0; - for (int _Jx = 0; _Jx < _Nwords - 1; ++_Jx) { // read components of value - _Factor /= static_cast<_Ty>(_Two32); - _Val += _Gx() * _Factor; - } - _Ty _Temp = (static_cast(_Gx()) & _Mask) / _Scale1; - _Val += (_Temp - static_cast(_Temp)) * _Factor; - _Ax[_Ix] = _Val; - } - if (!_Readcy) { - return _Ax[_Rx - 1] != 0 ? 0 : _Cy; - } else { - return _Gx() == 0 ? 0 : _Cy; - } - } - - template - static void _Write( - basic_ostream<_Elem, _Traits>& _Ostr, const _Circ_buf<_Ty, _Rx>& _Buf, _Cy_t _Cy) { // write state to _Ostr - for (size_t _Ix = 0; _Ix < _Rx; ++_Ix) { // write values - _Ty _Val = _Buf._At(_Ix); - unsigned long _Temp; - for (int _Jx = 0; _Jx < _Nwords - 1; ++_Jx) { // write components of value - _Val *= static_cast<_Ty>(_Two32); - _Temp = static_cast(_Val); - _Val -= _Temp; - _Ostr << _Temp << ' '; - } - _Temp = static_cast(_Val * _Scale1); - _Ostr << _Temp << ' '; - } - _Ostr << (_Cy ? 1 : 0); - } private: - static constexpr _Ty _Scale1 = static_cast<_Ty>(_Cx_exp2(_Wx % 32)); - static constexpr unsigned long _Mask = ~((~0UL) << (_Wx % 32)); -}; - -template -class _DEPRECATE_TR1_NAMESPACE subtract_with_carry_01 - : public _Swc_base<_Ty, _Sx, _Rx, _Swc_01_traits<_Ty, _Wx, _Rx>> { // subtract_with_carry_01 generator -public: - static constexpr size_t word_size = _Wx; - - using _Mybase = _Swc_base<_Ty, _Sx, _Rx, _Swc_01_traits<_Ty, _Wx, _Rx>>; - - subtract_with_carry_01() : _Mybase() {} - - explicit subtract_with_carry_01(typename _Mybase::_Seed_t _Value) : _Mybase(_Value) {} - - template = 0> - subtract_with_carry_01(_Gen& _Gx) : _Mybase(_Gx) {} -}; - -template -class _DEPRECATE_TR1_RANDOM mersenne_twister : public _Circ_buf<_Ty, _Nx> { // mersenne twister generator -public: - using result_type = _Ty; - - static constexpr int word_size = _Wx; - static constexpr int state_size = _Nx; - static constexpr int shift_size = _Mx; - static constexpr int mask_bits = _Rx; - static constexpr _Ty parameter_a = _Px; - static constexpr int output_u = _Ux; - static constexpr int output_s = _Sx; - static constexpr _Ty output_b = _Bx; - static constexpr int output_t = _Tx; - static constexpr _Ty output_c = _Cx; - static constexpr int output_l = _Lx; - - static constexpr _Ty default_seed = 5489U; - - mersenne_twister() : _Dxval(_WMSK) { - seed(default_seed, static_cast<_Ty>(1812433253)); - } - - explicit mersenne_twister(_Ty _Xx0, _Ty _Dxarg = _WMSK, _Ty _Fxarg = static_cast<_Ty>(1812433253)) - : _Dxval(_Dxarg) { - seed(_Xx0, _Fxarg); - } - - template = 0> - explicit mersenne_twister(_Gen& _Gx) : _Dxval(_WMSK) { - seed(_Gx); - } - - void seed(_Ty _Xx0 = default_seed, _Ty _Fx = static_cast<_Ty>(1812433253)) { - // set initial values from specified value - _Ty _Prev = this->_Ax[0] = _Xx0 & _WMSK; - for (size_t _Ix = 1; _Ix < _Nx; ++_Ix) { - _Prev = this->_Ax[_Ix] = (_Ix + _Fx * (_Prev ^ (_Prev >> (_Wx - 2)))) & _WMSK; - } - - this->_Idx = _Nx; - } - - template = 0> - void seed(_Gen& _Gx, bool = false) { // set initial values from range - for (size_t _Ix = 0; _Ix < _Nx; ++_Ix) { - this->_Ax[_Ix] = _Gx() & _WMSK; + void _Setx(size_t _Ix, _Ty _Xis, _Ty _Xir) noexcept { // update _Ax[_Ix] and _Carry + bool _Underflowed = false; + _Ty _Newx = _Xis; + if (_Newx < _Xir) { + _Underflowed = true; } - this->_Idx = _Nx; - } - - _NODISCARD friend bool operator==(const mersenne_twister& _Left, const mersenne_twister& _Right) noexcept - /* strengthened */ { - return _Left._Equals(_Right); - } - -#if !_HAS_CXX20 - _NODISCARD friend bool operator!=(const mersenne_twister& _Left, const mersenne_twister& _Right) noexcept - /* strengthened */ { - return !_Left._Equals(_Right); - } -#endif // !_HAS_CXX20 - - template - friend basic_istream<_Elem, _S_Traits>& operator>>(basic_istream<_Elem, _S_Traits>& _Istr, - mersenne_twister& _Eng) { // read state from _Istr - _Wrap_istream<_Elem, _S_Traits, _Ty> _Gen(_Istr); - _Eng.seed(_Gen); - return _Istr; - } - - template - friend basic_ostream<_Elem, _S_Traits>& operator<<(basic_ostream<_Elem, _S_Traits>& _Ostr, - const mersenne_twister& _Eng) { // write state to _Ostr - _Ostr << _Eng._At(0); - - for (size_t _Ix = 1; _Ix < mersenne_twister::state_size; ++_Ix) { - _Ostr << ' ' << _Eng._At(_Ix); + _Newx -= _Xir; + if (_Newx < static_cast<_UCy_t>(_Carry)) { + _Underflowed = true; } - return _Ostr; - } - - _NODISCARD result_type(min)() const noexcept { - return 0; - } - - _NODISCARD result_type(max)() const noexcept { - return _WMSK; - } - - _NODISCARD result_type operator()() { - if (this->_Idx == _Nx) { - _Refill_upper(); - } else if (2 * _Nx <= this->_Idx) { - _Refill_lower(); + _Newx -= _Carry; + if (_Underflowed) { // underflowed, so add _Mx + _Newx += _Mx; + _Carry = 1; + } else { + _Carry = 0; } - _Ty _Res = this->_Ax[this->_Idx++] & _WMSK; - _Res ^= (_Res >> _Ux) & _Dxval; - _Res ^= (_Res << _Sx) & _Bx; - _Res ^= (_Res << _Tx) & _Cx; - _Res ^= (_Res & _WMSK) >> _Lx; - return _Res; + this->_Ax[_Ix] = _Newx; } - void discard(unsigned long long _Nskip) { // discard _Nskip elements - for (; 0 < _Nskip; --_Nskip) { - (void) (*this)(); + static constexpr int _Get_wc() noexcept { // compute number of 32-bit words per element + if constexpr (_Mx == 0) { + return (8 * sizeof(_Ty) + 31) / 32; + } else if constexpr (_Mx > (1ULL << 32)) { + return 2; + } else { + return 1; } } -protected: - _Post_satisfies_(this->_Idx == 0) void _Refill_lower() { - // compute values for the lower half of the history array - constexpr size_t _Wrap_bound_one = _Nx - _One_mod_n; - constexpr size_t _Wrap_bound_m = _Nx - _M_mod_n; - - if constexpr (_M_mod_n == 0) { - for (size_t _Ix = 0; _Ix < _Wrap_bound_one; ++_Ix) { // fill in values - const _Ty _Tmp = (this->_Ax[_Ix + _Nx] & _HMSK) | (this->_Ax[_Ix + _Nx + _One_mod_n] & _LMSK); - this->_Ax[_Ix] = (_Tmp >> 1) ^ (_Tmp & 1 ? _Px : 0) ^ this->_Ax[_Ix + _Nx + _M_mod_n]; - } - - if constexpr (_One_mod_n == 1) { // fill in _Ax[_Nx - 1] - constexpr size_t _Ix = _Wrap_bound_one; - - const _Ty _Tmp = (this->_Ax[_Ix + _Nx] & _HMSK) | (this->_Ax[_Ix - _Nx + _One_mod_n] & _LMSK); - this->_Ax[_Ix] = (_Tmp >> 1) ^ (_Tmp & 1 ? _Px : 0) ^ this->_Ax[_Ix + _Nx + _M_mod_n]; - } - } else { - for (size_t _Ix = 0; _Ix < _Wrap_bound_m; ++_Ix) { // fill in lower region - const _Ty _Tmp = (this->_Ax[_Ix + _Nx] & _HMSK) | (this->_Ax[_Ix + _Nx + _One_mod_n] & _LMSK); - this->_Ax[_Ix] = (_Tmp >> 1) ^ (_Tmp & 1 ? _Px : 0) ^ this->_Ax[_Ix + _Nx + _M_mod_n]; - } - - for (size_t _Ix = _Wrap_bound_m; _Ix < _Wrap_bound_one; ++_Ix) { - // fill in upper region (avoids modulus operation) - const _Ty _Tmp = (this->_Ax[_Ix + _Nx] & _HMSK) | (this->_Ax[_Ix + _Nx + _One_mod_n] & _LMSK); - this->_Ax[_Ix] = (_Tmp >> 1) ^ (_Tmp & 1 ? _Px : 0) ^ this->_Ax[_Ix - _Nx + _M_mod_n]; - } - - if constexpr (_One_mod_n == 1) { // fill in _Ax[_Nx - 1] - constexpr size_t _Ix = _Wrap_bound_one; - - const _Ty _Tmp = (this->_Ax[_Ix + _Nx] & _HMSK) | (this->_Ax[_Ix - _Nx + _One_mod_n] & _LMSK); - this->_Ax[_Ix] = (_Tmp >> 1) ^ (_Tmp & 1 ? _Px : 0) ^ this->_Ax[_Ix - _Nx + _M_mod_n]; +#pragma warning(push) +#pragma warning(disable : 4724) // potential mod by 0 + _Cy_t _Reduce() noexcept { // reduce values to allowed range + if constexpr (_Mx != 0) { + for (size_t _Ix = 0; _Ix < _Rx; ++_Ix) { + this->_Ax[_Ix] %= _Mx; } } - this->_Idx = 0; + return this->_Ax[_Rx - 1] == 0; } +#pragma warning(pop) - void _Refill_upper() { // compute values for the upper half of the history array - for (size_t _Ix = _Nx; _Ix < 2 * _Nx; ++_Ix) { // fill in values - const _Ty _Tmp = (this->_Ax[_Ix - _Nx] & _HMSK) | (this->_Ax[_Ix - _Nx + _One_mod_n] & _LMSK); - this->_Ax[_Ix] = (_Tmp >> 1) ^ (_Tmp & 1 ? _Px : 0) ^ this->_Ax[_Ix - _Nx + _M_mod_n]; - } - } - - _Ty _Dxval; - - static constexpr _Ty _WMSK = ~((~_Ty{0} << (_Wx - 1)) << 1); - static constexpr _Ty _HMSK = (_WMSK << _Rx) & _WMSK; - static constexpr _Ty _LMSK = ~_HMSK & _WMSK; - - static constexpr int _One_mod_n = 1 % _Nx; // either 0 or 1 - static constexpr int _M_mod_n = _Mx % _Nx; + _Cy_t _Carry; }; -#endif // _HAS_TR1_NAMESPACE _EXPORT_STD template @@ -1629,113 +1030,15 @@ private: } } - _Ty _Dxval{_Dx}; // TRANSITION, ABI: _Dxval must be initialized to _Dx but is unused by the current implementation - - static constexpr _Ty _WMSK = ~((~_Ty{0} << (_Wx - 1)) << 1); - static constexpr _Ty _HMSK = (_WMSK << _Rx) & _WMSK; - static constexpr _Ty _LMSK = ~_HMSK & _WMSK; - - static constexpr int _One_mod_n = 1 % _Nx; // either 0 or 1 - static constexpr int _M_mod_n = _Mx % _Nx; -}; - -#if _HAS_TR1_NAMESPACE -template -class _DEPRECATE_TR1_RANDOM discard_block { // discard_block compound engine -public: -#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; - static constexpr int used_block = _Rx; - - discard_block() : _Eng(), _Nx(0) {} - - 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> - explicit discard_block(_Seed_seq& _Seq) : _Eng(_Seq), _Nx(0) {} - - void seed() { // seed engine from default value - _Eng.seed(); - _Nx = 0; - } - - void seed(result_type _Xx0) { // seed engine from specified value - _Eng.seed(_Xx0); - _Nx = 0; - } - - template = 0> - void seed(_Seed_seq& _Seq) { // seed engine from seed sequence - _Eng.seed(_Seq); - _Nx = 0; - } - - _NODISCARD const _Engine& base() const noexcept { - return _Eng; - } - - _NODISCARD result_type(min)() const { - return (_Eng.min)(); - } - - _NODISCARD result_type(max)() const { - return (_Eng.max)(); - } - - _NODISCARD result_type operator()() { - if (_Rx <= _Nx) { // discard values - while (_Nx++ < _Px) { - (void) _Eng(); - } - - _Nx = 0; - } - ++_Nx; - return _Eng(); - } - - void discard(unsigned long long _Nskip) { // discard _Nskip elements - for (; 0 < _Nskip; --_Nskip) { - (void) (*this)(); - } - } - - _NODISCARD friend bool operator==(const discard_block& _Left, const discard_block& _Right) { - return _Left._Eng == _Right._Eng && _Left._Nx == _Right._Nx; - } - -#if !_HAS_CXX20 - _NODISCARD friend bool operator!=(const discard_block& _Left, const discard_block& _Right) { - return !(_Left == _Right); - } -#endif // !_HAS_CXX20 - - template - friend basic_istream<_Elem, _Traits>& operator>>( - basic_istream<_Elem, _Traits>& _Istr, discard_block& _Eng) { // read state from _Istr - return _Istr >> _Eng._Eng >> _Eng._Nx; - } - - template - friend basic_ostream<_Elem, _Traits>& operator<<( - basic_ostream<_Elem, _Traits>& _Ostr, const discard_block& _Eng) { // write state to _Ostr - return _Ostr << _Eng._Eng << ' ' << _Eng._Nx; - } + _Ty _Dxval{_Dx}; // TRANSITION, ABI: _Dxval must be initialized to _Dx but is unused by the current implementation -private: - _Engine _Eng; - int _Nx; + static constexpr _Ty _WMSK = ~((~_Ty{0} << (_Wx - 1)) << 1); + static constexpr _Ty _HMSK = (_WMSK << _Rx) & _WMSK; + static constexpr _Ty _LMSK = ~_HMSK & _WMSK; + + static constexpr int _One_mod_n = 1 % _Nx; // either 0 or 1 + static constexpr int _M_mod_n = _Mx % _Nx; }; -#endif // _HAS_TR1_NAMESPACE _EXPORT_STD template class discard_block_engine { @@ -2110,150 +1413,6 @@ private: double _Scale; }; -#if _HAS_TR1_NAMESPACE -template -class _DEPRECATE_TR1_RANDOM uniform_int { // uniform integer distribution -public: - using result_type = _Ty; - - struct param_type { // parameter package - using distribution_type = uniform_int; - - param_type() noexcept { - _Init(0, 9); - } - - explicit param_type(result_type _Min0, result_type _Max0 = 9) noexcept { - _Init(_Min0, _Max0); - } - - _NODISCARD friend bool operator==(const param_type& _Left, const param_type& _Right) noexcept - /* strengthened */ { - return _Left._Min == _Right._Min && _Left._Max == _Right._Max; - } - -#if !_HAS_CXX20 - _NODISCARD friend bool operator!=(const param_type& _Left, const param_type& _Right) noexcept - /* strengthened */ { - return !(_Left == _Right); - } -#endif // !_HAS_CXX20 - - _NODISCARD result_type a() const noexcept /* strengthened */ { - return _Min; - } - - _NODISCARD result_type b() const noexcept /* strengthened */ { - return _Max; - } - - void _Init(_Ty _Min0, _Ty _Max0) noexcept { // set internal state - _STL_ASSERT(_Min0 <= _Max0, "invalid min and max arguments for uniform_int"); - _Min = _Min0; - _Max = _Max0; - } - - result_type _Min; - result_type _Max; - }; - - uniform_int() noexcept : _Par(0, 9) {} - - explicit uniform_int(_Ty _Min0, _Ty _Max0 = 9) noexcept : _Par(_Min0, _Max0) {} - - explicit uniform_int(const param_type& _Par0) noexcept : _Par(_Par0) {} - - _NODISCARD result_type a() const noexcept /* strengthened */ { - return _Par.a(); - } - - _NODISCARD result_type b() const noexcept /* strengthened */ { - return _Par.b(); - } - - _NODISCARD param_type param() const noexcept /* strengthened */ { - return _Par; - } - - void param(const param_type& _Par0) noexcept /* strengthened */ { // set parameter package - _Par = _Par0; - } - - _NODISCARD result_type(min)() const noexcept /* strengthened */ { - return _Par._Min; - } - - _NODISCARD result_type(max)() const noexcept /* strengthened */ { - return _Par._Max; - } - - void reset() noexcept /* strengthened */ {} // clear internal state - - template - _NODISCARD result_type operator()(_Engine& _Eng) _DISTRIBUTION_CONST { - return _Eval(_Eng, _Par._Min, _Par._Max); - } - - template - _NODISCARD result_type operator()(_Engine& _Eng, const param_type& _Par0) _DISTRIBUTION_CONST { - return _Eval(_Eng, _Par0._Min, _Par0._Max); - } - - template - _NODISCARD result_type operator()(_Engine& _Eng, result_type _Nx) _DISTRIBUTION_CONST { - return _Eval(_Eng, 0, _Nx - 1); - } - - template - friend basic_istream<_Elem, _Traits>& operator>>(basic_istream<_Elem, _Traits>& _Istr, - uniform_int& _Dist) { // read state from _Istr - uniform_int::result_type _Min0; - uniform_int::result_type _Max0; - _Istr >> _Min0 >> _Max0; - _Dist._Par._Init(_Min0, _Max0); - return _Istr; - } - - template - friend basic_ostream<_Elem, _Traits>& operator<<(basic_ostream<_Elem, _Traits>& _Ostr, - const uniform_int& _Dist) { // write state to _Ostr - return _Ostr << _Dist._Par._Min << ' ' << _Dist._Par._Max; - } - -private: - using _Uty = make_unsigned_t<_Ty>; - - template - result_type _Eval(_Engine& _Eng, _Ty _Min, _Ty _Max) const { // compute next value in range [_Min, _Max] - _Rng_from_urng_v1_or_v2<_Uty, _Engine> _Generator(_Eng); - - const _Uty _Umin = _Adjust(static_cast<_Uty>(_Min)); - const _Uty _Umax = _Adjust(static_cast<_Uty>(_Max)); - - _Uty _Uret; - - if (_Umax - _Umin == static_cast<_Uty>(-1)) { - _Uret = static_cast<_Uty>(_Generator._Get_all_bits()); - } else { - _Uret = static_cast<_Uty>(_Generator(static_cast<_Uty>(_Umax - _Umin + 1))); - } - - return static_cast<_Ty>(_Adjust(static_cast<_Uty>(_Uret + _Umin))); - } - - static _Uty _Adjust(_Uty _Uval) noexcept { // convert signed ranges to unsigned ranges and vice versa - if constexpr (is_signed_v<_Ty>) { - constexpr _Uty _Adjuster = (static_cast<_Uty>(-1) >> 1) + 1; // 2^(N-1) - return static_cast<_Uty>(_Uval ^ _Adjuster); - } else { // _Ty is already unsigned, do nothing - return _Uval; - } - } - - param_type _Par; -}; -#endif // _HAS_TR1_NAMESPACE - _EXPORT_STD template class uniform_int_distribution { // uniform integer distribution public: @@ -3085,135 +2244,6 @@ private: param_type _Par; }; -#if _HAS_TR1_NAMESPACE -template -class _DEPRECATE_TR1_RANDOM uniform_real { // uniform real distribution -public: - using result_type = _Ty; - - struct param_type { // parameter package - using distribution_type = uniform_real; - - param_type() noexcept { - _Init(_Ty{0}, _Ty{1}); - } - - explicit param_type(_Ty _Min0, _Ty _Max0 = _Ty{1}) noexcept { - _Init(_Min0, _Max0); - } - - _NODISCARD friend bool operator==(const param_type& _Left, const param_type& _Right) noexcept - /* strengthened */ { - return _Left._Min == _Right._Min && _Left._Max == _Right._Max; - } - -#if !_HAS_CXX20 - _NODISCARD friend bool operator!=(const param_type& _Left, const param_type& _Right) noexcept - /* strengthened */ { - return !(_Left == _Right); - } -#endif // !_HAS_CXX20 - - _NODISCARD result_type a() const noexcept /* strengthened */ { - return _Min; - } - - _NODISCARD result_type b() const noexcept /* strengthened */ { - return _Max; - } - - void _Init(_Ty _Min0, _Ty _Max0) noexcept { // set internal state - _STL_ASSERT(_Min0 <= _Max0 && (0 <= _Min0 || _Max0 <= _Min0 + (numeric_limits<_Ty>::max)()), - "invalid min and max arguments for uniform_real"); - _Min = _Min0; - _Max = _Max0; - } - - result_type _Min; - result_type _Max; - }; - - uniform_real() noexcept : _Par(_Ty{0}, _Ty{1}) {} - - explicit uniform_real(_Ty _Min0, _Ty _Max0 = _Ty{1}) noexcept : _Par(_Min0, _Max0) {} - - explicit uniform_real(const param_type& _Par0) noexcept : _Par(_Par0) {} - - _NODISCARD result_type a() const noexcept /* strengthened */ { - return _Par.a(); - } - - _NODISCARD result_type b() const noexcept /* strengthened */ { - return _Par.b(); - } - - _NODISCARD param_type param() const noexcept /* strengthened */ { - return _Par; - } - - void param(const param_type& _Par0) noexcept /* strengthened */ { // set parameter package - _Par = _Par0; - } - - _NODISCARD result_type(min)() const noexcept /* strengthened */ { - return _Par._Min; - } - - _NODISCARD result_type(max)() const noexcept /* strengthened */ { - return _Par._Max; - } - - void reset() noexcept /* strengthened */ {} // clear internal state - - template - _NODISCARD result_type operator()(_Engine& _Eng) _DISTRIBUTION_CONST { - return _Eval(_Eng, _Par); - } - - template - _NODISCARD result_type operator()(_Engine& _Eng, const param_type& _Par0) _DISTRIBUTION_CONST { - return _Eval(_Eng, _Par0); - } - - template - friend basic_istream<_Elem, _Traits>& operator>>(basic_istream<_Elem, _Traits>& _Istr, - uniform_real& _Dist) { // read state from _Istr - return _Dist._Read(_Istr); - } - - template - friend basic_ostream<_Elem, _Traits>& operator<<(basic_ostream<_Elem, _Traits>& _Ostr, - const uniform_real& _Dist) { // write state to _Ostr - return _Dist._Write(_Ostr); - } - - template - basic_istream<_Elem, _Traits>& _Read(basic_istream<_Elem, _Traits>& _Istr) { // read state from _Istr - _Ty _Min0; - _Ty _Max0; - _In(_Istr, _Min0); - _In(_Istr, _Max0); - _Par._Init(_Min0, _Max0); - return _Istr; - } - - template - basic_ostream<_Elem, _Traits>& _Write(basic_ostream<_Elem, _Traits>& _Ostr) const { // write state to _Ostr - _Out(_Ostr, _Par._Min); - _Out(_Ostr, _Par._Max); - return _Ostr; - } - -private: - template - result_type _Eval(_Engine& _Eng, const param_type& _Par0) const { - return _Nrand_impl<_Ty>(_Eng) * (_Par0._Max - _Par0._Min) + _Par0._Min; - } - - param_type _Par; -}; -#endif // _HAS_TR1_NAMESPACE - _EXPORT_STD template class uniform_real_distribution { // uniform real distribution public: @@ -5625,19 +4655,6 @@ _EXPORT_STD using minstd_rand = linear_congruential_engine; -#if _HAS_TR1_NAMESPACE -_STL_DISABLE_DEPRECATED_WARNING -using _Ranbase = subtract_with_carry; -using ranlux3 _DEPRECATE_TR1_NAMESPACE = discard_block<_Ranbase, 223, 24>; -using ranlux4 _DEPRECATE_TR1_NAMESPACE = discard_block<_Ranbase, 389, 24>; - -using ranlux_base_01 _DEPRECATE_TR1_NAMESPACE = subtract_with_carry_01; -using ranlux64_base_01 _DEPRECATE_TR1_NAMESPACE = subtract_with_carry_01; -using ranlux3_01 _DEPRECATE_TR1_NAMESPACE = discard_block; -using ranlux4_01 _DEPRECATE_TR1_NAMESPACE = discard_block; -_STL_RESTORE_DEPRECATED_WARNING -#endif // _HAS_TR1_NAMESPACE - _EXPORT_STD using mt19937_64 = mersenne_twister_engine; @@ -5678,79 +4695,10 @@ public: random_device(const random_device&) = delete; random_device& operator=(const random_device&) = delete; }; - -#if _HAS_TR1_NAMESPACE -_STL_DISABLE_DEPRECATED_WARNING -namespace _DEPRECATE_TR1_NAMESPACE tr1 { - using _STD bernoulli_distribution; - using _STD binomial_distribution; - using _STD discard_block; - using _STD exponential_distribution; - using _STD gamma_distribution; - using _STD geometric_distribution; - using _STD linear_congruential; - using _STD mersenne_twister; - using _STD minstd_rand; - using _STD minstd_rand0; - using _STD mt19937; - using _STD normal_distribution; - using _STD poisson_distribution; - using _STD random_device; - using _STD ranlux3; - using _STD ranlux3_01; - using _STD ranlux4; - using _STD ranlux4_01; - using _STD ranlux64_base_01; - using _STD ranlux_base_01; - using _STD subtract_with_carry; - using _STD subtract_with_carry_01; - using _STD uniform_int; - using _STD uniform_real; - using _STD cauchy_distribution; - using _STD chi_squared_distribution; - using _STD default_random_engine; - using _STD discard_block_engine; - using _STD discrete_distribution; - using _STD extreme_value_distribution; - using _STD fisher_f_distribution; - using _STD generate_canonical; - using _STD independent_bits_engine; - using _STD knuth_b; - using _STD linear_congruential_engine; - using _STD lognormal_distribution; - using _STD mersenne_twister_engine; - using _STD mt19937_64; - using _STD negative_binomial_distribution; - using _STD piecewise_constant_distribution; - using _STD piecewise_linear_distribution; - using _STD ranlux24; - using _STD ranlux24_base; - using _STD ranlux48; - using _STD ranlux48_base; - using _STD seed_seq; - using _STD shuffle_order_engine; - using _STD student_t_distribution; - using _STD subtract_with_carry_engine; - using _STD uniform_int_distribution; - using _STD uniform_real_distribution; - using _STD weibull_distribution; -} // namespace _DEPRECATE_TR1_NAMESPACE tr1 -_STL_RESTORE_DEPRECATED_WARNING -#endif // _HAS_TR1_NAMESPACE _STD_END #undef _DISTRIBUTION_CONST -#if _HAS_TR1_NAMESPACE -// TRANSITION, GH-183 -#pragma pop_macro("uniform_real") -#pragma pop_macro("uniform_int") -#pragma pop_macro("subtract_with_carry") -#pragma pop_macro("mersenne_twister") -#pragma pop_macro("linear_congruential") -#pragma pop_macro("discard_block") -#endif // _HAS_TR1_NAMESPACE - #pragma pop_macro("new") _STL_RESTORE_CLANG_WARNINGS #pragma warning(pop) diff --git a/stl/inc/regex b/stl/inc/regex index 949f41a2271..f0b250a8533 100644 --- a/stl/inc/regex +++ b/stl/inc/regex @@ -5388,43 +5388,6 @@ _Parser2<_FwdIt, _Elem, _RxTraits>::_Parser2( _Trans(); } -#if _HAS_TR1_NAMESPACE -namespace _DEPRECATE_TR1_NAMESPACE tr1 { - using _STD basic_regex; - using _STD cmatch; - using _STD cregex_iterator; - using _STD cregex_token_iterator; - using _STD csub_match; - using _STD match_results; - using _STD regex; - using _STD regex_error; - using _STD regex_iterator; - using _STD regex_match; - using _STD regex_replace; - using _STD regex_search; - using _STD regex_token_iterator; - using _STD regex_traits; - using _STD smatch; - using _STD sregex_iterator; - using _STD sregex_token_iterator; - using _STD ssub_match; - using _STD sub_match; - using _STD swap; - using _STD wcmatch; - using _STD wcregex_iterator; - using _STD wcregex_token_iterator; - using _STD wcsub_match; - using _STD wregex; - using _STD wsmatch; - using _STD wsregex_iterator; - using _STD wsregex_token_iterator; - using _STD wssub_match; - namespace regex_constants { - using namespace _STD regex_constants; - } -} // namespace _DEPRECATE_TR1_NAMESPACE tr1 -#endif // _HAS_TR1_NAMESPACE - #if _HAS_CXX17 namespace pmr { _EXPORT_STD template diff --git a/stl/inc/tuple b/stl/inc/tuple index f46ad59a7d9..87acbf49b78 100644 --- a/stl/inc/tuple +++ b/stl/inc/tuple @@ -1320,18 +1320,6 @@ struct common_type<_TTuple, _UTuple> { using type = _Tuple_like_common_type<_TTuple, _UTuple>::type; }; #endif // _HAS_CXX23 - -#if _HAS_TR1_NAMESPACE -namespace _DEPRECATE_TR1_NAMESPACE tr1 { - using _STD get; - using _STD ignore; - using _STD make_tuple; - using _STD ref; - using _STD tie; - using _STD tuple; -} // namespace _DEPRECATE_TR1_NAMESPACE tr1 -#endif // _HAS_TR1_NAMESPACE - _STD_END #pragma pop_macro("new") diff --git a/stl/inc/type_traits b/stl/inc/type_traits index 25bb7575aeb..8e20a4259bb 100644 --- a/stl/inc/type_traits +++ b/stl/inc/type_traits @@ -2696,74 +2696,6 @@ void _Swap_trivial_arrays(_Ty (&_Left)[_Size], _Ty (&_Right)[_Size]) noexcept { *reinterpret_cast<_Last_buffer_type*>(_Right_ptr) = _Last_buffer; } } - -#if _HAS_TR1_NAMESPACE -_STL_DISABLE_DEPRECATED_WARNING -namespace _DEPRECATE_TR1_NAMESPACE tr1 { - using _STD add_const; - using _STD add_cv; - using _STD add_pointer; - using _STD add_volatile; - using _STD aligned_storage; - using _STD alignment_of; - using _STD conditional; - using _STD decay; - using _STD enable_if; - using _STD extent; - using _STD false_type; - using _STD has_virtual_destructor; - using _STD integral_constant; - using _STD is_abstract; - using _STD is_arithmetic; - using _STD is_array; - using _STD is_base_of; - using _STD is_class; - using _STD is_compound; - using _STD is_const; - using _STD is_convertible; - using _STD is_empty; - using _STD is_enum; - using _STD is_floating_point; - using _STD is_function; - using _STD is_fundamental; - using _STD is_integral; - using _STD is_member_function_pointer; - using _STD is_member_object_pointer; - using _STD is_member_pointer; - using _STD is_object; - using _STD is_pod; - using _STD is_pointer; - using _STD is_polymorphic; - using _STD is_reference; - using _STD is_same; - using _STD is_scalar; - using _STD is_signed; - using _STD is_union; - using _STD is_unsigned; - using _STD is_void; - using _STD is_volatile; - using _STD make_signed; - using _STD make_unsigned; - using _STD rank; - using _STD remove_all_extents; - using _STD remove_const; - using _STD remove_cv; - using _STD remove_extent; - using _STD remove_pointer; - using _STD remove_reference; - using _STD remove_volatile; - using _STD true_type; - using _STD cref; - using _STD ref; - using _STD reference_wrapper; -#if _HAS_DEPRECATED_RESULT_OF - using _STD result_of; -#endif // _HAS_DEPRECATED_RESULT_OF - using _STD hash; -} // namespace _DEPRECATE_TR1_NAMESPACE tr1 -_STL_RESTORE_DEPRECATED_WARNING -#endif // _HAS_TR1_NAMESPACE - _STD_END // TRANSITION, non-_Ugly attribute tokens diff --git a/stl/inc/unordered_map b/stl/inc/unordered_map index b7f4891cf82..c65530b092d 100644 --- a/stl/inc/unordered_map +++ b/stl/inc/unordered_map @@ -918,13 +918,6 @@ _NODISCARD bool operator!=(const unordered_multimap<_Kty, _Ty, _Hasher, _Keyeq, } #endif // !_HAS_CXX20 -#if _HAS_TR1_NAMESPACE -namespace _DEPRECATE_TR1_NAMESPACE tr1 { - using _STD unordered_map; - using _STD unordered_multimap; -} // namespace _DEPRECATE_TR1_NAMESPACE tr1 -#endif // _HAS_TR1_NAMESPACE - #if _HAS_CXX17 namespace pmr { _EXPORT_STD template , class _Keyeq = equal_to<_Kty>> diff --git a/stl/inc/unordered_set b/stl/inc/unordered_set index 0f41d148e97..f388b7d7437 100644 --- a/stl/inc/unordered_set +++ b/stl/inc/unordered_set @@ -746,13 +746,6 @@ _NODISCARD bool operator!=(const unordered_multiset<_Kty, _Hasher, _Keyeq, _Allo } #endif // !_HAS_CXX20 -#if _HAS_TR1_NAMESPACE -namespace _DEPRECATE_TR1_NAMESPACE tr1 { - using _STD unordered_multiset; - using _STD unordered_set; -} // namespace _DEPRECATE_TR1_NAMESPACE tr1 -#endif // _HAS_TR1_NAMESPACE - #if _HAS_CXX17 namespace pmr { _EXPORT_STD template , class _Keyeq = equal_to<_Kty>> diff --git a/stl/inc/utility b/stl/inc/utility index 6c2ec4336cd..ceb98ae3ee1 100644 --- a/stl/inc/utility +++ b/stl/inc/utility @@ -1061,15 +1061,6 @@ struct hash { } }; #endif // _HAS_CXX17 - -#if _HAS_TR1_NAMESPACE -namespace _DEPRECATE_TR1_NAMESPACE tr1 { - using _STD get; - using _STD tuple_element; - using _STD tuple_size; -} // namespace _DEPRECATE_TR1_NAMESPACE tr1 -#endif // _HAS_TR1_NAMESPACE - _STD_END // TRANSITION, non-_Ugly attribute tokens diff --git a/stl/inc/yvals_core.h b/stl/inc/yvals_core.h index 1ebbeb3676e..50d1fe59839 100644 --- a/stl/inc/yvals_core.h +++ b/stl/inc/yvals_core.h @@ -155,7 +155,6 @@ // LWG-2385 function::assign allocator argument doesn't make sense // LWG-2921 packaged_task and type-erased allocators // LWG-2976 Dangling uses_allocator specialization for packaged_task -// The non-Standard std::tr1 namespace and TR1-only machinery // Enforcement of matching allocator value_types // _HAS_CXX17 and _SILENCE_ALL_CXX17_DEPRECATION_WARNINGS control: @@ -1039,26 +1038,9 @@ _EMIT_STL_ERROR(STL1004, "C++98 unexpected() is incompatible with C++23 unexpect #define _HAS_FUNCTION_ALLOCATOR_SUPPORT (!_HAS_CXX17) #endif // !defined(_HAS_FUNCTION_ALLOCATOR_SUPPORT) -// The non-Standard std::tr1 namespace and TR1-only machinery -#ifndef _HAS_TR1_NAMESPACE -#define _HAS_TR1_NAMESPACE (!_HAS_CXX17) -#endif // !defined(_HAS_TR1_NAMESPACE) - // STL4000 is "_STATIC_CPPLIB is deprecated", currently in yvals.h // STL4001 is "/clr:pure is deprecated", currently in yvals.h - -#if _HAS_TR1_NAMESPACE -#ifdef _SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING -#define _DEPRECATE_TR1_NAMESPACE -#else // ^^^ warning disabled / warning enabled vvv -#define _DEPRECATE_TR1_NAMESPACE \ - [[deprecated( \ - "warning STL4002: " \ - "The non-Standard std::tr1 namespace and TR1-only machinery are deprecated and will be REMOVED. You can " \ - "define _SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING to suppress this warning.")]] -#endif // ^^^ warning enabled ^^^ -#endif // _HAS_TR1_NAMESPACE - +// STL4002 was "The non-Standard std::tr1 namespace and TR1-only machinery are deprecated and will be REMOVED." // STL4003 was "The non-Standard std::identity struct is deprecated and will be REMOVED." // Enforcement of matching allocator value_types @@ -1516,15 +1498,7 @@ _EMIT_STL_ERROR(STL1004, "C++98 unexpected() is incompatible with C++23 unexpect #define _DEPRECATE_IO_PFX_SFX #endif // ^^^ warning disabled ^^^ -#if !defined(_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING) && !defined(_SILENCE_TR1_RANDOM_DEPRECATION_WARNING) \ - && !defined(_SILENCE_ALL_MS_EXT_DEPRECATION_WARNINGS) -#define _DEPRECATE_TR1_RANDOM \ - [[deprecated("warning STL4046: Non-Standard TR1 components in are deprecated and will be REMOVED. You " \ - "can define _SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING, _SILENCE_TR1_RANDOM_DEPRECATION_WARNING, or " \ - "_SILENCE_ALL_MS_EXT_DEPRECATION_WARNINGS to suppress this warning.")]] -#else // ^^^ warning enabled / warning disabled vvv -#define _DEPRECATE_TR1_RANDOM -#endif // ^^^ warning disabled ^^^ +// STL4046 was "Non-Standard TR1 components in are deprecated and will be REMOVED." #if _HAS_CXX20 && defined(__cpp_char8_t) && !defined(_SILENCE_CXX20_CODECVT_CHAR8_T_FACETS_DEPRECATION_WARNING) \ && !defined(_SILENCE_ALL_CXX20_DEPRECATION_WARNINGS) diff --git a/tests/std/tests/GH_002206_unreserved_names/test.compile.pass.cpp b/tests/std/tests/GH_002206_unreserved_names/test.compile.pass.cpp index 2ad4d398e86..2600ea8f442 100644 --- a/tests/std/tests/GH_002206_unreserved_names/test.compile.pass.cpp +++ b/tests/std/tests/GH_002206_unreserved_names/test.compile.pass.cpp @@ -9,6 +9,13 @@ #define xtime delete #define xtime_get delete +#define discard_block delete +#define linear_congruential delete +#define mersenne_twister delete +#define subtract_with_carry delete +#define uniform_int delete +#define uniform_real delete + // Test workaround for extensions of non-reserved names that can't be removed at this moment. #define raw_name 1001 @@ -23,13 +30,6 @@ #define make_unchecked_array_iterator 1008 #define unchecked_array_iterator 1009 -#define discard_block 1010 -#define linear_congruential 1011 -#define mersenne_twister 1012 -#define subtract_with_carry 1013 -#define uniform_int 1014 -#define uniform_real 1015 - // Also test GH-2645: : Conformance issue on [[msvc::known_semantics]] #define msvc 1 #define known_semantics 2 @@ -104,27 +104,3 @@ #if unchecked_array_iterator != 1009 #error bad macro expansion #endif // unchecked_array_iterator != 1009 - -#if discard_block != 1010 -#error bad macro expansion -#endif // discard_block != 1010 - -#if linear_congruential != 1011 -#error bad macro expansion -#endif // linear_congruential != 1011 - -#if mersenne_twister != 1012 -#error bad macro expansion -#endif // mersenne_twister != 1012 - -#if subtract_with_carry != 1013 -#error bad macro expansion -#endif // subtract_with_carry != 1013 - -#if uniform_int != 1014 -#error bad macro expansion -#endif // uniform_int != 1014 - -#if uniform_real != 1015 -#error bad macro expansion -#endif // uniform_real != 1015 diff --git a/tests/std/tests/P0952R2_new_generate_canonical/test.cpp b/tests/std/tests/P0952R2_new_generate_canonical/test.cpp index 3778db5d592..e7035cf6c78 100644 --- a/tests/std/tests/P0952R2_new_generate_canonical/test.cpp +++ b/tests/std/tests/P0952R2_new_generate_canonical/test.cpp @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -#define _SILENCE_TR1_RANDOM_DEPRECATION_WARNING - #include <__msvc_int128.hpp> #include #include @@ -20,87 +18,6 @@ void test_lwg2524() { assert((generate_canonical) (mt2) < 1.0f); } -#if _HAS_TR1_NAMESPACE -void test_tr1_16() { - using E_std = linear_congruential_engine; - using E_tr1 = linear_congruential; - - E_std std_eng; - E_tr1 tr1_eng; - - for (int i = 0; i < 10; ++i) { - assert(std_eng() == tr1_eng()); - } - - std_eng.seed(); - tr1_eng.seed(); - - uniform_real_distribution dist_32; - for (int i = 0; i < 10; ++i) { - assert(dist_32(std_eng) == dist_32(tr1_eng)); - } - - uniform_real_distribution dist_64; - for (int i = 0; i < 10; ++i) { - assert(dist_64(std_eng) == dist_64(tr1_eng)); - } -} - -void test_tr1_32() { - using E_std = minstd_rand; - using E_tr1 = linear_congruential; - - E_std std_eng; - E_tr1 tr1_eng; - - for (int i = 0; i < 10; ++i) { - assert(std_eng() == tr1_eng()); - } - - std_eng.seed(); - tr1_eng.seed(); - - uniform_real_distribution dist_32; - for (int i = 0; i < 10; ++i) { - assert(dist_32(std_eng) == dist_32(tr1_eng)); - } - - uniform_real_distribution dist_64; - for (int i = 0; i < 10; ++i) { - assert(dist_64(std_eng) == dist_64(tr1_eng)); - } -} - -void test_tr1_64() { - using E_std = mt19937_64; - using E_tr1 = mersenne_twister; - - E_std std_eng; - E_tr1 tr1_eng(E_tr1::default_seed, 0x5555555555555555ULL, 6364136223846793005ULL); - - std_eng.seed(); - tr1_eng.seed(E_tr1::default_seed, 6364136223846793005ULL); - - for (int i = 0; i < 10; ++i) { - assert(std_eng() == tr1_eng()); - } - - std_eng.seed(); - tr1_eng.seed(E_tr1::default_seed, 6364136223846793005ULL); - - uniform_real_distribution dist_32; - for (int i = 0; i < 10; ++i) { - assert(dist_32(std_eng) == dist_32(tr1_eng)); - } - - uniform_real_distribution dist_64; - for (int i = 0; i < 10; ++i) { - assert(dist_64(std_eng) == dist_64(tr1_eng)); - } -} -#endif // _HAS_TR1_NAMESPACE - template Real generate_with_ibe() { independent_bits_engine ibe; @@ -199,12 +116,6 @@ int main() { assert((generate_canonical) (eng) == expected); } -#if _HAS_TR1_NAMESPACE - test_tr1_16(); - test_tr1_32(); - test_tr1_64(); -#endif // _HAS_TR1_NAMESPACE - test_lwg2524(); return 0; diff --git a/tests/std/tests/VSO_0000000_instantiate_iterators_misc/test.compile.pass.cpp b/tests/std/tests/VSO_0000000_instantiate_iterators_misc/test.compile.pass.cpp index ff5f35e3424..564ae410552 100644 --- a/tests/std/tests/VSO_0000000_instantiate_iterators_misc/test.compile.pass.cpp +++ b/tests/std/tests/VSO_0000000_instantiate_iterators_misc/test.compile.pass.cpp @@ -20,7 +20,6 @@ #define _SILENCE_CXX20_VOLATILE_DEPRECATION_WARNING #define _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING #define _SILENCE_STDEXT_ARR_ITERS_DEPRECATION_WARNING -#define _SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING #define _USE_NAMED_IDL_NAMESPACE 1 #include @@ -1138,15 +1137,6 @@ void engine_test_impl() { common_engine_test_impl(ss); } -#if _HAS_TR1_NAMESPACE -template -void tr1_engine_test_impl() { - random_device rd{}; - mt19937 gen(rd()); - common_engine_test_impl(gen); -} -#endif // _HAS_TR1_NAMESPACE - void random_test() { seed_seq ss0({1, 2, 3, 4, 5, 6}); vector v{1, 2, 3, 4}; @@ -1168,19 +1158,6 @@ void random_test() { engine_test_impl(); engine_test_impl(); -#if _HAS_TR1_NAMESPACE - linear_congruential minstd_rand_eng(gen); - minstd_rand_eng.seed(gen); - - tr1_engine_test_impl>(); - tr1_engine_test_impl(); - tr1_engine_test_impl(); - tr1_engine_test_impl(); - tr1_engine_test_impl(); - tr1_engine_test_impl(); - tr1_engine_test_impl(); -#endif // _HAS_TR1_NAMESPACE - uniform_int_distribution<> uni_int_d{}; bernoulli_distribution bern_d{}; geometric_distribution<> geo_d{}; diff --git a/tests/tr1/include/tspec_random.h b/tests/tr1/include/tspec_random.h index e600c6a8a46..b491bde3b8d 100644 --- a/tests/tr1/include/tspec_random.h +++ b/tests/tr1/include/tspec_random.h @@ -129,15 +129,8 @@ void test_random() { // test all of the distributions TESTR(geometric_distribution); TESTR(normal_distribution); TESTR(poisson_distribution); - -#if _HAS_TR1_NAMESPACE - TESTR(uniform_int); - TESTR(uniform_real); -#else // ^^^ _HAS_TR1_NAMESPACE / !_HAS_TR1_NAMESPACE vvv TESTR(uniform_int_distribution); TESTR(uniform_real_distribution); -#endif // ^^^ !_HAS_TR1_NAMESPACE ^^^ - TESTR(cauchy_distribution); TESTR(chi_squared_distribution); TESTR(extreme_value_distribution); diff --git a/tests/tr1/include/tspec_random_defs.h b/tests/tr1/include/tspec_random_defs.h index ac01067f733..781d871979f 100644 --- a/tests/tr1/include/tspec_random_defs.h +++ b/tests/tr1/include/tspec_random_defs.h @@ -129,43 +129,6 @@ One_arg poisson_distribution_vals[] = { {FLIT(99.0), FLIT(0.03986496337366227799), FLIT(0.0)}, }; -#if _HAS_TR1_NAMESPACE -typedef unsigned int uniform_int_type; -uniform_int uniform_int_dist(10, 90); -int uniform_int_smaller_ok = 0; -int uniform_int_larger_ok = 0; - -One_arg uniform_int_vals[] = { - {FLIT(0.0), FLIT(0.0), FLIT(0.0)}, - {FLIT(11.0), FLIT(0.012345679012345678328), FLIT(0.0)}, - {FLIT(22.0), FLIT(0.012345679012345678328), FLIT(0.0)}, - {FLIT(33.0), FLIT(0.012345679012345678328), FLIT(0.0)}, - {FLIT(44.0), FLIT(0.012345679012345678328), FLIT(0.0)}, - {FLIT(55.0), FLIT(0.012345679012345678328), FLIT(0.0)}, - {FLIT(66.0), FLIT(0.012345679012345678328), FLIT(0.0)}, - {FLIT(77.0), FLIT(0.012345679012345678328), FLIT(0.0)}, - {FLIT(88.0), FLIT(0.012345679012345678328), FLIT(0.0)}, - {FLIT(99.0), FLIT(0.0), FLIT(0.0)}, -}; - -typedef double uniform_real_type; -uniform_real uniform_real_dist(40.2, 60.5); -int uniform_real_smaller_ok = 0; -int uniform_real_larger_ok = 0; - -One_arg uniform_real_vals[] = { - {FLIT(0.0), FLIT(0.0), FLIT(0.0)}, - {FLIT(11.0), FLIT(0.0), FLIT(0.0)}, - {FLIT(22.0), FLIT(0.0), FLIT(0.0)}, - {FLIT(33.0), FLIT(0.0), FLIT(0.0)}, - {FLIT(44.0), FLIT(0.049261083743842366821), FLIT(0.0)}, - {FLIT(55.0), FLIT(0.049261083743842366821), FLIT(0.0)}, - {FLIT(66.0), FLIT(0.0), FLIT(0.0)}, - {FLIT(77.0), FLIT(0.0), FLIT(0.0)}, - {FLIT(88.0), FLIT(0.0), FLIT(0.0)}, - {FLIT(99.0), FLIT(0.0), FLIT(0.0)}, -}; -#else // ^^^ _HAS_TR1_NAMESPACE / !_HAS_TR1_NAMESPACE vvv typedef unsigned int uniform_int_distribution_type; uniform_int_distribution uniform_int_distribution_dist(10, 90); int uniform_int_distribution_smaller_ok = 0; @@ -201,7 +164,6 @@ One_arg uniform_real_distribution_vals[] = { {FLIT(88.0), FLIT(0.0), FLIT(0.0)}, {FLIT(99.0), FLIT(0.0), FLIT(0.0)}, }; -#endif // ^^^ !_HAS_TR1_NAMESPACE ^^^ typedef double cauchy_distribution_type; cauchy_distribution cauchy_distribution_dist(50.0, 20.0); diff --git a/tests/tr1/tests/random1/test.cpp b/tests/tr1/tests/random1/test.cpp index e8f842a64f4..cde9f074e32 100644 --- a/tests/tr1/tests/random1/test.cpp +++ b/tests/tr1/tests/random1/test.cpp @@ -4,8 +4,6 @@ // test header, part 1 #define TEST_NAME ", part 1" -#define _SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING - #include "tdefs.h" #include #include @@ -61,11 +59,7 @@ struct test_globals { // tests engine global functions }; static void tlinear() { -#if _HAS_TR1_NAMESPACE - typedef STD linear_congruential rng_t; -#else // ^^^ _HAS_TR1_NAMESPACE / !_HAS_TR1_NAMESPACE vvv typedef STD linear_congruential_engine rng_t; -#endif // ^^^ !_HAS_TR1_NAMESPACE ^^^ CHECK_INT(rng_t::multiplier, 16807); CHECK_INT(rng_t::increment, 0); @@ -83,24 +77,6 @@ static void tlinear() { CHECK_INT(rng1.max(), 2147483646); CHECK_INT(rng1(), 33614); -#if _HAS_TR1_NAMESPACE - generator g; - Uint32 init[] = {1, 2}; - g.reset(init, 2); - - rng_t rng2(g); - CHECK_INT(rng2.min(), 1); - CHECK_INT(rng2.max(), 2147483646); - CHECK_INT(rng2(), 16807); - CHECK_INT(g.index(), 1); - - rng_t rng3(g); - CHECK_INT(rng3.min(), 1); - CHECK_INT(rng3.max(), 2147483646); - CHECK_INT(rng3(), 33614); - CHECK_INT(g.index(), 2); -#endif // ^^^ _HAS_TR1_NAMESPACE ^^^ - rng.seed(1); CHECK_INT(rng.min(), 1); CHECK_INT(rng.max(), 2147483646); @@ -111,32 +87,13 @@ static void tlinear() { CHECK_INT(rng.max(), 2147483646); CHECK_INT(rng(), 33614); -#if _HAS_TR1_NAMESPACE - g.reset(init, 2); - rng3.seed(g); - CHECK_INT(rng3.min(), 1); - CHECK_INT(rng3.max(), 2147483646); - CHECK_INT(rng3(), 16807); - CHECK_INT(g.index(), 1); - - rng3.seed(g); - CHECK_INT(rng3.min(), 1); - CHECK_INT(rng3.max(), 2147483646); - CHECK_INT(rng3(), 33614); - CHECK_INT(g.index(), 2); -#endif // ^^^ _HAS_TR1_NAMESPACE ^^^ - test_globals::test(); // check large values typedef unsigned long long int_type; const int_type max_val = (int_type) -1; -#if _HAS_TR1_NAMESPACE - typedef STD linear_congruential rng4_t; -#else // ^^^ _HAS_TR1_NAMESPACE / !_HAS_TR1_NAMESPACE vvv typedef STD linear_congruential_engine rng4_t; -#endif // ^^^ !_HAS_TR1_NAMESPACE ^^^ rng4_t rng4(1); CHECK(rng4() == max_val - 1); CHECK(rng4() == 1); @@ -169,24 +126,11 @@ static void tminstd_rand() { } static void tmersenne() { -#if _HAS_TR1_NAMESPACE - typedef STD mersenne_twister rng_t; -#else // ^^^ _HAS_TR1_NAMESPACE / !_HAS_TR1_NAMESPACE vvv typedef STD mt19937 rng_t; -#endif // ^^^ !_HAS_TR1_NAMESPACE ^^^ CHECK_INT(rng_t::word_size, 32); CHECK_INT(rng_t::state_size, 624); CHECK_INT(rng_t::shift_size, 397); CHECK_INT(rng_t::mask_bits, 31); -#if _HAS_TR1_NAMESPACE - CHECK_INT((int) rng_t::parameter_a, (int) 0x9908b0df); - CHECK_INT(rng_t::output_u, 11); - CHECK_INT(rng_t::output_s, 7); - CHECK_INT((int) rng_t::output_b, (int) 0x9d2c5680); - CHECK_INT(rng_t::output_t, 15); - CHECK_INT((int) rng_t::output_c, (int) 0xefc60000); - CHECK_INT(rng_t::output_l, 18); -#else // ^^^ _HAS_TR1_NAMESPACE / !_HAS_TR1_NAMESPACE vvv CHECK_INT(rng_t::xor_mask, 0x9908b0df); CHECK_INT(rng_t::tempering_u, 11); CHECK_INT(rng_t::tempering_d, 0xffffffff); @@ -196,7 +140,6 @@ static void tmersenne() { CHECK_INT(rng_t::tempering_c, 0xefc60000); CHECK_INT(rng_t::tempering_l, 18); CHECK_INT(rng_t::initialization_multiplier, 1812433253); -#endif // ^^^ !_HAS_TR1_NAMESPACE ^^^ bool st = STD is_same::value; CHECK(st); @@ -210,20 +153,6 @@ static void tmersenne() { CHECK_INT(ptr_rng1->max(), 0xffffffff); CHECK_INT((*ptr_rng1)(), 1791095845); -#if _HAS_TR1_NAMESPACE - STD linear_congruential init_gen(4357); - - const auto ptr_rng2 = STD make_unique(init_gen); - CHECK_INT(ptr_rng2->min(), 0); - CHECK_INT(ptr_rng2->max(), 0xffffffff); - CHECK_INT((*ptr_rng2)(), (int) 4290933890u); - - rng_t rng3(init_gen); - CHECK_INT(rng3.min(), 0); - CHECK_INT(rng3.max(), 0xffffffff); - CHECK_INT(rng3(), (int) 2649890907u); -#endif // ^^^ _HAS_TR1_NAMESPACE ^^^ - rng.seed(1); CHECK_INT(rng.min(), 0); CHECK_INT(rng.max(), 0xffffffff); @@ -234,19 +163,6 @@ static void tmersenne() { CHECK_INT(rng.max(), 0xffffffff); CHECK_INT(rng(), 1872583848); -#if _HAS_TR1_NAMESPACE - init_gen.seed(4357); - rng3.seed(init_gen); - CHECK_INT(rng3.min(), 0); - CHECK_INT(rng3.max(), 0xffffffff); - CHECK_INT(rng3(), (int) 4290933890u); - - rng3.seed(init_gen); - CHECK_INT(rng3.min(), 0); - CHECK_INT(rng3.max(), 0xffffffff); - CHECK_INT(rng3(), (int) 2649890907u); -#endif // ^^^ _HAS_TR1_NAMESPACE ^^^ - test_globals::test(); } @@ -306,13 +222,8 @@ static void tmt19937() { } static void tsubtract() { -#if _HAS_TR1_NAMESPACE - typedef STD subtract_with_carry rng_t; - CHECK_INT(rng_t::modulus, 1 << 24); -#else // ^^^ _HAS_TR1_NAMESPACE / !_HAS_TR1_NAMESPACE vvv typedef STD subtract_with_carry_engine rng_t; CHECK_INT(rng_t::word_size, 24); -#endif // ^^^ !_HAS_TR1_NAMESPACE ^^^ CHECK_INT(rng_t::short_lag, 10); CHECK_INT(rng_t::long_lag, 24); bool st = STD is_same::value; @@ -328,20 +239,6 @@ static void tsubtract() { CHECK_INT(rng1.max(), (1 << 24) - 1); CHECK_INT(rng1(), 8871692); -#if _HAS_TR1_NAMESPACE - STD linear_congruential init_gen(19780503); - - rng_t rng2(init_gen); - CHECK_INT(rng2.min(), 0); - CHECK_INT(rng2.max(), (1 << 24) - 1); - CHECK_INT(rng2(), 15039276); - - rng_t rng3(init_gen); - CHECK_INT(rng3.min(), 0); - CHECK_INT(rng3.max(), (1 << 24) - 1); - CHECK_INT(rng3(), 6319224); -#endif // ^^^ _HAS_TR1_NAMESPACE ^^^ - rng.seed(1); CHECK_INT(rng.min(), 0); CHECK_INT(rng.max(), (1 << 24) - 1); @@ -352,177 +249,15 @@ static void tsubtract() { CHECK_INT(rng.max(), (1 << 24) - 1); CHECK_INT(rng(), 966168); -#if _HAS_TR1_NAMESPACE - init_gen.seed(19780503); - rng3.seed(init_gen); - CHECK_INT(rng3.min(), 0); - CHECK_INT(rng3.max(), (1 << 24) - 1); - CHECK_INT(rng3(), 15039276); - - rng3.seed(init_gen); - CHECK_INT(rng3.min(), 0); - CHECK_INT(rng3.max(), (1 << 24) - 1); - CHECK_INT(rng3(), 6319224); -#endif // ^^^ _HAS_TR1_NAMESPACE ^^^ - test_globals::test(); } -#if _HAS_TR1_NAMESPACE -static void tranlux3() { - typedef STD ranlux3 rng_t; - CHECK_INT(rng_t::block_size, 223); - CHECK_INT(rng_t::used_block, 24); - 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); - rng_t rng; - Int32 res = 0; - for (int i = 0; i < 10000; ++i) { - res = rng(); - } - CHECK_INT(res, 5957620); -} - -static void tranlux4() { - typedef STD ranlux4 rng_t; - CHECK_INT(rng_t::block_size, 389); - CHECK_INT(rng_t::used_block, 24); - 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); - rng_t rng; - Int32 res = 0; - for (int i = 0; i < 10000; ++i) { - res = rng(); - } - CHECK_INT(res, 8587295); -} - -static void tsubtract_01() { - float factor = ldexpf(1.0f, -24); - typedef STD subtract_with_carry_01 rng_t; - CHECK_INT(rng_t::word_size, 24); - CHECK_INT(rng_t::long_lag, 24); - CHECK_INT(rng_t::short_lag, 10); - bool st = STD is_same::value; - CHECK(st); - - rng_t rng; - CHECK_DOUBLE(rng.min(), 0.0); - CHECK_DOUBLE(rng.max(), 1.0); - CHECK_DOUBLE(rng(), 15039276 * factor); - - rng_t rng1(1); - CHECK_DOUBLE(rng1.min(), 0.0); - CHECK_DOUBLE(rng1.max(), 1.0); - CHECK_DOUBLE(rng1(), 8871692 * factor); - -#if _HAS_TR1_NAMESPACE - STD linear_congruential init_gen(19780503); -#else // ^^^ _HAS_TR1_NAMESPACE / !_HAS_TR1_NAMESPACE vvv - STD linear_congruential_engine init_gen(19780503); -#endif // ^^^ !_HAS_TR1_NAMESPACE ^^^ - - rng_t rng2(init_gen); - CHECK_DOUBLE(rng2.min(), 0.0); - CHECK_DOUBLE(rng2.max(), 1.0); - CHECK_DOUBLE(rng2(), 15039276 * factor); - - rng_t rng3(init_gen); - CHECK_DOUBLE(rng3.min(), 0); - CHECK_DOUBLE(rng3.max(), 1.0); - CHECK_DOUBLE(rng3(), 6319224 * factor); - - rng.seed(1); - CHECK_DOUBLE(rng.min(), 0.0); - CHECK_DOUBLE(rng.max(), 1.0); - CHECK_DOUBLE(rng(), 8871692 * factor); - - rng.seed(2); - CHECK_DOUBLE(rng.min(), 0.0); - CHECK_DOUBLE(rng.max(), 1.0); - CHECK_DOUBLE(rng(), 966168 * factor); - - init_gen.seed(19780503); - rng3.seed(init_gen); - CHECK_DOUBLE(rng3.min(), 0); - CHECK_DOUBLE(rng3.max(), 1.0); - CHECK_DOUBLE(rng3(), 15039276 * factor); - - rng3.seed(init_gen); - CHECK_DOUBLE(rng3.min(), 0.0); - CHECK_DOUBLE(rng3.max(), 1.0); - CHECK_DOUBLE(rng3(), 6319224 * factor); - - test_globals::test(); -} - -static void tranlux_base_01() { - typedef STD ranlux_base_01 rng_t; - bool st = STD is_same::value; - CHECK(st); - CHECK_INT(rng_t::word_size, 24); - CHECK_INT(rng_t::short_lag, 10); - CHECK_INT(rng_t::long_lag, 24); -} - -static void tranlux64_base_01() { - typedef STD ranlux64_base_01 rng_t; - bool st = STD is_same::value; - CHECK(st); - CHECK_INT(rng_t::word_size, 48); - CHECK_INT(rng_t::short_lag, 5); - CHECK_INT(rng_t::long_lag, 12); -} - -static void tranlux3_01() { - typedef STD ranlux3_01 rng_t; - CHECK_INT(rng_t::block_size, 223); - CHECK_INT(rng_t::used_block, 24); - CHECK_INT(rng_t::base_type::word_size, 24); - CHECK_INT(rng_t::base_type::short_lag, 10); - CHECK_INT(rng_t::base_type::long_lag, 24); - rng_t rng; - float res = 0; - for (int i = 0; i < 10000; ++i) { - res = rng(); - } - CHECK_DOUBLE(res, 5957620 / CSTD pow(2.0f, 24)); -} - -static void tranlux4_01() { - typedef STD ranlux4_01 rng_t; - CHECK_INT(rng_t::block_size, 389); - CHECK_INT(rng_t::used_block, 24); - CHECK_INT(rng_t::base_type::word_size, 24); - CHECK_INT(rng_t::base_type::short_lag, 10); - CHECK_INT(rng_t::base_type::long_lag, 24); - rng_t rng; - float res = 0; - for (int i = 0; i < 10000; ++i) { - res = rng(); - } - CHECK_DOUBLE(res, 8587295 / STD pow(2.0f, 24)); -} -#endif // _HAS_TR1_NAMESPACE - static void tdiscard() { int i; -#if _HAS_TR1_NAMESPACE - typedef STD subtract_with_carry rng_base_t; - typedef STD discard_block rng_t; -#else // ^^^ _HAS_TR1_NAMESPACE / !_HAS_TR1_NAMESPACE vvv typedef STD subtract_with_carry_engine rng_base_t; typedef STD discard_block_engine rng_t; -#endif // ^^^ !_HAS_TR1_NAMESPACE ^^^ 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); @@ -531,31 +266,6 @@ static void tdiscard() { CHECK_INT(rng.max(), (1 << 24) - 1); CHECK_INT(rng(), 15039276); -#if _HAS_TR1_NAMESPACE - STD linear_congruential init_gen(19780503); - - rng_t rng2(init_gen); - CHECK_INT(rng2.min(), 0); - CHECK_INT(rng2.max(), (1 << 24) - 1); - CHECK_INT(rng2(), 15039276); - - rng_t rng3(init_gen); - CHECK_INT(rng3.min(), 0); - CHECK_INT(rng3.max(), (1 << 24) - 1); - CHECK_INT(rng3(), 6319224); - - init_gen.seed(19780503); - rng3.seed(init_gen); - CHECK_INT(rng3.min(), 0); - CHECK_INT(rng3.max(), (1 << 24) - 1); - CHECK_INT(rng3(), 15039276); - - rng3.seed(init_gen); - CHECK_INT(rng3.min(), 0); - CHECK_INT(rng3.max(), (1 << 24) - 1); - CHECK_INT(rng3(), 6319224); -#endif // ^^^ _HAS_TR1_NAMESPACE ^^^ - rng_base_t rng4; rng_t rng5; for (i = 0; i < static_cast(rng_t::used_block); ++i) { @@ -578,14 +288,5 @@ void test_main() { // test generators tmersenne(); tmt19937(); tsubtract(); -#if _HAS_TR1_NAMESPACE - tranlux3(); - tranlux4(); - tsubtract_01(); - tranlux_base_01(); - tranlux64_base_01(); - tranlux3_01(); - tranlux4_01(); -#endif // _HAS_TR1_NAMESPACE tdiscard(); } diff --git a/tests/tr1/tests/random2/test.cpp b/tests/tr1/tests/random2/test.cpp index fa99589f4f6..18e3ac701b6 100644 --- a/tests/tr1/tests/random2/test.cpp +++ b/tests/tr1/tests/random2/test.cpp @@ -4,8 +4,6 @@ // test header, part 2 #define TEST_NAME ", part 2" -#define _SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING - #include "tdefs.h" #include #include @@ -45,13 +43,9 @@ struct test_globals { }; static void tuniform_int() { -#if _HAS_TR1_NAMESPACE - typedef STD uniform_int dist_t; - constexpr int default_max = 9; -#else // ^^^ _HAS_TR1_NAMESPACE / !_HAS_TR1_NAMESPACE vvv typedef STD uniform_int_distribution dist_t; constexpr int default_max = STD numeric_limits::max(); -#endif // ^^^ !_HAS_TR1_NAMESPACE ^^^ + bool st = STD is_same::value; CHECK(st); @@ -212,11 +206,7 @@ static void tbinomial_distribution() { } static void tuniform_real() { -#if _HAS_TR1_NAMESPACE - typedef STD uniform_real dist_t; -#else // ^^^ _HAS_TR1_NAMESPACE / !_HAS_TR1_NAMESPACE vvv typedef STD uniform_real_distribution dist_t; -#endif // ^^^ !_HAS_TR1_NAMESPACE ^^^ bool st = STD is_same::value; CHECK(st); @@ -235,10 +225,6 @@ static void tuniform_real() { str >> dist0; CHECK_DOUBLE(dist0.min(), double_m); CHECK_DOUBLE(dist0.max(), double_p); - -#if _HAS_TR1_NAMESPACE - test_globals::test(); -#endif // _HAS_TR1_NAMESPACE } static void texponential_distribution() { diff --git a/tests/tr1/tests/random5/test.cpp b/tests/tr1/tests/random5/test.cpp index a0c7e780b9c..c13d68a555f 100644 --- a/tests/tr1/tests/random5/test.cpp +++ b/tests/tr1/tests/random5/test.cpp @@ -4,8 +4,6 @@ // test C++11 header, part 5 #define TEST_NAME ", part 5" -#define _SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING - #include "tdefs.h" #include #include @@ -116,10 +114,6 @@ static void tuniform_real() { typedef STD ranlux24 rng_t; rng_t rng; CHECK(dist0(rng) != dist0(rng, par0)); - -#if _HAS_TR1_NAMESPACE - test_globals::test(); -#endif // _HAS_TR1_NAMESPACE } static void tnegative_binomial() { diff --git a/tests/tr1/tests/random6/test.cpp b/tests/tr1/tests/random6/test.cpp index 04e9a519888..8bccb27c211 100644 --- a/tests/tr1/tests/random6/test.cpp +++ b/tests/tr1/tests/random6/test.cpp @@ -4,8 +4,6 @@ // test C++11 header, part 6 #define TEST_NAME ", part 6" -#define _SILENCE_TR1_RANDOM_DEPRECATION_WARNING - #include #define FLOAT_TYPE IS_DOUBLE #include "tdefs.h"