diff --git a/stl/inc/iterator b/stl/inc/iterator index 2aeb23824cc..650f88c0764 100644 --- a/stl/inc/iterator +++ b/stl/inc/iterator @@ -1477,10 +1477,7 @@ public: return _Tmp; } -#ifndef __CUDACC__ // TRANSITION, VSO-568006 - _NODISCARD -#endif // TRANSITION, VSO-568006 - friend constexpr checked_array_iterator operator+( + _NODISCARD_FRIEND constexpr checked_array_iterator operator+( const difference_type _Off, const checked_array_iterator<_Ptr>& _Next) noexcept { return _Next + _Off; } @@ -1656,10 +1653,7 @@ public: return _Tmp; } -#ifndef __CUDACC__ // TRANSITION, VSO-568006 - _NODISCARD -#endif // TRANSITION, VSO-568006 - friend constexpr unchecked_array_iterator operator+( + _NODISCARD_FRIEND constexpr unchecked_array_iterator operator+( const difference_type _Off, const unchecked_array_iterator& _Next) noexcept { return _Next + _Off; } diff --git a/stl/inc/random b/stl/inc/random index f35aec3bf6a..c2007b2d05d 100644 --- a/stl/inc/random +++ b/stl/inc/random @@ -422,21 +422,19 @@ public: _Prev = _Temp; } -#ifndef __CUDACC__ // TRANSITION, VSO-568006 - _NODISCARD -#endif // TRANSITION, VSO-568006 - friend bool operator==(const linear_congruential_engine& _Lhs, const linear_congruential_engine& _Rhs) noexcept + _NODISCARD_FRIEND bool operator==( + const linear_congruential_engine& _Lhs, const linear_congruential_engine& _Rhs) noexcept /* strengthened */ { return _Lhs._Prev == _Rhs._Prev; } -#ifndef __CUDACC__ // TRANSITION, VSO-568006 - _NODISCARD -#endif // TRANSITION, VSO-568006 - friend bool operator!=(const linear_congruential_engine& _Lhs, const linear_congruential_engine& _Rhs) noexcept +#if !_HAS_CXX20 + _NODISCARD_FRIEND bool operator!=( + const linear_congruential_engine& _Lhs, const linear_congruential_engine& _Rhs) noexcept /* strengthened */ { return _Lhs._Prev != _Rhs._Prev; } +#endif // !_HAS_CXX20 template friend basic_istream<_Elem, _Traits>& operator>>( @@ -515,21 +513,17 @@ public: _Prev = _Temp; } -#ifndef __CUDACC__ // TRANSITION, VSO-568006 - _NODISCARD -#endif // TRANSITION, VSO-568006 - friend bool operator==(const linear_congruential& _Lhs, const linear_congruential& _Rhs) noexcept + _NODISCARD_FRIEND bool operator==(const linear_congruential& _Lhs, const linear_congruential& _Rhs) noexcept /* strengthened */ { return _Lhs._Prev == _Rhs._Prev; } -#ifndef __CUDACC__ // TRANSITION, VSO-568006 - _NODISCARD -#endif // TRANSITION, VSO-568006 - friend bool operator!=(const linear_congruential& _Lhs, const linear_congruential& _Rhs) noexcept +#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) { @@ -664,13 +658,28 @@ public: } } - bool _Equals(const _Swc_base& _Right) const { - return _Mybase::_Equals(_Right) && _Carry == _Right._Carry; + _NODISCARD_FRIEND bool operator==(const _Swc_base& _Left, const _Swc_base& _Right) { + 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) { + return !(_Left == _Right); + } +#endif // !_HAS_CXX20 + template - basic_ostream<_Elem, _Traits>& _Write(basic_ostream<_Elem, _Traits>& _Ostr) const { // write state to _Ostr - _Swc_Traits::_Write(_Ostr, *this, _Carry); + 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; } @@ -724,32 +733,6 @@ protected: typename _Swc_Traits::_Cy_t _Carry; }; -template -_NODISCARD bool operator==( - const _Swc_base<_Ty, _Sx, _Rx, _Swc_Traits>& _Left, const _Swc_base<_Ty, _Sx, _Rx, _Swc_Traits>& _Right) { - return _Left._Equals(_Right); -} - -template -_NODISCARD bool operator!=( - const _Swc_base<_Ty, _Sx, _Rx, _Swc_Traits>& _Left, const _Swc_base<_Ty, _Sx, _Rx, _Swc_Traits>& _Right) { - return !_Left._Equals(_Right); -} - -template -basic_istream<_Elem, _Traits>& operator>>( - basic_istream<_Elem, _Traits>& _Istr, _Swc_base<_Ty, _Sx, _Rx, _Swc_Traits>& _Eng) { // read state from _Istr - _Wrap_istream<_Elem, _Traits, typename _Swc_Traits::_Seed_t> _Gen(_Istr); - _Eng.seed(_Gen, true); - return _Istr; -} - -template -basic_ostream<_Elem, _Traits>& operator<<( - basic_ostream<_Elem, _Traits>& _Ostr, const _Swc_base<_Ty, _Sx, _Rx, _Swc_Traits>& _Eng) { // write state to _Ostr - return _Eng._Write(_Ostr); -} - template const size_t _Swc_base<_Ty, _Sx, _Rx, _Swc_Traits>::short_lag; @@ -1111,12 +1094,31 @@ public: this->_Idx = _Nx; } + _NODISCARD_FRIEND bool operator==(const mersenne_twister& _Left, const mersenne_twister& _Right) { + return _Left._Equals(_Right); + } + +#if !_HAS_CXX20 + _NODISCARD_FRIEND bool operator!=(const mersenne_twister& _Left, const mersenne_twister& _Right) { + 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 - basic_ostream<_Elem, _S_Traits>& _Write(basic_ostream<_Elem, _S_Traits>& _Ostr) const { // write state to _Ostr - _Ostr << this->_At(0); + 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 < _Nx; ++_Ix) { - _Ostr << ' ' << this->_At(_Ix); + for (size_t _Ix = 1; _Ix < mersenne_twister::state_size; ++_Ix) { + _Ostr << ' ' << _Eng._At(_Ix); } return _Ostr; @@ -1210,34 +1212,6 @@ protected: static constexpr int _M_mod_n = _Mx % _Nx; }; -template -_NODISCARD bool operator==(const mersenne_twister<_Ty, _Wx, _Nx, _Mx, _Rx, _Px, _Ux, _Sx, _Bx, _Tx, _Cx, _Lx>& _Left, - const mersenne_twister<_Ty, _Wx, _Nx, _Mx, _Rx, _Px, _Ux, _Sx, _Bx, _Tx, _Cx, _Lx>& _Right) { - return _Left._Equals(_Right); -} - -template -_NODISCARD bool operator!=(const mersenne_twister<_Ty, _Wx, _Nx, _Mx, _Rx, _Px, _Ux, _Sx, _Bx, _Tx, _Cx, _Lx>& _Left, - const mersenne_twister<_Ty, _Wx, _Nx, _Mx, _Rx, _Px, _Ux, _Sx, _Bx, _Tx, _Cx, _Lx>& _Right) { - return !_Left._Equals(_Right); -} - -template -basic_istream<_Elem, _S_Traits>& operator>>(basic_istream<_Elem, _S_Traits>& _Istr, - mersenne_twister<_Ty, _Wx, _Nx, _Mx, _Rx, _Px, _Ux, _Sx, _Bx, _Tx, _Cx, _Lx>& _Eng) { // read state from _Istr - _Wrap_istream<_Elem, _S_Traits, _Ty> _Gen(_Istr); - _Eng.seed(_Gen); - return _Istr; -} - -template -basic_ostream<_Elem, _S_Traits>& operator<<(basic_ostream<_Elem, _S_Traits>& _Ostr, - const mersenne_twister<_Ty, _Wx, _Nx, _Mx, _Rx, _Px, _Ux, _Sx, _Bx, _Tx, _Cx, _Lx>& _Eng) { // write state to _Ostr - return _Eng._Write(_Ostr); -} - template class mersenne_twister_engine : public mersenne_twister<_Ty, _Wx, _Nx, _Mx, _Rx, _Px, _Ux, _Sx, _Bx, _Tx, _Cx, _Lx> { @@ -1386,18 +1360,26 @@ public: } } - bool _Equals(const discard_block& _Right) const { - return _Eng == _Right._Eng && _Nx == _Right._Nx; + _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 - basic_istream<_Elem, _Traits>& _Read(basic_istream<_Elem, _Traits>& _Istr) { // read state from _Istr - return _Istr >> _Eng >> _Nx; + 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 - basic_ostream<_Elem, _Traits>& _Write(basic_ostream<_Elem, _Traits>& _Ostr) const { // write state to _Ostr - return _Ostr << _Eng << ' ' << _Nx; + 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; } private: @@ -1411,30 +1393,6 @@ const int discard_block<_Engine, _Px, _Rx>::block_size; template const int discard_block<_Engine, _Px, _Rx>::used_block; -template -_NODISCARD bool operator==( - const discard_block<_Engine, _Px, _Rx>& _Left, const discard_block<_Engine, _Px, _Rx>& _Right) { - return _Left._Equals(_Right); -} - -template -_NODISCARD bool operator!=( - const discard_block<_Engine, _Px, _Rx>& _Left, const discard_block<_Engine, _Px, _Rx>& _Right) { - return !(_Left == _Right); -} - -template -basic_istream<_Elem, _Traits>& operator>>( - basic_istream<_Elem, _Traits>& _Istr, discard_block<_Engine, _Px, _Rx>& _Eng) { // read state from _Istr - return _Eng._Read(_Istr); -} - -template -basic_ostream<_Elem, _Traits>& operator<<( - basic_ostream<_Elem, _Traits>& _Ostr, const discard_block<_Engine, _Px, _Rx>& _Eng) { // write state to _Ostr - return _Eng._Write(_Ostr); -} - template class discard_block_engine : public discard_block<_Engine, _Px, _Rx> { // discard_block_engine compound engine public: @@ -1556,14 +1514,26 @@ public: } } + _NODISCARD_FRIEND bool operator==(const independent_bits_engine& _Left, const independent_bits_engine& _Right) { + return _Left.base() == _Right.base(); + } + +#if !_HAS_CXX20 + _NODISCARD_FRIEND bool operator!=(const independent_bits_engine& _Left, const independent_bits_engine& _Right) { + return !(_Left == _Right); + } +#endif // !_HAS_CXX20 + template - basic_istream<_Elem, _Traits>& _Read(basic_istream<_Elem, _Traits>& _Istr) { // read state from _Istr - return _Istr >> _Eng; + friend basic_istream<_Elem, _Traits>& operator>>(basic_istream<_Elem, _Traits>& _Istr, + independent_bits_engine& _Eng) { // read state from _Istr + return _Istr >> _Eng._Eng; } template - basic_ostream<_Elem, _Traits>& _Write(basic_ostream<_Elem, _Traits>& _Ostr) const { // write state to _Ostr - return _Ostr << _Eng; + friend basic_ostream<_Elem, _Traits>& operator<<(basic_ostream<_Elem, _Traits>& _Ostr, + const independent_bits_engine& _Eng) { // write state to _Ostr + return _Ostr << _Eng._Eng; } private: @@ -1602,30 +1572,6 @@ private: _Eres _Yx1; // max value for larger packing word }; -template -_NODISCARD bool operator==(const independent_bits_engine<_Engine, _Wx, _UIntType>& _Left, - const independent_bits_engine<_Engine, _Wx, _UIntType>& _Right) { - return _Left.base() == _Right.base(); -} - -template -_NODISCARD bool operator!=(const independent_bits_engine<_Engine, _Wx, _UIntType>& _Left, - const independent_bits_engine<_Engine, _Wx, _UIntType>& _Right) { - return !(_Left == _Right); -} - -template -basic_istream<_Elem, _Traits>& operator>>(basic_istream<_Elem, _Traits>& _Istr, - independent_bits_engine<_Engine, _Wx, _UIntType>& _Eng) { // read state from _Istr - return _Eng._Read(_Istr); -} - -template -basic_ostream<_Elem, _Traits>& operator<<(basic_ostream<_Elem, _Traits>& _Ostr, - const independent_bits_engine<_Engine, _Wx, _UIntType>& _Eng) { // write state to _Ostr - return _Eng._Write(_Ostr); -} - template class shuffle_order_engine { // shuffle_order_engine compound engine public: @@ -1699,24 +1645,36 @@ public: } } + _NODISCARD_FRIEND bool operator==(const shuffle_order_engine& _Left, const shuffle_order_engine& _Right) { + return _Left.base() == _Right.base(); + } + +#if !_HAS_CXX20 + _NODISCARD_FRIEND bool operator!=(const shuffle_order_engine& _Left, const shuffle_order_engine& _Right) { + return !(_Left == _Right); + } +#endif // !_HAS_CXX20 + template - basic_istream<_Elem, _Traits>& _Read(basic_istream<_Elem, _Traits>& _Istr) { // read state from _Istr - _Istr >> _Eng; - for (size_t _Idx = 0; _Idx < _Kx; ++_Idx) { - _Istr >> _Arr[_Idx]; + friend basic_istream<_Elem, _Traits>& operator>>( + basic_istream<_Elem, _Traits>& _Istr, shuffle_order_engine& _Eng) { // read state from _Istr + _Istr >> _Eng._Eng; + for (size_t _Idx = 0; _Idx < shuffle_order_engine::table_size; ++_Idx) { + _Istr >> _Eng._Arr[_Idx]; } - return _Istr >> _Yx; + return _Istr >> _Eng._Yx; } template - basic_ostream<_Elem, _Traits>& _Write(basic_ostream<_Elem, _Traits>& _Ostr) const { // write state to _Ostr - _Ostr << _Eng; - for (size_t _Idx = 0; _Idx < _Kx; ++_Idx) { - _Ostr << ' ' << _Arr[_Idx]; + friend basic_ostream<_Elem, _Traits>& operator<<( + basic_ostream<_Elem, _Traits>& _Ostr, const shuffle_order_engine& _Eng) { // write state to _Ostr + _Ostr << _Eng._Eng; + for (size_t _Idx = 0; _Idx < shuffle_order_engine::table_size; ++_Idx) { + _Ostr << ' ' << _Eng._Arr[_Idx]; } - return _Ostr << ' ' << _Yx; + return _Ostr << ' ' << _Eng._Yx; } private: @@ -1736,30 +1694,6 @@ private: double _Scale; }; -template -_NODISCARD bool operator==( - const shuffle_order_engine<_Engine, _Kx>& _Left, const shuffle_order_engine<_Engine, _Kx>& _Right) { - return _Left.base() == _Right.base(); -} - -template -_NODISCARD bool operator!=( - const shuffle_order_engine<_Engine, _Kx>& _Left, const shuffle_order_engine<_Engine, _Kx>& _Right) { - return !(_Left == _Right); -} - -template -basic_istream<_Elem, _Traits>& operator>>( - basic_istream<_Elem, _Traits>& _Istr, shuffle_order_engine<_Engine, _Kx>& _Eng) { // read state from _Istr - return _Eng._Read(_Istr); -} - -template -basic_ostream<_Elem, _Traits>& operator<<( - basic_ostream<_Elem, _Traits>& _Ostr, const shuffle_order_engine<_Engine, _Kx>& _Eng) { // write state to _Ostr - return _Eng._Write(_Ostr); -} - template class uniform_int { // uniform integer distribution public: @@ -1776,13 +1710,15 @@ public: _Init(_Min0, _Max0); } - _NODISCARD bool operator==(const param_type& _Right) const { - return _Min == _Right._Min && _Max == _Right._Max; + _NODISCARD_FRIEND bool operator==(const param_type& _Left, const param_type& _Right) { + return _Left._Min == _Right._Min && _Left._Max == _Right._Max; } - _NODISCARD bool operator!=(const param_type& _Right) const { - return !(*this == _Right); +#if !_HAS_CXX20 + _NODISCARD_FRIEND bool operator!=(const param_type& _Left, const param_type& _Right) { + return !(_Left == _Right); } +#endif // !_HAS_CXX20 _NODISCARD result_type a() const { return _Min; @@ -1850,17 +1786,19 @@ public: } template - basic_istream<_Elem, _Traits>& _Read(basic_istream<_Elem, _Traits>& _Istr) { // read state from _Istr - _Ty _Min0; - _Ty _Max0; + 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; - _Par._Init(_Min0, _Max0); + _Dist._Par._Init(_Min0, _Max0); return _Istr; } template - basic_ostream<_Elem, _Traits>& _Write(basic_ostream<_Elem, _Traits>& _Ostr) const { // write state to _Ostr - return _Ostr << _Par._Min << ' ' << _Par._Max; + 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: @@ -1901,18 +1839,6 @@ private: param_type _Par; }; -template -basic_istream<_Elem, _Traits>& operator>>(basic_istream<_Elem, _Traits>& _Istr, - uniform_int<_Ty>& _Dist) { // read state from _Istr - return _Dist._Read(_Istr); -} - -template -basic_ostream<_Elem, _Traits>& operator<<(basic_ostream<_Elem, _Traits>& _Ostr, - const uniform_int<_Ty>& _Dist) { // write state to _Ostr - return _Dist._Write(_Ostr); -} - template class uniform_int_distribution : public uniform_int<_Ty> { // uniform integer distribution public: @@ -1938,17 +1864,17 @@ public: explicit uniform_int_distribution(_Ty _Min0, _Ty _Max0 = (numeric_limits<_Ty>::max) ()) : _Mybase(_Min0, _Max0) {} explicit uniform_int_distribution(const param_type& _Par0) : _Mybase(_Par0) {} -}; -template -_NODISCARD bool operator==(const uniform_int_distribution<_Ty>& _Left, const uniform_int_distribution<_Ty>& _Right) { - return _Left.param() == _Right.param(); -} + _NODISCARD_FRIEND bool operator==(const uniform_int_distribution& _Left, const uniform_int_distribution& _Right) { + return _Left.param() == _Right.param(); + } -template -_NODISCARD bool operator!=(const uniform_int_distribution<_Ty>& _Left, const uniform_int_distribution<_Ty>& _Right) { - return !(_Left == _Right); -} +#if !_HAS_CXX20 + _NODISCARD_FRIEND bool operator!=(const uniform_int_distribution& _Left, const uniform_int_distribution& _Right) { + return !(_Left == _Right); + } +#endif // !_HAS_CXX20 +}; class bernoulli_distribution { // class for bernoulli distribution public: @@ -1965,13 +1891,15 @@ public: _Init(_Px0); } - _NODISCARD bool operator==(const param_type& _Right) const { - return _Px == _Right._Px; + _NODISCARD_FRIEND bool operator==(const param_type& _Left, const param_type& _Right) { + return _Left._Px == _Right._Px; } - _NODISCARD bool operator!=(const param_type& _Right) const { - return !(*this == _Right); +#if !_HAS_CXX20 + _NODISCARD_FRIEND bool operator!=(const param_type& _Left, const param_type& _Right) { + return !(_Left == _Right); } +#endif // !_HAS_CXX20 _NODISCARD double p() const { return _Px; @@ -2024,17 +1952,29 @@ public: return _Eval(_Eng, _Par0); } + _NODISCARD_FRIEND bool operator==(const bernoulli_distribution& _Left, const bernoulli_distribution& _Right) { + return _Left.param() == _Right.param(); + } + +#if !_HAS_CXX20 + _NODISCARD_FRIEND bool operator!=(const bernoulli_distribution& _Left, const bernoulli_distribution& _Right) { + return !(_Left == _Right); + } +#endif // !_HAS_CXX20 + template - basic_istream<_Elem, _Traits>& _Read(basic_istream<_Elem, _Traits>& _Istr) { // read state from _Istr + friend basic_istream<_Elem, _Traits>& operator>>(basic_istream<_Elem, _Traits>& _Istr, + bernoulli_distribution& _Dist) { // read state from _Istr double _Px0; _In(_Istr, _Px0); - _Par._Init(_Px0); + _Dist._Par._Init(_Px0); return _Istr; } template - basic_ostream<_Elem, _Traits>& _Write(basic_ostream<_Elem, _Traits>& _Ostr) const { // write state to _Ostr - _Out(_Ostr, _Par._Px); + friend basic_ostream<_Elem, _Traits>& operator<<(basic_ostream<_Elem, _Traits>& _Ostr, + const bernoulli_distribution& _Dist) { // write state to _Ostr + _Out(_Ostr, _Dist._Par._Px); return _Ostr; } @@ -2047,26 +1987,6 @@ private: param_type _Par; }; -_NODISCARD inline bool operator==(const bernoulli_distribution& _Left, const bernoulli_distribution& _Right) { - return _Left.param() == _Right.param(); -} - -_NODISCARD inline bool operator!=(const bernoulli_distribution& _Left, const bernoulli_distribution& _Right) { - return !(_Left == _Right); -} - -template -basic_istream<_Elem, _Traits>& operator>>(basic_istream<_Elem, _Traits>& _Istr, - bernoulli_distribution& _Dist) { // read state from _Istr - return _Dist._Read(_Istr); -} - -template -basic_ostream<_Elem, _Traits>& operator<<(basic_ostream<_Elem, _Traits>& _Ostr, - const bernoulli_distribution& _Dist) { // write state to _Ostr - return _Dist._Write(_Ostr); -} - // Returns smallest _Flt such that static_cast<_Ty>(_Result) > _Val. // First truncate to largest _Flt <= _Val, then add ceil(ulp). @@ -2125,13 +2045,15 @@ public: _Init(_Px0); } - _NODISCARD bool operator==(const param_type& _Right) const { - return _Px == _Right._Px; + _NODISCARD_FRIEND bool operator==(const param_type& _Left, const param_type& _Right) { + return _Left._Px == _Right._Px; } - _NODISCARD bool operator!=(const param_type& _Right) const { - return !(*this == _Right); +#if !_HAS_CXX20 + _NODISCARD_FRIEND bool operator!=(const param_type& _Left, const param_type& _Right) { + return !(_Left == _Right); } +#endif // !_HAS_CXX20 _NODISCARD _Ty1 p() const { return _Px; @@ -2185,17 +2107,29 @@ public: return _Eval(_Eng, _Par0); } + _NODISCARD_FRIEND bool operator==(const geometric_distribution& _Left, const geometric_distribution& _Right) { + return _Left.param() == _Right.param(); + } + +#if !_HAS_CXX20 + _NODISCARD_FRIEND bool operator!=(const geometric_distribution& _Left, const geometric_distribution& _Right) { + return !(_Left == _Right); + } +#endif // !_HAS_CXX20 + template - basic_istream<_Elem, _Traits>& _Read(basic_istream<_Elem, _Traits>& _Istr) { // read state from _Istr - _Ty1 _Px0; + friend basic_istream<_Elem, _Traits>& operator>>(basic_istream<_Elem, _Traits>& _Istr, + geometric_distribution& _Dist) { // read state from _Istr + geometric_distribution::_Ty1 _Px0; _In(_Istr, _Px0); - _Par._Init(_Px0); + _Dist._Par._Init(_Px0); return _Istr; } template - basic_ostream<_Elem, _Traits>& _Write(basic_ostream<_Elem, _Traits>& _Ostr) const { // write state to _Ostr - _Out(_Ostr, _Par._Px); + friend basic_ostream<_Elem, _Traits>& operator<<(basic_ostream<_Elem, _Traits>& _Ostr, + const geometric_distribution& _Dist) { // write state to _Ostr + _Out(_Ostr, _Dist._Par._Px); return _Ostr; } @@ -2216,28 +2150,6 @@ private: param_type _Par; }; -template -_NODISCARD bool operator==(const geometric_distribution<_Ty>& _Left, const geometric_distribution<_Ty>& _Right) { - return _Left.param() == _Right.param(); -} - -template -_NODISCARD bool operator!=(const geometric_distribution<_Ty>& _Left, const geometric_distribution<_Ty>& _Right) { - return !(_Left == _Right); -} - -template -basic_istream<_Elem, _Traits>& operator>>(basic_istream<_Elem, _Traits>& _Istr, - geometric_distribution<_Ty>& _Dist) { // read state from _Istr - return _Dist._Read(_Istr); -} - -template -basic_ostream<_Elem, _Traits>& operator<<(basic_ostream<_Elem, _Traits>& _Ostr, - const geometric_distribution<_Ty>& _Dist) { // write state to _Ostr - return _Dist._Write(_Ostr); -} - template class _Small_poisson_distribution { // poisson distribution with small mean public: @@ -2284,13 +2196,15 @@ public: _Init(_Mean0); } - _NODISCARD bool operator==(const param_type& _Right) const { - return _Mean == _Right._Mean; + _NODISCARD_FRIEND bool operator==(const param_type& _Left, const param_type& _Right) { + return _Left._Mean == _Right._Mean; } - _NODISCARD bool operator!=(const param_type& _Right) const { - return !(*this == _Right); +#if !_HAS_CXX20 + _NODISCARD_FRIEND bool operator!=(const param_type& _Left, const param_type& _Right) { + return !(_Left == _Right); } +#endif // !_HAS_CXX20 _NODISCARD _Ty1 mean() const { return _Mean; @@ -2351,17 +2265,29 @@ public: return _Eval(_Eng, _Par0); } + _NODISCARD_FRIEND bool operator==(const poisson_distribution& _Left, const poisson_distribution& _Right) { + return _Left.param() == _Right.param(); + } + +#if !_HAS_CXX20 + _NODISCARD_FRIEND bool operator!=(const poisson_distribution& _Left, const poisson_distribution& _Right) { + return !(_Left == _Right); + } +#endif // !_HAS_CXX20 + template - basic_istream<_Elem, _Traits>& _Read(basic_istream<_Elem, _Traits>& _Istr) { // read state from _Istr - _Ty1 _Mean0; + friend basic_istream<_Elem, _Traits>& operator>>(basic_istream<_Elem, _Traits>& _Istr, + poisson_distribution& _Dist) { // read state from _Istr + poisson_distribution::_Ty1 _Mean0; _In(_Istr, _Mean0); - _Par._Init(_Mean0); + _Dist._Par._Init(_Mean0); return _Istr; } template - basic_ostream<_Elem, _Traits>& _Write(basic_ostream<_Elem, _Traits>& _Ostr) const { // write state to _Ostr - _Out(_Ostr, _Par._Mean); + friend basic_ostream<_Elem, _Traits>& operator<<(basic_ostream<_Elem, _Traits>& _Ostr, + const poisson_distribution& _Dist) { // write state to _Ostr + _Out(_Ostr, _Dist._Par._Mean); return _Ostr; } @@ -2398,28 +2324,6 @@ private: param_type _Par; }; -template -_NODISCARD bool operator==(const poisson_distribution<_Ty>& _Left, const poisson_distribution<_Ty>& _Right) { - return _Left.param() == _Right.param(); -} - -template -_NODISCARD bool operator!=(const poisson_distribution<_Ty>& _Left, const poisson_distribution<_Ty>& _Right) { - return !(_Left == _Right); -} - -template -basic_istream<_Elem, _Traits>& operator>>(basic_istream<_Elem, _Traits>& _Istr, - poisson_distribution<_Ty>& _Dist) { // read state from _Istr - return _Dist._Read(_Istr); -} - -template -basic_ostream<_Elem, _Traits>& operator<<(basic_ostream<_Elem, _Traits>& _Ostr, - const poisson_distribution<_Ty>& _Dist) { // write state to _Ostr - return _Dist._Write(_Ostr); -} - template class binomial_distribution { // binomial distribution public: @@ -2440,13 +2344,15 @@ public: _Init(_Tx0, _Px0); } - _NODISCARD bool operator==(const param_type& _Right) const { - return _Tx == _Right._Tx && _Px == _Right._Px; + _NODISCARD_FRIEND bool operator==(const param_type& _Left, const param_type& _Right) { + return _Left._Tx == _Right._Tx && _Left._Px == _Right._Px; } - _NODISCARD bool operator!=(const param_type& _Right) const { - return !(*this == _Right); +#if !_HAS_CXX20 + _NODISCARD_FRIEND bool operator!=(const param_type& _Left, const param_type& _Right) { + return !(_Left == _Right); } +#endif // !_HAS_CXX20 _NODISCARD _Ty t() const { return _Tx; @@ -2524,20 +2430,32 @@ public: return _Eval(_Eng, _Par0); } + _NODISCARD_FRIEND bool operator==(const binomial_distribution& _Left, const binomial_distribution& _Right) { + return _Left.param() == _Right.param(); + } + +#if !_HAS_CXX20 + _NODISCARD_FRIEND bool operator!=(const binomial_distribution& _Left, const binomial_distribution& _Right) { + return !(_Left == _Right); + } +#endif // !_HAS_CXX20 + template - basic_istream<_Elem, _Traits>& _Read(basic_istream<_Elem, _Traits>& _Istr) { // read state from _Istr - _Ty _Tx0; - _Ty1 _Px0; + friend basic_istream<_Elem, _Traits>& operator>>(basic_istream<_Elem, _Traits>& _Istr, + binomial_distribution& _Dist) { // read state from _Istr + binomial_distribution::result_type _Tx0; + binomial_distribution::_Ty1 _Px0; _In(_Istr, _Px0); _In(_Istr, _Tx0); - _Par._Init(_Tx0, _Px0); + _Dist._Par._Init(_Tx0, _Px0); return _Istr; } template - basic_ostream<_Elem, _Traits>& _Write(basic_ostream<_Elem, _Traits>& _Ostr) const { // write state to _Ostr - _Out(_Ostr, _Par._Px); - _Out(_Ostr, _Par._Tx); + friend basic_ostream<_Elem, _Traits>& operator<<(basic_ostream<_Elem, _Traits>& _Ostr, + const binomial_distribution& _Dist) { // write state to _Ostr + _Out(_Ostr, _Dist._Par._Px); + _Out(_Ostr, _Dist._Par._Tx); return _Ostr; } @@ -2604,28 +2522,6 @@ private: param_type _Par; }; -template -_NODISCARD bool operator==(const binomial_distribution<_Ty>& _Left, const binomial_distribution<_Ty>& _Right) { - return _Left.param() == _Right.param(); -} - -template -_NODISCARD bool operator!=(const binomial_distribution<_Ty>& _Left, const binomial_distribution<_Ty>& _Right) { - return !(_Left == _Right); -} - -template -basic_istream<_Elem, _Traits>& operator>>(basic_istream<_Elem, _Traits>& _Istr, - binomial_distribution<_Ty>& _Dist) { // read state from _Istr - return _Dist._Read(_Istr); -} - -template -basic_ostream<_Elem, _Traits>& operator<<(basic_ostream<_Elem, _Traits>& _Ostr, - const binomial_distribution<_Ty>& _Dist) { // write state to _Ostr - return _Dist._Write(_Ostr); -} - template class uniform_real { // uniform real distribution public: @@ -2642,13 +2538,15 @@ public: _Init(_Min0, _Max0); } - _NODISCARD bool operator==(const param_type& _Right) const { - return _Min == _Right._Min && _Max == _Right._Max; + _NODISCARD_FRIEND bool operator==(const param_type& _Left, const param_type& _Right) { + return _Left._Min == _Right._Min && _Left._Max == _Right._Max; } - _NODISCARD bool operator!=(const param_type& _Right) const { - return !(*this == _Right); +#if !_HAS_CXX20 + _NODISCARD_FRIEND bool operator!=(const param_type& _Left, const param_type& _Right) { + return !(_Left == _Right); } +#endif // !_HAS_CXX20 _NODISCARD result_type a() const { return _Min; @@ -2711,6 +2609,18 @@ public: 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; @@ -2737,18 +2647,6 @@ private: param_type _Par; }; -template -basic_istream<_Elem, _Traits>& operator>>(basic_istream<_Elem, _Traits>& _Istr, - uniform_real<_Ty>& _Dist) { // read state from _Istr - return _Dist._Read(_Istr); -} - -template -basic_ostream<_Elem, _Traits>& operator<<(basic_ostream<_Elem, _Traits>& _Ostr, - const uniform_real<_Ty>& _Dist) { // write state to _Ostr - return _Dist._Write(_Ostr); -} - template class uniform_real_distribution : public uniform_real<_Ty> { // uniform real distribution public: @@ -2773,17 +2671,17 @@ public: explicit uniform_real_distribution(_Ty _Min0, _Ty _Max0 = _Ty{1}) : _Mybase(_Min0, _Max0) {} explicit uniform_real_distribution(const param_type& _Par0) : _Mybase(_Par0) {} -}; -template -_NODISCARD bool operator==(const uniform_real_distribution<_Ty>& _Left, const uniform_real_distribution<_Ty>& _Right) { - return _Left.param() == _Right.param(); -} + _NODISCARD_FRIEND bool operator==(const uniform_real_distribution& _Left, const uniform_real_distribution& _Right) { + return _Left.param() == _Right.param(); + } -template -_NODISCARD bool operator!=(const uniform_real_distribution<_Ty>& _Left, const uniform_real_distribution<_Ty>& _Right) { - return !(_Left == _Right); -} +#if !_HAS_CXX20 + _NODISCARD_FRIEND bool operator!=(const uniform_real_distribution& _Left, const uniform_real_distribution& _Right) { + return !(_Left == _Right); + } +#endif // !_HAS_CXX20 +}; template class exponential_distribution { // exponential distribution @@ -2803,13 +2701,15 @@ public: _Init(_Lambda0); } - _NODISCARD bool operator==(const param_type& _Right) const { - return _Lambda == _Right._Lambda; + _NODISCARD_FRIEND bool operator==(const param_type& _Left, const param_type& _Right) { + return _Left._Lambda == _Right._Lambda; } - _NODISCARD bool operator!=(const param_type& _Right) const { - return !(*this == _Right); +#if !_HAS_CXX20 + _NODISCARD_FRIEND bool operator!=(const param_type& _Left, const param_type& _Right) { + return !(_Left == _Right); } +#endif // !_HAS_CXX20 _NODISCARD _Ty lambda() const { return _Lambda; @@ -2861,17 +2761,29 @@ public: return _Eval(_Eng, _Par0); } + _NODISCARD_FRIEND bool operator==(const exponential_distribution& _Left, const exponential_distribution& _Right) { + return _Left.param() == _Right.param(); + } + +#if !_HAS_CXX20 + _NODISCARD_FRIEND bool operator!=(const exponential_distribution& _Left, const exponential_distribution& _Right) { + return !(_Left == _Right); + } +#endif // !_HAS_CXX20 + template - basic_istream<_Elem, _Traits>& _Read(basic_istream<_Elem, _Traits>& _Istr) { // read state from _Istr - _Ty _Lambda0; + friend basic_istream<_Elem, _Traits>& operator>>(basic_istream<_Elem, _Traits>& _Istr, + exponential_distribution& _Dist) { // read state from _Istr + exponential_distribution::result_type _Lambda0; _In(_Istr, _Lambda0); - _Par._Init(_Lambda0); + _Dist._Par._Init(_Lambda0); return _Istr; } template - basic_ostream<_Elem, _Traits>& _Write(basic_ostream<_Elem, _Traits>& _Ostr) const { // write state to _Ostr - _Out(_Ostr, _Par._Lambda); + friend basic_ostream<_Elem, _Traits>& operator<<(basic_ostream<_Elem, _Traits>& _Ostr, + const exponential_distribution& _Dist) { // write state to _Ostr + _Out(_Ostr, _Dist._Par._Lambda); return _Ostr; } @@ -2884,28 +2796,6 @@ private: param_type _Par; }; -template -_NODISCARD bool operator==(const exponential_distribution<_Ty>& _Left, const exponential_distribution<_Ty>& _Right) { - return _Left.param() == _Right.param(); -} - -template -_NODISCARD bool operator!=(const exponential_distribution<_Ty>& _Left, const exponential_distribution<_Ty>& _Right) { - return !(_Left == _Right); -} - -template -basic_istream<_Elem, _Traits>& operator>>(basic_istream<_Elem, _Traits>& _Istr, - exponential_distribution<_Ty>& _Dist) { // read state from _Istr - return _Dist._Read(_Istr); -} - -template -basic_ostream<_Elem, _Traits>& operator<<(basic_ostream<_Elem, _Traits>& _Ostr, - const exponential_distribution<_Ty>& _Dist) { // write state to _Ostr - return _Dist._Write(_Ostr); -} - template class normal_distribution { // normal distribution public: @@ -2924,13 +2814,15 @@ public: _Init(_Mean0, _Sigma0); } - _NODISCARD bool operator==(const param_type& _Right) const { - return _Mean == _Right._Mean && _Sigma == _Right._Sigma; + _NODISCARD_FRIEND bool operator==(const param_type& _Left, const param_type& _Right) { + return _Left._Mean == _Right._Mean && _Left._Sigma == _Right._Sigma; } - _NODISCARD bool operator!=(const param_type& _Right) const { - return !(*this == _Right); +#if !_HAS_CXX20 + _NODISCARD_FRIEND bool operator!=(const param_type& _Left, const param_type& _Right) { + return !(_Left == _Right); } +#endif // !_HAS_CXX20 _NODISCARD _Ty mean() const { return _Mean; @@ -3004,26 +2896,38 @@ public: return _Eval(_Eng, _Par0, false); } + _NODISCARD_FRIEND bool operator==(const normal_distribution& _Left, const normal_distribution& _Right) { + return _Left.param() == _Right.param(); + } + +#if !_HAS_CXX20 + _NODISCARD_FRIEND bool operator!=(const normal_distribution& _Left, const normal_distribution& _Right) { + return !(_Left == _Right); + } +#endif // !_HAS_CXX20 + template - basic_istream<_Elem, _Traits>& _Read(basic_istream<_Elem, _Traits>& _Istr) { // read state from _Istr - _Ty _Mean0; - _Ty _Sigma0; + friend basic_istream<_Elem, _Traits>& operator>>(basic_istream<_Elem, _Traits>& _Istr, + normal_distribution& _Dist) { // read state from _Istr + normal_distribution::result_type _Mean0; + normal_distribution::result_type _Sigma0; _In(_Istr, _Mean0); _In(_Istr, _Sigma0); - _Par._Init(_Mean0, _Sigma0); + _Dist._Par._Init(_Mean0, _Sigma0); - _Istr >> _Valid; - _In(_Istr, _Xx2); + _Istr >> _Dist._Valid; + _In(_Istr, _Dist._Xx2); return _Istr; } template - basic_ostream<_Elem, _Traits>& _Write(basic_ostream<_Elem, _Traits>& _Ostr) const { // write state to _Ostr - _Out(_Ostr, _Par._Mean); - _Out(_Ostr, _Par._Sigma); + friend basic_ostream<_Elem, _Traits>& operator<<(basic_ostream<_Elem, _Traits>& _Ostr, + const normal_distribution& _Dist) { // write state to _Ostr + _Out(_Ostr, _Dist._Par._Mean); + _Out(_Ostr, _Dist._Par._Sigma); - _Ostr << ' ' << _Valid; - _Out(_Ostr, _Xx2); + _Ostr << ' ' << _Dist._Valid; + _Out(_Ostr, _Dist._Xx2); return _Ostr; } @@ -3080,28 +2984,6 @@ private: _Ty _Xx2; }; -template -_NODISCARD bool operator==(const normal_distribution<_Ty>& _Left, const normal_distribution<_Ty>& _Right) { - return _Left.param() == _Right.param(); -} - -template -_NODISCARD bool operator!=(const normal_distribution<_Ty>& _Left, const normal_distribution<_Ty>& _Right) { - return !(_Left == _Right); -} - -template -basic_istream<_Elem, _Traits>& operator>>(basic_istream<_Elem, _Traits>& _Istr, - normal_distribution<_Ty>& _Dist) { // read state from _Istr - return _Dist._Read(_Istr); -} - -template -basic_ostream<_Elem, _Traits>& operator<<(basic_ostream<_Elem, _Traits>& _Ostr, - const normal_distribution<_Ty>& _Dist) { // write state to _Ostr - return _Dist._Write(_Ostr); -} - template class gamma_distribution { // gamma distribution public: @@ -3120,13 +3002,15 @@ public: _Init(_Alpha0, _Beta0); } - _NODISCARD bool operator==(const param_type& _Right) const { - return _Alpha == _Right._Alpha && _Beta == _Right._Beta; + _NODISCARD_FRIEND bool operator==(const param_type& _Left, const param_type& _Right) { + return _Left._Alpha == _Right._Alpha && _Left._Beta == _Right._Beta; } - _NODISCARD bool operator!=(const param_type& _Right) const { - return !(*this == _Right); +#if !_HAS_CXX20 + _NODISCARD_FRIEND bool operator!=(const param_type& _Left, const param_type& _Right) { + return !(_Left == _Right); } +#endif // !_HAS_CXX20 _NODISCARD _Ty alpha() const { return _Alpha; @@ -3194,20 +3078,32 @@ public: return _Eval(_Eng, _Par0); } + _NODISCARD_FRIEND bool operator==(const gamma_distribution& _Left, const gamma_distribution& _Right) { + return _Left.param() == _Right.param(); + } + +#if !_HAS_CXX20 + _NODISCARD_FRIEND bool operator!=(const gamma_distribution& _Left, const gamma_distribution& _Right) { + return !(_Left == _Right); + } +#endif // !_HAS_CXX20 + template - basic_istream<_Elem, _Traits>& _Read(basic_istream<_Elem, _Traits>& _Istr) { // read state from _Istr - _Ty _Alpha0; - _Ty _Beta0; + friend basic_istream<_Elem, _Traits>& operator>>(basic_istream<_Elem, _Traits>& _Istr, + gamma_distribution& _Dist) { // read state from _Istr + gamma_distribution::result_type _Alpha0; + gamma_distribution::result_type _Beta0; _In(_Istr, _Alpha0); _In(_Istr, _Beta0); - _Par._Init(_Alpha0, _Beta0); + _Dist._Par._Init(_Alpha0, _Beta0); return _Istr; } template - basic_ostream<_Elem, _Traits>& _Write(basic_ostream<_Elem, _Traits>& _Ostr) const { // write state to _Ostr - _Out(_Ostr, _Par._Alpha); - _Out(_Ostr, _Par._Beta); + friend basic_ostream<_Elem, _Traits>& operator<<(basic_ostream<_Elem, _Traits>& _Ostr, + const gamma_distribution& _Dist) { // write state to _Ostr + _Out(_Ostr, _Dist._Par._Alpha); + _Out(_Ostr, _Dist._Par._Beta); return _Ostr; } @@ -3275,28 +3171,6 @@ private: param_type _Par; }; -template -_NODISCARD bool operator==(const gamma_distribution<_Ty>& _Left, const gamma_distribution<_Ty>& _Right) { - return _Left.param() == _Right.param(); -} - -template -_NODISCARD bool operator!=(const gamma_distribution<_Ty>& _Left, const gamma_distribution<_Ty>& _Right) { - return !(_Left == _Right); -} - -template -basic_istream<_Elem, _Traits>& operator>>(basic_istream<_Elem, _Traits>& _Istr, - gamma_distribution<_Ty>& _Dist) { // read state from _Istr - return _Dist._Read(_Istr); -} - -template -basic_ostream<_Elem, _Traits>& operator<<(basic_ostream<_Elem, _Traits>& _Ostr, - const gamma_distribution<_Ty>& _Dist) { // write state to _Ostr - return _Dist._Write(_Ostr); -} - template class weibull_distribution { // weibull distribution public: @@ -3315,13 +3189,15 @@ public: _Init(_Ax0, _Bx0); } - _NODISCARD bool operator==(const param_type& _Right) const { - return _Ax == _Right._Ax && _Bx == _Right._Bx; + _NODISCARD_FRIEND bool operator==(const param_type& _Left, const param_type& _Right) { + return _Left._Ax == _Right._Ax && _Left._Bx == _Right._Bx; } - _NODISCARD bool operator!=(const param_type& _Right) const { - return !(*this == _Right); +#if !_HAS_CXX20 + _NODISCARD_FRIEND bool operator!=(const param_type& _Left, const param_type& _Right) { + return !(_Left == _Right); } +#endif // !_HAS_CXX20 _NODISCARD _Ty a() const { return _Ax; @@ -3384,20 +3260,32 @@ public: return _Eval(_Eng, _Par0); } + _NODISCARD_FRIEND bool operator==(const weibull_distribution& _Left, const weibull_distribution& _Right) { + return _Left.param() == _Right.param(); + } + +#if !_HAS_CXX20 + _NODISCARD_FRIEND bool operator!=(const weibull_distribution& _Left, const weibull_distribution& _Right) { + return !(_Left == _Right); + } +#endif // !_HAS_CXX20 + template - basic_istream<_Elem, _Traits>& _Read(basic_istream<_Elem, _Traits>& _Istr) { // read state from _Istr - _Ty _Ax0; - _Ty _Bx0; + friend basic_istream<_Elem, _Traits>& operator>>(basic_istream<_Elem, _Traits>& _Istr, + weibull_distribution& _Dist) { // read state from _Istr + weibull_distribution::result_type _Ax0; + weibull_distribution::result_type _Bx0; _In(_Istr, _Ax0); _In(_Istr, _Bx0); - _Par._Init(_Ax0, _Bx0); + _Dist._Par._Init(_Ax0, _Bx0); return _Istr; } template - basic_ostream<_Elem, _Traits>& _Write(basic_ostream<_Elem, _Traits>& _Ostr) const { // write state to _Ostr - _Out(_Ostr, _Par._Ax); - _Out(_Ostr, _Par._Bx); + friend basic_ostream<_Elem, _Traits>& operator<<(basic_ostream<_Elem, _Traits>& _Ostr, + const weibull_distribution& _Dist) { // write state to _Ostr + _Out(_Ostr, _Dist._Par._Ax); + _Out(_Ostr, _Dist._Par._Bx); return _Ostr; } @@ -3411,28 +3299,6 @@ private: param_type _Par; }; -template -_NODISCARD bool operator==(const weibull_distribution<_Ty>& _Left, const weibull_distribution<_Ty>& _Right) { - return _Left.param() == _Right.param(); -} - -template -_NODISCARD bool operator!=(const weibull_distribution<_Ty>& _Left, const weibull_distribution<_Ty>& _Right) { - return !(_Left == _Right); -} - -template -basic_istream<_Elem, _Traits>& operator>>(basic_istream<_Elem, _Traits>& _Istr, - weibull_distribution<_Ty>& _Dist) { // read state from _Istr - return _Dist._Read(_Istr); -} - -template -basic_ostream<_Elem, _Traits>& operator<<(basic_ostream<_Elem, _Traits>& _Ostr, - const weibull_distribution<_Ty>& _Dist) { // write state to _Ostr - return _Dist._Write(_Ostr); -} - template class extreme_value_distribution { // extreme value distribution public: @@ -3451,13 +3317,15 @@ public: _Init(_Ax0, _Bx0); } - _NODISCARD bool operator==(const param_type& _Right) const { - return _Ax == _Right._Ax && _Bx == _Right._Bx; + _NODISCARD_FRIEND bool operator==(const param_type& _Left, const param_type& _Right) { + return _Left._Ax == _Right._Ax && _Left._Bx == _Right._Bx; } - _NODISCARD bool operator!=(const param_type& _Right) const { - return !(*this == _Right); +#if !_HAS_CXX20 + _NODISCARD_FRIEND bool operator!=(const param_type& _Left, const param_type& _Right) { + return !(_Left == _Right); } +#endif // !_HAS_CXX20 _NODISCARD _Ty a() const { return _Ax; @@ -3519,20 +3387,34 @@ public: return _Eval(_Eng, _Par0); } + _NODISCARD_FRIEND bool operator==( + const extreme_value_distribution& _Left, const extreme_value_distribution& _Right) { + return _Left.param() == _Right.param(); + } + +#if !_HAS_CXX20 + _NODISCARD_FRIEND bool operator!=( + const extreme_value_distribution& _Left, const extreme_value_distribution& _Right) { + return !(_Left == _Right); + } +#endif // !_HAS_CXX20 + template - basic_istream<_Elem, _Traits>& _Read(basic_istream<_Elem, _Traits>& _Istr) { // read state from _Istr - _Ty _Ax0; - _Ty _Bx0; + friend basic_istream<_Elem, _Traits>& operator>>(basic_istream<_Elem, _Traits>& _Istr, + extreme_value_distribution& _Dist) { // read state from _Istr + extreme_value_distribution::result_type _Ax0; + extreme_value_distribution::result_type _Bx0; _In(_Istr, _Ax0); _In(_Istr, _Bx0); - _Par._Init(_Ax0, _Bx0); + _Dist._Par._Init(_Ax0, _Bx0); return _Istr; } template - basic_ostream<_Elem, _Traits>& _Write(basic_ostream<_Elem, _Traits>& _Ostr) const { // write state to _Ostr - _Out(_Ostr, _Par._Ax); - _Out(_Ostr, _Par._Bx); + friend basic_ostream<_Elem, _Traits>& operator<<(basic_ostream<_Elem, _Traits>& _Ostr, + const extreme_value_distribution& _Dist) { // write state to _Ostr + _Out(_Ostr, _Dist._Par._Ax); + _Out(_Ostr, _Dist._Par._Bx); return _Ostr; } @@ -3546,30 +3428,6 @@ private: param_type _Par; }; -template -_NODISCARD bool operator==( - const extreme_value_distribution<_Ty>& _Left, const extreme_value_distribution<_Ty>& _Right) { - return _Left.param() == _Right.param(); -} - -template -_NODISCARD bool operator!=( - const extreme_value_distribution<_Ty>& _Left, const extreme_value_distribution<_Ty>& _Right) { - return !(_Left == _Right); -} - -template -basic_istream<_Elem, _Traits>& operator>>(basic_istream<_Elem, _Traits>& _Istr, - extreme_value_distribution<_Ty>& _Dist) { // read state from _Istr - return _Dist._Read(_Istr); -} - -template -basic_ostream<_Elem, _Traits>& operator<<(basic_ostream<_Elem, _Traits>& _Ostr, - const extreme_value_distribution<_Ty>& _Dist) { // write state to _Ostr - return _Dist._Write(_Ostr); -} - template class lognormal_distribution { // lognormal_distribution public: @@ -3588,13 +3446,15 @@ public: _Init(_Mx0, _Sx0); } - _NODISCARD bool operator==(const param_type& _Right) const { - return _Mx == _Right._Mx && _Sx == _Right._Sx; + _NODISCARD_FRIEND bool operator==(const param_type& _Left, const param_type& _Right) { + return _Left._Mx == _Right._Mx && _Left._Sx == _Right._Sx; } - _NODISCARD bool operator!=(const param_type& _Right) const { - return !(*this == _Right); +#if !_HAS_CXX20 + _NODISCARD_FRIEND bool operator!=(const param_type& _Left, const param_type& _Right) { + return !(_Left == _Right); } +#endif // !_HAS_CXX20 _NODISCARD _Ty m() const { return _Mx; @@ -3656,20 +3516,32 @@ public: return _Eval(_Eng, _Par0); } + _NODISCARD_FRIEND bool operator==(const lognormal_distribution& _Left, const lognormal_distribution& _Right) { + return _Left.param() == _Right.param(); + } + +#if !_HAS_CXX20 + _NODISCARD_FRIEND bool operator!=(const lognormal_distribution& _Left, const lognormal_distribution& _Right) { + return !(_Left == _Right); + } +#endif // !_HAS_CXX20 + template - basic_istream<_Elem, _Traits>& _Read(basic_istream<_Elem, _Traits>& _Istr) { // read state from _Istr - _Ty _Mx0; - _Ty _Sx0; + friend basic_istream<_Elem, _Traits>& operator>>(basic_istream<_Elem, _Traits>& _Istr, + lognormal_distribution& _Dist) { // read state from _Istr + lognormal_distribution::result_type _Mx0; + lognormal_distribution::result_type _Sx0; _In(_Istr, _Mx0); _In(_Istr, _Sx0); - _Par._Init(_Mx0, _Sx0); + _Dist._Par._Init(_Mx0, _Sx0); return _Istr; } template - basic_ostream<_Elem, _Traits>& _Write(basic_ostream<_Elem, _Traits>& _Ostr) const { // write state to _Ostr - _Out(_Ostr, _Par._Mx); - _Out(_Ostr, _Par._Sx); + friend basic_ostream<_Elem, _Traits>& operator<<(basic_ostream<_Elem, _Traits>& _Ostr, + const lognormal_distribution& _Dist) { // write state to _Ostr + _Out(_Ostr, _Dist._Par._Mx); + _Out(_Ostr, _Dist._Par._Sx); return _Ostr; } @@ -3683,28 +3555,6 @@ private: param_type _Par; }; -template -_NODISCARD bool operator==(const lognormal_distribution<_Ty>& _Left, const lognormal_distribution<_Ty>& _Right) { - return _Left.param() == _Right.param(); -} - -template -_NODISCARD bool operator!=(const lognormal_distribution<_Ty>& _Left, const lognormal_distribution<_Ty>& _Right) { - return !(_Left == _Right); -} - -template -basic_istream<_Elem, _Traits>& operator>>(basic_istream<_Elem, _Traits>& _Istr, - lognormal_distribution<_Ty>& _Dist) { // read state from _Istr - return _Dist._Read(_Istr); -} - -template -basic_ostream<_Elem, _Traits>& operator<<(basic_ostream<_Elem, _Traits>& _Ostr, - const lognormal_distribution<_Ty>& _Dist) { // write state to _Ostr - return _Dist._Write(_Ostr); -} - template class chi_squared_distribution { // chi squared distribution public: @@ -3723,13 +3573,15 @@ public: _Init(_Nx0); } - _NODISCARD bool operator==(const param_type& _Right) const { - return _Nx == _Right._Nx; + _NODISCARD_FRIEND bool operator==(const param_type& _Left, const param_type& _Right) { + return _Left._Nx == _Right._Nx; } - _NODISCARD bool operator!=(const param_type& _Right) const { - return !(*this == _Right); +#if !_HAS_CXX20 + _NODISCARD_FRIEND bool operator!=(const param_type& _Left, const param_type& _Right) { + return !(_Left == _Right); } +#endif // !_HAS_CXX20 _NODISCARD _Ty n() const { return _Nx; @@ -3781,17 +3633,29 @@ public: return _Eval(_Eng, _Par0); } + _NODISCARD_FRIEND bool operator==(const chi_squared_distribution& _Left, const chi_squared_distribution& _Right) { + return _Left.param() == _Right.param(); + } + +#if !_HAS_CXX20 + _NODISCARD_FRIEND bool operator!=(const chi_squared_distribution& _Left, const chi_squared_distribution& _Right) { + return !(_Left == _Right); + } +#endif // !_HAS_CXX20 + template - basic_istream<_Elem, _Traits>& _Read(basic_istream<_Elem, _Traits>& _Istr) { // read state from _Istr - _Ty _Nx0; + friend basic_istream<_Elem, _Traits>& operator>>(basic_istream<_Elem, _Traits>& _Istr, + chi_squared_distribution& _Dist) { // read state from _Istr + chi_squared_distribution::result_type _Nx0; _Istr >> _Nx0; - _Par._Init(_Nx0); + _Dist._Par._Init(_Nx0); return _Istr; } template - basic_ostream<_Elem, _Traits>& _Write(basic_ostream<_Elem, _Traits>& _Ostr) const { // write state to _Ostr - return _Ostr << ' ' << _Par._Nx; + friend basic_ostream<_Elem, _Traits>& operator<<(basic_ostream<_Elem, _Traits>& _Ostr, + const chi_squared_distribution& _Dist) { // write state to _Ostr + return _Ostr << ' ' << _Dist._Par._Nx; } private: @@ -3804,28 +3668,6 @@ private: param_type _Par; }; -template -_NODISCARD bool operator==(const chi_squared_distribution<_Ty>& _Left, const chi_squared_distribution<_Ty>& _Right) { - return _Left.param() == _Right.param(); -} - -template -_NODISCARD bool operator!=(const chi_squared_distribution<_Ty>& _Left, const chi_squared_distribution<_Ty>& _Right) { - return !(_Left == _Right); -} - -template -basic_istream<_Elem, _Traits>& operator>>(basic_istream<_Elem, _Traits>& _Istr, - chi_squared_distribution<_Ty>& _Dist) { // read state from _Istr - return _Dist._Read(_Istr); -} - -template -basic_ostream<_Elem, _Traits>& operator<<(basic_ostream<_Elem, _Traits>& _Ostr, - const chi_squared_distribution<_Ty>& _Dist) { // write state to _Ostr - return _Dist._Write(_Ostr); -} - template class cauchy_distribution { // Cauchy distribution public: @@ -3844,13 +3686,15 @@ public: _Init(_Ax0, _Bx0); } - _NODISCARD bool operator==(const param_type& _Right) const { - return _Ax == _Right._Ax && _Bx == _Right._Bx; + _NODISCARD_FRIEND bool operator==(const param_type& _Left, const param_type& _Right) { + return _Left._Ax == _Right._Ax && _Left._Bx == _Right._Bx; } - _NODISCARD bool operator!=(const param_type& _Right) const { - return !(*this == _Right); +#if !_HAS_CXX20 + _NODISCARD_FRIEND bool operator!=(const param_type& _Left, const param_type& _Right) { + return !(_Left == _Right); } +#endif // !_HAS_CXX20 _NODISCARD _Ty a() const { return _Ax; @@ -3912,20 +3756,32 @@ public: return _Eval(_Eng, _Par0); } + _NODISCARD_FRIEND bool operator==(const cauchy_distribution& _Left, const cauchy_distribution& _Right) { + return _Left.param() == _Right.param(); + } + +#if !_HAS_CXX20 + _NODISCARD_FRIEND bool operator!=(const cauchy_distribution& _Left, const cauchy_distribution& _Right) { + return !(_Left == _Right); + } +#endif // !_HAS_CXX20 + template - basic_istream<_Elem, _Traits>& _Read(basic_istream<_Elem, _Traits>& _Istr) { // read state from _Istr - _Ty _Ax0; - _Ty _Bx0; + friend basic_istream<_Elem, _Traits>& operator>>(basic_istream<_Elem, _Traits>& _Istr, + cauchy_distribution& _Dist) { // read state from _Istr + cauchy_distribution::result_type _Ax0; + cauchy_distribution::result_type _Bx0; _In(_Istr, _Ax0); _In(_Istr, _Bx0); - _Par._Init(_Ax0, _Bx0); + _Dist._Par._Init(_Ax0, _Bx0); return _Istr; } template - basic_ostream<_Elem, _Traits>& _Write(basic_ostream<_Elem, _Traits>& _Ostr) const { // write state to _Ostr - _Out(_Ostr, _Par._Ax); - _Out(_Ostr, _Par._Bx); + friend basic_ostream<_Elem, _Traits>& operator<<(basic_ostream<_Elem, _Traits>& _Ostr, + const cauchy_distribution& _Dist) { // write state to _Ostr + _Out(_Ostr, _Dist._Par._Ax); + _Out(_Ostr, _Dist._Par._Bx); return _Ostr; } @@ -3939,28 +3795,6 @@ private: param_type _Par; }; -template -_NODISCARD bool operator==(const cauchy_distribution<_Ty>& _Left, const cauchy_distribution<_Ty>& _Right) { - return _Left.param() == _Right.param(); -} - -template -_NODISCARD bool operator!=(const cauchy_distribution<_Ty>& _Left, const cauchy_distribution<_Ty>& _Right) { - return !(_Left == _Right); -} - -template -basic_istream<_Elem, _Traits>& operator>>(basic_istream<_Elem, _Traits>& _Istr, - cauchy_distribution<_Ty>& _Dist) { // read state from _Istr - return _Dist._Read(_Istr); -} - -template -basic_ostream<_Elem, _Traits>& operator<<(basic_ostream<_Elem, _Traits>& _Ostr, - const cauchy_distribution<_Ty>& _Dist) { // write state to _Ostr - return _Dist._Write(_Ostr); -} - template class _Beta_distribution { // beta distribution public: @@ -4038,13 +3872,15 @@ public: _Init(_Mx0, _Nx0); } - _NODISCARD bool operator==(const param_type& _Right) const { - return _Mx == _Right._Mx && _Nx == _Right._Nx; + _NODISCARD_FRIEND bool operator==(const param_type& _Left, const param_type& _Right) { + return _Left._Mx == _Right._Mx && _Left._Nx == _Right._Nx; } - _NODISCARD bool operator!=(const param_type& _Right) const { - return !(*this == _Right); +#if !_HAS_CXX20 + _NODISCARD_FRIEND bool operator!=(const param_type& _Left, const param_type& _Right) { + return !(_Left == _Right); } +#endif // !_HAS_CXX20 _NODISCARD _Ty m() const { return _Mx; @@ -4107,18 +3943,30 @@ public: return _Eval(_Eng, _Par0); } + _NODISCARD_FRIEND bool operator==(const fisher_f_distribution& _Left, const fisher_f_distribution& _Right) { + return _Left.param() == _Right.param(); + } + +#if !_HAS_CXX20 + _NODISCARD_FRIEND bool operator!=(const fisher_f_distribution& _Left, const fisher_f_distribution& _Right) { + return !(_Left == _Right); + } +#endif // !_HAS_CXX20 + template - basic_istream<_Elem, _Traits>& _Read(basic_istream<_Elem, _Traits>& _Istr) { // read state from _Istr - _Ty _Mx0; - _Ty _Nx0; + friend basic_istream<_Elem, _Traits>& operator>>(basic_istream<_Elem, _Traits>& _Istr, + fisher_f_distribution& _Dist) { // read state from _Istr + fisher_f_distribution::result_type _Mx0; + fisher_f_distribution::result_type _Nx0; _Istr >> _Mx0 >> _Nx0; - _Par._Init(_Mx0, _Nx0); + _Dist._Par._Init(_Mx0, _Nx0); return _Istr; } template - basic_ostream<_Elem, _Traits>& _Write(basic_ostream<_Elem, _Traits>& _Ostr) const { // write state to _Ostr - _Ostr << ' ' << _Par._Mx << ' ' << _Par._Nx; + friend basic_ostream<_Elem, _Traits>& operator<<(basic_ostream<_Elem, _Traits>& _Ostr, + const fisher_f_distribution& _Dist) { // write state to _Ostr + _Ostr << ' ' << _Dist._Par._Mx << ' ' << _Dist._Par._Nx; return _Ostr; } @@ -4145,28 +3993,6 @@ private: param_type _Par; }; -template -_NODISCARD bool operator==(const fisher_f_distribution<_Ty>& _Left, const fisher_f_distribution<_Ty>& _Right) { - return _Left.param() == _Right.param(); -} - -template -_NODISCARD bool operator!=(const fisher_f_distribution<_Ty>& _Left, const fisher_f_distribution<_Ty>& _Right) { - return !(_Left == _Right); -} - -template -basic_istream<_Elem, _Traits>& operator>>(basic_istream<_Elem, _Traits>& _Istr, - fisher_f_distribution<_Ty>& _Dist) { // read state from _Istr - return _Dist._Read(_Istr); -} - -template -basic_ostream<_Elem, _Traits>& operator<<(basic_ostream<_Elem, _Traits>& _Ostr, - const fisher_f_distribution<_Ty>& _Dist) { // write state to _Ostr - return _Dist._Write(_Ostr); -} - template class student_t_distribution { // student_t distribution public: @@ -4185,13 +4011,15 @@ public: _Init(_Nx0); } - _NODISCARD bool operator==(const param_type& _Right) const { - return _Nx == _Right._Nx; + _NODISCARD_FRIEND bool operator==(const param_type& _Left, const param_type& _Right) { + return _Left._Nx == _Right._Nx; } - _NODISCARD bool operator!=(const param_type& _Right) const { - return !(*this == _Right); +#if !_HAS_CXX20 + _NODISCARD_FRIEND bool operator!=(const param_type& _Left, const param_type& _Right) { + return !(_Left == _Right); } +#endif // !_HAS_CXX20 _NODISCARD _Ty n() const { return _Nx; @@ -4243,17 +4071,29 @@ public: return _Eval(_Eng, _Par0); } + _NODISCARD_FRIEND bool operator==(const student_t_distribution& _Left, const student_t_distribution& _Right) { + return _Left.param() == _Right.param(); + } + +#if !_HAS_CXX20 + _NODISCARD_FRIEND bool operator!=(const student_t_distribution& _Left, const student_t_distribution& _Right) { + return !(_Left == _Right); + } +#endif // !_HAS_CXX20 + template - basic_istream<_Elem, _Traits>& _Read(basic_istream<_Elem, _Traits>& _Istr) { // read state from _Istr - _Ty _Nx0; + friend basic_istream<_Elem, _Traits>& operator>>(basic_istream<_Elem, _Traits>& _Istr, + student_t_distribution& _Dist) { // read state from _Istr + student_t_distribution::result_type _Nx0; _Istr >> _Nx0; - _Par._Init(_Nx0); + _Dist._Par._Init(_Nx0); return _Istr; } template - basic_ostream<_Elem, _Traits>& _Write(basic_ostream<_Elem, _Traits>& _Ostr) const { // write state to _Ostr - return _Ostr << ' ' << _Par._Nx; + friend basic_ostream<_Elem, _Traits>& operator<<(basic_ostream<_Elem, _Traits>& _Ostr, + const student_t_distribution& _Dist) { // write state to _Ostr + return _Ostr << ' ' << _Dist._Par._Nx; } private: @@ -4281,28 +4121,6 @@ private: param_type _Par; }; -template -_NODISCARD bool operator==(const student_t_distribution<_Ty>& _Left, const student_t_distribution<_Ty>& _Right) { - return _Left.param() == _Right.param(); -} - -template -_NODISCARD bool operator!=(const student_t_distribution<_Ty>& _Left, const student_t_distribution<_Ty>& _Right) { - return !(_Left == _Right); -} - -template -basic_istream<_Elem, _Traits>& operator>>(basic_istream<_Elem, _Traits>& _Istr, - student_t_distribution<_Ty>& _Dist) { // read state from _Istr - return _Dist._Read(_Istr); -} - -template -basic_ostream<_Elem, _Traits>& operator<<(basic_ostream<_Elem, _Traits>& _Ostr, - const student_t_distribution<_Ty>& _Dist) { // write state to _Ostr - return _Dist._Write(_Ostr); -} - template class negative_binomial_distribution { // negative binomial distribution public: @@ -4321,13 +4139,15 @@ public: _Init(_Kx0, _Px0); } - _NODISCARD bool operator==(const param_type& _Right) const { - return _Kx == _Right._Kx && _Px == _Right._Px; + _NODISCARD_FRIEND bool operator==(const param_type& _Left, const param_type& _Right) { + return _Left._Kx == _Right._Kx && _Left._Px == _Right._Px; } - _NODISCARD bool operator!=(const param_type& _Right) const { - return !(*this == _Right); +#if !_HAS_CXX20 + _NODISCARD_FRIEND bool operator!=(const param_type& _Left, const param_type& _Right) { + return !(_Left == _Right); } +#endif // !_HAS_CXX20 _NODISCARD _Ty k() const { return _Kx; @@ -4392,20 +4212,34 @@ public: return _Eval(_Eng, _Par0); } + _NODISCARD_FRIEND bool operator==( + const negative_binomial_distribution& _Left, const negative_binomial_distribution& _Right) { + return _Left.param() == _Right.param(); + } + +#if !_HAS_CXX20 + _NODISCARD_FRIEND bool operator!=( + const negative_binomial_distribution& _Left, const negative_binomial_distribution& _Right) { + return !(_Left == _Right); + } +#endif // !_HAS_CXX20 + template - basic_istream<_Elem, _Traits>& _Read(basic_istream<_Elem, _Traits>& _Istr) { // read state from _Istr - _Ty _Kx0; + friend basic_istream<_Elem, _Traits>& operator>>(basic_istream<_Elem, _Traits>& _Istr, + negative_binomial_distribution& _Dist) { // read state from _Istr + negative_binomial_distribution::result_type _Kx0; double _Px0; _In(_Istr, _Px0); _In(_Istr, _Kx0); - _Par._Init(_Kx0, _Px0); + _Dist._Par._Init(_Kx0, _Px0); return _Istr; } template - basic_ostream<_Elem, _Traits>& _Write(basic_ostream<_Elem, _Traits>& _Ostr) const { // write state to _Ostr - _Out(_Ostr, _Par._Px); - _Out(_Ostr, _Par._Kx); + friend basic_ostream<_Elem, _Traits>& operator<<(basic_ostream<_Elem, _Traits>& _Ostr, + const negative_binomial_distribution& _Dist) { // write state to _Ostr + _Out(_Ostr, _Dist._Par._Px); + _Out(_Ostr, _Dist._Par._Kx); return _Ostr; } @@ -4424,30 +4258,6 @@ private: param_type _Par; }; -template -_NODISCARD bool operator==( - const negative_binomial_distribution<_Ty>& _Left, const negative_binomial_distribution<_Ty>& _Right) { - return _Left.param() == _Right.param(); -} - -template -_NODISCARD bool operator!=( - const negative_binomial_distribution<_Ty>& _Left, const negative_binomial_distribution<_Ty>& _Right) { - return !(_Left == _Right); -} - -template -basic_istream<_Elem, _Traits>& operator>>(basic_istream<_Elem, _Traits>& _Istr, - negative_binomial_distribution<_Ty>& _Dist) { // read state from _Istr - return _Dist._Read(_Istr); -} - -template -basic_ostream<_Elem, _Traits>& operator<<(basic_ostream<_Elem, _Traits>& _Ostr, - const negative_binomial_distribution<_Ty>& _Dist) { // write state to _Ostr - return _Dist._Write(_Ostr); -} - template class discrete_distribution { // discrete integer distribution public: @@ -4491,13 +4301,15 @@ public: _Init(); } - _NODISCARD bool operator==(const param_type& _Right) const { - return _Pvec == _Right._Pvec; + _NODISCARD_FRIEND bool operator==(const param_type& _Left, const param_type& _Right) { + return _Left._Pvec == _Right._Pvec; } - _NODISCARD bool operator!=(const param_type& _Right) const { - return !(*this == _Right); +#if !_HAS_CXX20 + _NODISCARD_FRIEND bool operator!=(const param_type& _Left, const param_type& _Right) { + return !(_Left == _Right); } +#endif // !_HAS_CXX20 _NODISCARD _Myvec probabilities() const { return _Pvec; @@ -4533,6 +4345,32 @@ public: } } + template + basic_istream<_Elem, _Traits>& _Read(basic_istream<_Elem, _Traits>& _Istr) { // read state from _Istr + size_t _Nvals; + _Istr >> _Nvals; + _Pvec.clear(); + for (; 0 < _Nvals; --_Nvals) { // get a value and add to vector + double _Val; + _In(_Istr, _Val); + _Pvec.push_back(_Val); + } + _Init(false); // don't renormalize, just compute CDF + return _Istr; + } + + template + basic_ostream<_Elem, _Traits>& _Write(basic_ostream<_Elem, _Traits>& _Ostr) const { // write state to _Ostr + const size_t _Nvals = _Pvec.size(); + _Ostr << ' ' << _Nvals; + + for (size_t _Idx = 0; _Idx < _Nvals; ++_Idx) { + _Out(_Ostr, _Pvec[_Idx]); + } + + return _Ostr; + } + _Myvec _Pvec; _Myvec _Pcdf; }; @@ -4581,32 +4419,26 @@ public: return _Eval(_Eng, _Par0); } - template - basic_istream<_Elem, _Traits>& _Read(basic_istream<_Elem, _Traits>& _Istr, - param_type& _Par0) { // read state from _Istr - size_t _Nvals; - _Istr >> _Nvals; - _Par0._Pvec.clear(); - for (; 0 < _Nvals; --_Nvals) { // get a value and add to vector - double _Val; - _In(_Istr, _Val); - _Par0._Pvec.push_back(_Val); - } - _Par0._Init(false); // don't renormalize, just compute CDF - return _Istr; + _NODISCARD_FRIEND bool operator==(const discrete_distribution& _Left, const discrete_distribution& _Right) { + return _Left.param() == _Right.param(); } - template - basic_ostream<_Elem, _Traits>& _Write(basic_ostream<_Elem, _Traits>& _Ostr, - const param_type& _Par0) const { // write state to _Ostr - size_t _Nvals = _Par0._Pvec.size(); - _Ostr << ' ' << _Nvals; +#if !_HAS_CXX20 + _NODISCARD_FRIEND bool operator!=(const discrete_distribution& _Left, const discrete_distribution& _Right) { + return !(_Left == _Right); + } +#endif // !_HAS_CXX20 - for (size_t _Idx = 0; _Idx < _Par0._Pvec.size(); ++_Idx) { - _Out(_Ostr, _Par0._Pvec[_Idx]); - } + template + friend basic_istream<_Elem, _Traits>& operator>>(basic_istream<_Elem, _Traits>& _Istr, + discrete_distribution& _Dist) { // read state from _Istr + return _Dist._Par._Read(_Istr); + } - return _Ostr; + template + friend basic_ostream<_Elem, _Traits>& operator<<(basic_ostream<_Elem, _Traits>& _Ostr, + const discrete_distribution& _Dist) { // write state to _Ostr + return _Dist._Par._Write(_Ostr); } private: @@ -4622,31 +4454,10 @@ public: param_type _Par; }; -template -_NODISCARD bool operator==(const discrete_distribution<_Ty>& _Left, const discrete_distribution<_Ty>& _Right) { - return _Left.param() == _Right.param(); -} - -template -_NODISCARD bool operator!=(const discrete_distribution<_Ty>& _Left, const discrete_distribution<_Ty>& _Right) { - return !(_Left == _Right); -} - -template -basic_istream<_Elem, _Traits>& operator>>(basic_istream<_Elem, _Traits>& _Istr, - discrete_distribution<_Ty>& _Dist) { // read state from _Istr - return _Dist._Read(_Istr, _Dist._Par); -} - -template -basic_ostream<_Elem, _Traits>& operator<<(basic_ostream<_Elem, _Traits>& _Ostr, - const discrete_distribution<_Ty>& _Dist) { // write state to _Ostr - return _Dist._Write(_Ostr, _Dist._Par); -} - template class piecewise_constant_distribution : public discrete_distribution { // piecewise constant floating-point distribution + // TRANSITION: unused _Mypbase subobject from base class public: _RNG_REQUIRE_REALTYPE(piecewise_constant_distribution, _Ty); @@ -4700,13 +4511,16 @@ public: } } - _NODISCARD bool operator==(const param_type& _Right) const { - return static_cast(*this) == static_cast(_Right) && _Bvec == _Right._Bvec; + _NODISCARD_FRIEND bool operator==(const param_type& _Left, const param_type& _Right) { + return static_cast(_Left) == static_cast(_Right) + && _Left._Bvec == _Right._Bvec; } - _NODISCARD bool operator!=(const param_type& _Right) const { - return !(*this == _Right); +#if !_HAS_CXX20 + _NODISCARD_FRIEND bool operator!=(const param_type& _Left, const param_type& _Right) { + return !(_Left == _Right); } +#endif // !_HAS_CXX20 _NODISCARD vector<_Ty> intervals() const { return _Bvec; @@ -4778,25 +4592,39 @@ public: return _Eval(_Eng, _Par0); } + _NODISCARD_FRIEND bool operator==( + const piecewise_constant_distribution& _Left, const piecewise_constant_distribution& _Right) { + return _Left.param() == _Right.param(); + } + +#if !_HAS_CXX20 + _NODISCARD_FRIEND bool operator!=( + const piecewise_constant_distribution& _Left, const piecewise_constant_distribution& _Right) { + return !(_Left == _Right); + } +#endif // !_HAS_CXX20 + template - basic_istream<_Elem, _Traits>& _Read(basic_istream<_Elem, _Traits>& _Istr) { // read state from _Istr - _Mybase::_Read(_Istr, _Par); + friend basic_istream<_Elem, _Traits>& operator>>(basic_istream<_Elem, _Traits>& _Istr, + piecewise_constant_distribution& _Dist) { // read state from _Istr + static_cast(_Dist._Par)._Read(_Istr); - _Par._Bvec.clear(); - for (size_t _Idx = _Par._Pvec.size() + 1; 0 < _Idx; --_Idx) { // get a value and add to intervals vector + _Dist._Par._Bvec.clear(); + for (size_t _Idx = _Dist._Par._Pvec.size() + 1; 0 < _Idx; --_Idx) { // get a value and add to intervals vector double _Val; _In(_Istr, _Val); - _Par._Bvec.push_back(_Val); + _Dist._Par._Bvec.push_back(_Val); } return _Istr; } template - basic_ostream<_Elem, _Traits>& _Write(basic_ostream<_Elem, _Traits>& _Ostr) const { // write state to _Ostr - _Mybase::_Write(_Ostr, _Par); + friend basic_ostream<_Elem, _Traits>& operator<<(basic_ostream<_Elem, _Traits>& _Ostr, + const piecewise_constant_distribution& _Dist) { // write state to _Ostr + static_cast(_Dist._Par)._Write(_Ostr); - for (size_t _Idx = 0; _Idx < _Par._Bvec.size(); ++_Idx) { - _Out(_Ostr, _Par._Bvec[_Idx]); + for (size_t _Idx = 0; _Idx < _Dist._Par._Bvec.size(); ++_Idx) { + _Out(_Ostr, _Dist._Par._Bvec[_Idx]); } return _Ostr; @@ -4812,33 +4640,10 @@ public: param_type _Par; }; -template -_NODISCARD bool operator==( - const piecewise_constant_distribution<_Ty>& _Left, const piecewise_constant_distribution<_Ty>& _Right) { - return _Left.param() == _Right.param(); -} - -template -_NODISCARD bool operator!=( - const piecewise_constant_distribution<_Ty>& _Left, const piecewise_constant_distribution<_Ty>& _Right) { - return !(_Left == _Right); -} - -template -basic_istream<_Elem, _Traits>& operator>>(basic_istream<_Elem, _Traits>& _Istr, - piecewise_constant_distribution<_Ty>& _Dist) { // read state from _Istr - return _Dist._Read(_Istr); -} - -template -basic_ostream<_Elem, _Traits>& operator<<(basic_ostream<_Elem, _Traits>& _Ostr, - const piecewise_constant_distribution<_Ty>& _Dist) { // write state to _Ostr - return _Dist._Write(_Ostr); -} - template class piecewise_linear_distribution : public discrete_distribution { // piecewise linear floating-point distribution + // TRANSITION: unused _Mypbase subobject from base class public: _RNG_REQUIRE_REALTYPE(piecewise_linear_distribution, _Ty); @@ -4900,13 +4705,16 @@ public: _Init(); } - _NODISCARD bool operator==(const param_type& _Right) const { - return static_cast(*this) == static_cast(_Right) && _Bvec == _Right._Bvec; + _NODISCARD_FRIEND bool operator==(const param_type& _Left, const param_type& _Right) { + return static_cast(_Left) == static_cast(_Right) + && _Left._Bvec == _Right._Bvec; } - _NODISCARD bool operator!=(const param_type& _Right) const { - return !(*this == _Right); +#if !_HAS_CXX20 + _NODISCARD_FRIEND bool operator!=(const param_type& _Left, const param_type& _Right) { + return !(_Left == _Right); } +#endif // !_HAS_CXX20 _NODISCARD vector<_Ty> intervals() const { return _Bvec; @@ -5008,34 +4816,41 @@ public: return _Eval(_Eng, _Par0); } + _NODISCARD_FRIEND bool operator==( + const piecewise_linear_distribution& _Left, const piecewise_linear_distribution& _Right) { + return _Left.param() == _Right.param(); + } + +#if !_HAS_CXX20 + _NODISCARD_FRIEND bool operator!=( + const piecewise_linear_distribution& _Left, const piecewise_linear_distribution& _Right) { + return !(_Left == _Right); + } +#endif // !_HAS_CXX20 + template - basic_istream<_Elem, _Traits>& _Read(basic_istream<_Elem, _Traits>& _Istr, - param_type& _Par0) { // read state from _Istr - size_t _Nvals; - _Istr >> _Nvals; - _Par0._Pvec.clear(); - for (; 0 < _Nvals; --_Nvals) { // get a value and add to vector - double _Val; - _In(_Istr, _Val); - _Par0._Pvec.push_back(_Val); - } + friend basic_istream<_Elem, _Traits>& operator>>(basic_istream<_Elem, _Traits>& _Istr, + piecewise_linear_distribution& _Dist) { // read state from _Istr + static_cast(_Dist._Par)._Read(_Istr); + - _Par0._Bvec.clear(); - for (size_t _Idx = _Par0._Pvec.size(); 0 < _Idx; --_Idx) { // get a value and add to intervals vector + _Dist._Par._Bvec.clear(); + for (size_t _Idx = _Dist._Par._Pvec.size(); 0 < _Idx; --_Idx) { // get a value and add to intervals vector double _Val; _In(_Istr, _Val); - _Par0._Bvec.push_back(_Val); + _Dist._Par._Bvec.push_back(_Val); } - _Par0._Init(false); // don't renormalize, just compute CDF + _Dist._Par._Init(false); // don't renormalize, just compute CDF return _Istr; } template - basic_ostream<_Elem, _Traits>& _Write(basic_ostream<_Elem, _Traits>& _Ostr) const { // write state to _Ostr - _Mybase::_Write(_Ostr, _Par); + friend basic_ostream<_Elem, _Traits>& operator<<(basic_ostream<_Elem, _Traits>& _Ostr, + const piecewise_linear_distribution& _Dist) { // write state to _Ostr + static_cast(_Dist._Par)._Write(_Ostr); - for (size_t _Idx = 0; _Idx < _Par._Bvec.size(); ++_Idx) { - _Out(_Ostr, _Par._Bvec[_Idx]); + for (size_t _Idx = 0; _Idx < _Dist._Par._Bvec.size(); ++_Idx) { + _Out(_Ostr, _Dist._Par._Bvec[_Idx]); } return _Ostr; @@ -5060,30 +4875,6 @@ public: param_type _Par; }; -template -_NODISCARD bool operator==( - const piecewise_linear_distribution<_Ty>& _Left, const piecewise_linear_distribution<_Ty>& _Right) { - return _Left.param() == _Right.param(); -} - -template -_NODISCARD bool operator!=( - const piecewise_linear_distribution<_Ty>& _Left, const piecewise_linear_distribution<_Ty>& _Right) { - return !(_Left == _Right); -} - -template -basic_istream<_Elem, _Traits>& operator>>(basic_istream<_Elem, _Traits>& _Istr, - piecewise_linear_distribution<_Ty>& _Dist) { // read state from _Istr - return _Dist._Read(_Istr, _Dist._Par); -} - -template -basic_ostream<_Elem, _Traits>& operator<<(basic_ostream<_Elem, _Traits>& _Ostr, - const piecewise_linear_distribution<_Ty>& _Dist) { // write state to _Ostr - return _Dist._Write(_Ostr); -} - using minstd_rand0 = linear_congruential_engine; using minstd_rand = linear_congruential_engine; diff --git a/stl/inc/xhash b/stl/inc/xhash index 0298227a63c..dd0066b87e2 100644 --- a/stl/inc/xhash +++ b/stl/inc/xhash @@ -185,18 +185,12 @@ struct _Reinterpret_move_iter { // post ++ intentionally omitted -#ifndef __CUDACC__ // TRANSITION, VSO-568006 - _NODISCARD -#endif // TRANSITION, VSO-568006 - friend bool operator==(const _Reinterpret_move_iter& _Lhs, const _Reinterpret_move_iter& _Rhs) { + _NODISCARD_FRIEND bool operator==(const _Reinterpret_move_iter& _Lhs, const _Reinterpret_move_iter& _Rhs) { return _Lhs._Base == _Rhs._Base; } #if !_HAS_CXX20 -#ifndef __CUDACC__ // TRANSITION, VSO-568006 - _NODISCARD -#endif // TRANSITION, VSO-568006 - friend bool operator!=(const _Reinterpret_move_iter& _Lhs, const _Reinterpret_move_iter& _Rhs) { + _NODISCARD_FRIEND bool operator!=(const _Reinterpret_move_iter& _Lhs, const _Reinterpret_move_iter& _Rhs) { return _Lhs._Base != _Rhs._Base; } #endif // !_HAS_CXX20 diff --git a/stl/inc/yvals_core.h b/stl/inc/yvals_core.h index 037be9c5a92..bc98f550a62 100644 --- a/stl/inc/yvals_core.h +++ b/stl/inc/yvals_core.h @@ -421,6 +421,12 @@ #define _NODISCARD_CTOR #endif +#if defined(__CUDACC__) && !defined(__clang__) // TRANSITION, VSO-568006 +#define _NODISCARD_FRIEND friend +#else // ^^^ workaround ^^^ / vvv no workaround vvv +#define _NODISCARD_FRIEND _NODISCARD friend +#endif // TRANSITION, VSO-568006 + // Determine if we should use [[msvc::known_semantics]] to communicate to the compiler // that certain type trait specializations have the standard-mandated semantics #ifndef __has_cpp_attribute