Skip to content

Commit c1e42b9

Browse files
<random>: Deprecate TR1 components in the std namespace (#4284)
Co-authored-by: Stephan T. Lavavej <stl@nuwen.net>
1 parent 065e5ff commit c1e42b9

File tree

5 files changed

+240
-24
lines changed

5 files changed

+240
-24
lines changed

stl/inc/random

+218-14
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ private:
534534
};
535535

536536
template <class _Uint, _Uint _Ax, _Uint _Cx, _Uint _Mx>
537-
class linear_congruential { // linear congruential random engine
537+
class _DEPRECATE_TR1_RANDOM linear_congruential { // linear congruential random engine
538538
public:
539539
_RNG_REQUIRE_UINTTYPE(linear_congruential, _Uint);
540540

@@ -898,7 +898,7 @@ struct _Swc_traits { // traits for subtract_with_carry generator
898898
};
899899

900900
template <class _Ty, _Ty _Mx, size_t _Sx, size_t _Rx>
901-
class subtract_with_carry
901+
class _DEPRECATE_TR1_RANDOM subtract_with_carry
902902
: public _Swc_base<_Ty, _Sx, _Rx, _Swc_traits<_Ty, _Mx, _Rx>> { // subtract_with_carry generator
903903
public:
904904
using _Mybase = _Swc_base<_Ty, _Sx, _Rx, _Swc_traits<_Ty, _Mx, _Rx>>;
@@ -915,9 +915,10 @@ public:
915915
subtract_with_carry(_Gen& _Gx) : _Mybase(_Gx) {}
916916
};
917917

918+
_STL_DISABLE_DEPRECATED_WARNING
918919
_EXPORT_STD template <class _Ty, size_t _Wx, size_t _Sx, size_t _Rx>
919920
class subtract_with_carry_engine
920-
: public subtract_with_carry<_Ty, static_cast<_Ty>((_Ty{1} << (_Wx - 1)) << 1), _Sx, _Rx> {
921+
: private subtract_with_carry<_Ty, static_cast<_Ty>((_Ty{1} << (_Wx - 1)) << 1), _Sx, _Rx> {
921922
// subtract_with_carry generator
922923
public:
923924
_RNG_REQUIRE_UINTTYPE(subtract_with_carry_engine, _Ty);
@@ -981,6 +982,26 @@ public:
981982
return _Mx - 1;
982983
}
983984

985+
_NODISCARD_FRIEND bool operator==(
986+
const subtract_with_carry_engine& _Left, const subtract_with_carry_engine& _Right) noexcept /* strengthened */ {
987+
return static_cast<const _Mybase&>(_Left) == static_cast<const _Mybase&>(_Right);
988+
}
989+
990+
#if !_HAS_CXX20
991+
_NODISCARD_FRIEND bool operator!=(
992+
const subtract_with_carry_engine& _Left, const subtract_with_carry_engine& _Right) noexcept /* strengthened */ {
993+
return static_cast<const _Mybase&>(_Left) != static_cast<const _Mybase&>(_Right);
994+
}
995+
#endif // !_HAS_CXX20
996+
997+
_NODISCARD result_type operator()() {
998+
return _Mybase::operator()();
999+
}
1000+
1001+
void discard(unsigned long long _Nskip) {
1002+
_Mybase::discard(_Nskip);
1003+
}
1004+
9841005
template <class _Elem, class _Traits>
9851006
friend basic_ostream<_Elem, _Traits>& operator<<(
9861007
basic_ostream<_Elem, _Traits>& _Ostr, const subtract_with_carry_engine& _Eng) {
@@ -1019,6 +1040,7 @@ public:
10191040
return _Istr;
10201041
}
10211042
};
1043+
_STL_RESTORE_DEPRECATED_WARNING
10221044

10231045
#if _HAS_TR1_NAMESPACE
10241046
constexpr double _Cx_exp2(const int _Exp) noexcept {
@@ -1108,7 +1130,7 @@ public:
11081130
#endif // _HAS_TR1_NAMESPACE
11091131

11101132
template <class _Ty, int _Wx, int _Nx, int _Mx, int _Rx, _Ty _Px, int _Ux, int _Sx, _Ty _Bx, int _Tx, _Ty _Cx, int _Lx>
1111-
class mersenne_twister : public _Circ_buf<_Ty, _Nx> { // mersenne twister generator
1133+
class _DEPRECATE_TR1_RANDOM mersenne_twister : public _Circ_buf<_Ty, _Nx> { // mersenne twister generator
11121134
public:
11131135
using result_type = _Ty;
11141136

@@ -1278,9 +1300,10 @@ protected:
12781300
static constexpr int _M_mod_n = _Mx % _Nx;
12791301
};
12801302

1303+
_STL_DISABLE_DEPRECATED_WARNING
12811304
_EXPORT_STD template <class _Ty, size_t _Wx, size_t _Nx, size_t _Mx, size_t _Rx, _Ty _Px, size_t _Ux, _Ty _Dx,
12821305
size_t _Sx, _Ty _Bx, size_t _Tx, _Ty _Cx, size_t _Lx, _Ty _Fx>
1283-
class mersenne_twister_engine : public mersenne_twister<_Ty, _Wx, _Nx, _Mx, _Rx, _Px, _Ux, _Sx, _Bx, _Tx, _Cx, _Lx> {
1306+
class mersenne_twister_engine : private mersenne_twister<_Ty, _Wx, _Nx, _Mx, _Rx, _Px, _Ux, _Sx, _Bx, _Tx, _Cx, _Lx> {
12841307
public:
12851308
static constexpr unsigned long long _Max = (((1ULL << (_Wx - 1)) - 1) << 1) + 1;
12861309

@@ -1360,10 +1383,43 @@ public:
13601383
_NODISCARD static constexpr result_type(max)() noexcept /* strengthened */ {
13611384
return _Mybase::_WMSK;
13621385
}
1386+
1387+
_NODISCARD_FRIEND bool operator==(
1388+
const mersenne_twister_engine& _Left, const mersenne_twister_engine& _Right) noexcept /* strengthened */ {
1389+
return static_cast<const _Mybase&>(_Left) == static_cast<const _Mybase&>(_Right);
1390+
}
1391+
1392+
#if !_HAS_CXX20
1393+
_NODISCARD_FRIEND bool operator!=(
1394+
const mersenne_twister_engine& _Left, const mersenne_twister_engine& _Right) noexcept /* strengthened */ {
1395+
return static_cast<const _Mybase&>(_Left) != static_cast<const _Mybase&>(_Right);
1396+
}
1397+
#endif // !_HAS_CXX20
1398+
1399+
template <class _Elem, class _S_Traits>
1400+
friend basic_istream<_Elem, _S_Traits>& operator>>(
1401+
basic_istream<_Elem, _S_Traits>& _Istr, mersenne_twister_engine& _Eng) {
1402+
return _Istr >> static_cast<_Mybase&>(_Eng);
1403+
}
1404+
1405+
template <class _Elem, class _S_Traits>
1406+
friend basic_ostream<_Elem, _S_Traits>& operator<<(
1407+
basic_ostream<_Elem, _S_Traits>& _Ostr, const mersenne_twister_engine& _Eng) {
1408+
return _Ostr << static_cast<const _Mybase&>(_Eng);
1409+
}
1410+
1411+
_NODISCARD result_type operator()() {
1412+
return _Mybase::operator()();
1413+
}
1414+
1415+
void discard(unsigned long long _Nskip) {
1416+
_Mybase::discard(_Nskip);
1417+
}
13631418
};
1419+
_STL_RESTORE_DEPRECATED_WARNING
13641420

13651421
template <class _Engine, int _Px, int _Rx>
1366-
class discard_block { // discard_block compound engine
1422+
class _DEPRECATE_TR1_RANDOM discard_block { // discard_block compound engine
13671423
public:
13681424
#if _HAS_TR1_NAMESPACE
13691425
using base_type _DEPRECATE_TR1_NAMESPACE = _Engine; // TR1-only typedef
@@ -1539,9 +1595,10 @@ private:
15391595
size_t _Nx;
15401596
};
15411597

1598+
_STL_DISABLE_DEPRECATED_WARNING
15421599
_EXPORT_STD template <class _Engine, size_t _Px, size_t _Rx>
15431600
class discard_block_engine // discard_block_engine compound engine
1544-
: public conditional_t<_Px <= INT_MAX, discard_block<_Engine, static_cast<int>(_Px), static_cast<int>(_Rx)>,
1601+
: private conditional_t<_Px <= INT_MAX, discard_block<_Engine, static_cast<int>(_Px), static_cast<int>(_Rx)>,
15451602
_Discard_block_base<_Engine, _Px, _Rx>> {
15461603
public:
15471604
static_assert(0 < _Rx && _Rx <= _Px, "invalid template argument for discard_block_engine");
@@ -1564,14 +1621,61 @@ public:
15641621
template <class _Seed_seq, _Enable_if_seed_seq_t<_Seed_seq, discard_block_engine, _Engine> = 0>
15651622
explicit discard_block_engine(_Seed_seq& _Seq) : _Mybase(_Seq) {}
15661623

1624+
void seed() {
1625+
_Mybase::seed();
1626+
}
1627+
1628+
void seed(result_type _Xx0) {
1629+
_Mybase::seed(_Xx0);
1630+
}
1631+
1632+
template <class _Seed_seq, _Enable_if_seed_seq_t<_Seed_seq, discard_block_engine> = 0>
1633+
void seed(_Seed_seq& _Seq) {
1634+
_Mybase::seed(_Seq);
1635+
}
1636+
1637+
_NODISCARD const _Engine& base() const noexcept {
1638+
return _Mybase::base();
1639+
}
1640+
1641+
_NODISCARD result_type operator()() {
1642+
return _Mybase::operator()();
1643+
}
1644+
1645+
void discard(unsigned long long _Nskip) {
1646+
_Mybase::discard(_Nskip);
1647+
}
1648+
15671649
_NODISCARD static constexpr result_type(min)() noexcept /* strengthened */ {
15681650
return (_Engine::min)();
15691651
}
15701652

15711653
_NODISCARD static constexpr result_type(max)() noexcept /* strengthened */ {
15721654
return (_Engine::max)();
15731655
}
1656+
1657+
_NODISCARD_FRIEND bool operator==(const discard_block_engine& _Left, const discard_block_engine& _Right) {
1658+
return static_cast<const _Mybase&>(_Left) == static_cast<const _Mybase&>(_Right);
1659+
}
1660+
1661+
#if !_HAS_CXX20
1662+
_NODISCARD_FRIEND bool operator!=(const discard_block_engine& _Left, const discard_block_engine& _Right) {
1663+
return static_cast<const _Mybase&>(_Left) != static_cast<const _Mybase&>(_Right);
1664+
}
1665+
#endif // !_HAS_CXX20
1666+
1667+
template <class _Elem, class _Traits>
1668+
friend basic_istream<_Elem, _Traits>& operator>>(basic_istream<_Elem, _Traits>& _Istr, discard_block_engine& _Eng) {
1669+
return _Istr >> static_cast<_Mybase&>(_Eng);
1670+
}
1671+
1672+
template <class _Elem, class _Traits>
1673+
friend basic_ostream<_Elem, _Traits>& operator<<(
1674+
basic_ostream<_Elem, _Traits>& _Ostr, const discard_block_engine& _Eng) {
1675+
return _Ostr << static_cast<const _Mybase&>(_Eng);
1676+
}
15741677
};
1678+
_STL_RESTORE_DEPRECATED_WARNING
15751679

15761680
_EXPORT_STD template <class _Engine, size_t _Wx, class _UIntType>
15771681
class independent_bits_engine { // independent_bits_engine compound engine
@@ -1969,7 +2073,7 @@ private:
19692073
};
19702074

19712075
template <class _Ty = int>
1972-
class uniform_int { // uniform integer distribution
2076+
class _DEPRECATE_TR1_RANDOM uniform_int { // uniform integer distribution
19732077
public:
19742078
using result_type = _Ty;
19752079

@@ -2112,8 +2216,9 @@ private:
21122216
param_type _Par;
21132217
};
21142218

2219+
_STL_DISABLE_DEPRECATED_WARNING
21152220
_EXPORT_STD template <class _Ty = int>
2116-
class uniform_int_distribution : public uniform_int<_Ty> { // uniform integer distribution
2221+
class uniform_int_distribution : private uniform_int<_Ty> { // uniform integer distribution
21172222
public:
21182223
_RNG_REQUIRE_INTTYPE(uniform_int_distribution, _Ty);
21192224

@@ -2143,6 +2248,54 @@ public:
21432248
explicit uniform_int_distribution(const param_type& _Par0) noexcept // strengthened
21442249
: _Mybase(_Par0) {}
21452250

2251+
_NODISCARD result_type a() const noexcept /* strengthened */ {
2252+
return _Mybase::a();
2253+
}
2254+
2255+
_NODISCARD result_type b() const noexcept /* strengthened */ {
2256+
return _Mybase::b();
2257+
}
2258+
2259+
_NODISCARD param_type param() const noexcept /* strengthened */ {
2260+
return _Mybase::param();
2261+
}
2262+
2263+
void param(const param_type& _Par0) noexcept /* strengthened */ {
2264+
_Mybase::param(_Par0);
2265+
}
2266+
2267+
_NODISCARD result_type(min)() const noexcept /* strengthened */ {
2268+
return (_Mybase::min)();
2269+
}
2270+
2271+
_NODISCARD result_type(max)() const noexcept /* strengthened */ {
2272+
return (_Mybase::max)();
2273+
}
2274+
2275+
void reset() noexcept /* strengthened */ {}
2276+
2277+
template <class _Engine>
2278+
_NODISCARD result_type operator()(_Engine& _Eng) _DISTRIBUTION_CONST {
2279+
return _Mybase::operator()(_Eng);
2280+
}
2281+
2282+
template <class _Engine>
2283+
_NODISCARD result_type operator()(_Engine& _Eng, const param_type& _Par0) _DISTRIBUTION_CONST {
2284+
return _Mybase::operator()(_Eng, _Par0);
2285+
}
2286+
2287+
template <class _Elem, class _Traits>
2288+
friend basic_istream<_Elem, _Traits>& operator>>(
2289+
basic_istream<_Elem, _Traits>& _Istr, uniform_int_distribution& _Dist) {
2290+
return _Istr >> static_cast<_Mybase&>(_Dist);
2291+
}
2292+
2293+
template <class _Elem, class _Traits>
2294+
friend basic_ostream<_Elem, _Traits>& operator<<(
2295+
basic_ostream<_Elem, _Traits>& _Ostr, const uniform_int_distribution& _Dist) {
2296+
return _Ostr << static_cast<const _Mybase&>(_Dist);
2297+
}
2298+
21462299
_NODISCARD_FRIEND bool operator==(
21472300
const uniform_int_distribution& _Left, const uniform_int_distribution& _Right) noexcept /* strengthened */ {
21482301
return _Left.param() == _Right.param();
@@ -2155,6 +2308,7 @@ public:
21552308
}
21562309
#endif // !_HAS_CXX20
21572310
};
2311+
_STL_RESTORE_DEPRECATED_WARNING
21582312

21592313
_EXPORT_STD class bernoulli_distribution { // class for bernoulli distribution
21602314
public:
@@ -2828,7 +2982,7 @@ private:
28282982
};
28292983

28302984
template <class _Ty = double>
2831-
class uniform_real { // uniform real distribution
2985+
class _DEPRECATE_TR1_RANDOM uniform_real { // uniform real distribution
28322986
public:
28332987
using result_type = _Ty;
28342988

@@ -2954,8 +3108,9 @@ private:
29543108
param_type _Par;
29553109
};
29563110

3111+
_STL_DISABLE_DEPRECATED_WARNING
29573112
_EXPORT_STD template <class _Ty = double>
2958-
class uniform_real_distribution : public uniform_real<_Ty> { // uniform real distribution
3113+
class uniform_real_distribution : private uniform_real<_Ty> { // uniform real distribution
29593114
public:
29603115
_RNG_REQUIRE_REALTYPE(uniform_real_distribution, _Ty);
29613116

@@ -2984,6 +3139,54 @@ public:
29843139
explicit uniform_real_distribution(const param_type& _Par0) noexcept // strengthened
29853140
: _Mybase(_Par0) {}
29863141

3142+
_NODISCARD result_type a() const noexcept /* strengthened */ {
3143+
return _Mybase::a();
3144+
}
3145+
3146+
_NODISCARD result_type b() const noexcept /* strengthened */ {
3147+
return _Mybase::b();
3148+
}
3149+
3150+
_NODISCARD param_type param() const noexcept /* strengthened */ {
3151+
return _Mybase::param();
3152+
}
3153+
3154+
void param(const param_type& _Par0) noexcept /* strengthened */ {
3155+
_Mybase::param(_Par0);
3156+
}
3157+
3158+
_NODISCARD result_type(min)() const noexcept /* strengthened */ {
3159+
return (_Mybase::min)();
3160+
}
3161+
3162+
_NODISCARD result_type(max)() const noexcept /* strengthened */ {
3163+
return (_Mybase::max)();
3164+
}
3165+
3166+
void reset() noexcept /* strengthened */ {}
3167+
3168+
template <class _Engine>
3169+
_NODISCARD result_type operator()(_Engine& _Eng) _DISTRIBUTION_CONST {
3170+
return _Mybase::operator()(_Eng);
3171+
}
3172+
3173+
template <class _Engine>
3174+
_NODISCARD result_type operator()(_Engine& _Eng, const param_type& _Par0) _DISTRIBUTION_CONST {
3175+
return _Mybase::operator()(_Eng, _Par0);
3176+
}
3177+
3178+
template <class _Elem, class _Traits>
3179+
friend basic_istream<_Elem, _Traits>& operator>>(
3180+
basic_istream<_Elem, _Traits>& _Istr, uniform_real_distribution& _Dist) {
3181+
return _Istr >> static_cast<_Mybase&>(_Dist);
3182+
}
3183+
3184+
template <class _Elem, class _Traits>
3185+
friend basic_ostream<_Elem, _Traits>& operator<<(
3186+
basic_ostream<_Elem, _Traits>& _Ostr, const uniform_real_distribution& _Dist) {
3187+
return _Ostr << static_cast<const _Mybase&>(_Dist);
3188+
}
3189+
29873190
_NODISCARD_FRIEND bool operator==(
29883191
const uniform_real_distribution& _Left, const uniform_real_distribution& _Right) noexcept /* strengthened */ {
29893192
return _Left.param() == _Right.param();
@@ -2996,6 +3199,7 @@ public:
29963199
}
29973200
#endif // !_HAS_CXX20
29983201
};
3202+
_STL_RESTORE_DEPRECATED_WARNING
29993203

30003204
_EXPORT_STD template <class _Ty = double>
30013205
class exponential_distribution { // exponential distribution
@@ -4485,7 +4689,7 @@ private:
44854689
_Ty _Vx2;
44864690
_Ty _Rx0;
44874691
_Ty _Rs;
4488-
uniform_real<_Ty> _Dist(-1, 1);
4692+
uniform_real_distribution<_Ty> _Dist(-1, 1);
44894693
for (;;) { // get a point inside unit circle
44904694
_Vx1 = _Dist(_Eng);
44914695
_Vx2 = _Dist(_Eng);
@@ -5020,7 +5224,7 @@ public:
50205224
template <class _Engine>
50215225
result_type _Eval(_Engine& _Eng, const param_type& _Par0) _DISTRIBUTION_CONST {
50225226
size_t _Px = _Mybase::operator()(_Eng, _Par0);
5023-
uniform_real<_Ty> _Dist(_Par0._Bvec[_Px], _Par0._Bvec[_Px + 1]);
5227+
uniform_real_distribution<_Ty> _Dist(_Par0._Bvec[_Px], _Par0._Bvec[_Px + 1]);
50245228
return _Dist(_Eng);
50255229
}
50265230

@@ -5247,7 +5451,7 @@ public:
52475451
size_t _Px = _Mybase::operator()(_Eng, _Par0);
52485452
double _Px0 = _Par0._Pvec[_Px];
52495453
double _Px1 = _Par0._Pvec[_Px + 1];
5250-
uniform_real<_Ty> _Dist;
5454+
uniform_real_distribution<_Ty> _Dist;
52515455
result_type _Xx0 = _Dist(_Eng);
52525456

52535457
if (_Px0 != _Px1) {

0 commit comments

Comments
 (0)