[libc++] Reduce dependencies on <iostream> from <random>
We included <istream> and <ostream> from <random>, but really it is
sufficient to include <iosfwd> if we make sure we access ios_base
members through a dependent type. This allows us to break a hard
dependency of <random> on locales.
GitOrigin-RevId: 6abc15ae3c245b6043f15d3cdedfad187888dfd5
diff --git a/include/random b/include/random
index 4321195..9ba1693 100644
--- a/include/random
+++ b/include/random
@@ -1642,8 +1642,7 @@
#include <numeric>
#include <vector>
#include <string>
-#include <istream>
-#include <ostream>
+#include <iosfwd>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
@@ -1982,7 +1981,8 @@
const linear_congruential_engine<_UIntType, __a, __c, __m>& __x)
{
__save_flags<_CharT, _Traits> __lx(__os);
- __os.flags(ios_base::dec | ios_base::left);
+ typedef basic_ostream<_CharT, _Traits> _Ostream;
+ __os.flags(_Ostream::dec | _Ostream::left);
__os.fill(__os.widen(' '));
return __os << __x.__x_;
}
@@ -1994,7 +1994,8 @@
linear_congruential_engine<_UIntType, __a, __c, __m>& __x)
{
__save_flags<_CharT, _Traits> __lx(__is);
- __is.flags(ios_base::dec | ios_base::skipws);
+ typedef basic_istream<_CharT, _Traits> _Istream;
+ __is.flags(_Istream::dec | _Istream::skipws);
_UIntType __t;
__is >> __t;
if (!__is.fail())
@@ -2453,7 +2454,8 @@
_Bp, _Tp, _Cp, _Lp, _Fp>& __x)
{
__save_flags<_CharT, _Traits> __lx(__os);
- __os.flags(ios_base::dec | ios_base::left);
+ typedef basic_ostream<_CharT, _Traits> _Ostream;
+ __os.flags(_Ostream::dec | _Ostream::left);
_CharT __sp = __os.widen(' ');
__os.fill(__sp);
__os << __x.__x_[__x.__i_];
@@ -2474,7 +2476,8 @@
_Bp, _Tp, _Cp, _Lp, _Fp>& __x)
{
__save_flags<_CharT, _Traits> __lx(__is);
- __is.flags(ios_base::dec | ios_base::skipws);
+ typedef basic_istream<_CharT, _Traits> _Istream;
+ __is.flags(_Istream::dec | _Istream::skipws);
_UInt __t[_Np];
for (size_t __i = 0; __i < _Np; ++__i)
__is >> __t[__i];
@@ -2773,7 +2776,8 @@
const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x)
{
__save_flags<_CharT, _Traits> __lx(__os);
- __os.flags(ios_base::dec | ios_base::left);
+ typedef basic_ostream<_CharT, _Traits> _Ostream;
+ __os.flags(_Ostream::dec | _Ostream::left);
_CharT __sp = __os.widen(' ');
__os.fill(__sp);
__os << __x.__x_[__x.__i_];
@@ -2792,7 +2796,8 @@
subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x)
{
__save_flags<_CharT, _Traits> __lx(__is);
- __is.flags(ios_base::dec | ios_base::skipws);
+ typedef basic_istream<_CharT, _Traits> _Istream;
+ __is.flags(_Istream::dec | _Istream::skipws);
_UInt __t[_Rp+1];
for (size_t __i = 0; __i < _Rp+1; ++__i)
__is >> __t[__i];
@@ -2955,7 +2960,8 @@
const discard_block_engine<_Eng, _Pp, _Rp>& __x)
{
__save_flags<_CharT, _Traits> __lx(__os);
- __os.flags(ios_base::dec | ios_base::left);
+ typedef basic_ostream<_CharT, _Traits> _Ostream;
+ __os.flags(_Ostream::dec | _Ostream::left);
_CharT __sp = __os.widen(' ');
__os.fill(__sp);
return __os << __x.__e_ << __sp << __x.__n_;
@@ -2968,7 +2974,8 @@
discard_block_engine<_Eng, _Pp, _Rp>& __x)
{
__save_flags<_CharT, _Traits> __lx(__is);
- __is.flags(ios_base::dec | ios_base::skipws);
+ typedef basic_istream<_CharT, _Traits> _Istream;
+ __is.flags(_Istream::dec | _Istream::skipws);
_Eng __e;
int __n;
__is >> __e >> __n;
@@ -3440,7 +3447,8 @@
const shuffle_order_engine<_Eng, _Kp>& __x)
{
__save_flags<_CharT, _Traits> __lx(__os);
- __os.flags(ios_base::dec | ios_base::left);
+ typedef basic_ostream<_CharT, _Traits> _Ostream;
+ __os.flags(_Ostream::dec | _Ostream::left);
_CharT __sp = __os.widen(' ');
__os.fill(__sp);
__os << __x.__e_ << __sp << __x._V_[0];
@@ -3457,7 +3465,8 @@
{
typedef typename shuffle_order_engine<_Eng, _Kp>::result_type result_type;
__save_flags<_CharT, _Traits> __lx(__is);
- __is.flags(ios_base::dec | ios_base::skipws);
+ typedef basic_istream<_CharT, _Traits> _Istream;
+ __is.flags(_Istream::dec | _Istream::skipws);
_Eng __e;
result_type _Vp[_Kp+1];
__is >> __e;
@@ -3667,7 +3676,8 @@
const uniform_int_distribution<_IT>& __x)
{
__save_flags<_CharT, _Traits> __lx(__os);
- __os.flags(ios_base::dec | ios_base::left);
+ typedef basic_ostream<_CharT, _Traits> _Ostream;
+ __os.flags(_Ostream::dec | _Ostream::left);
_CharT __sp = __os.widen(' ');
__os.fill(__sp);
return __os << __x.a() << __sp << __x.b();
@@ -3682,7 +3692,8 @@
typedef typename _Eng::result_type result_type;
typedef typename _Eng::param_type param_type;
__save_flags<_CharT, _Traits> __lx(__is);
- __is.flags(ios_base::dec | ios_base::skipws);
+ typedef basic_istream<_CharT, _Traits> _Istream;
+ __is.flags(_Istream::dec | _Istream::skipws);
result_type __a;
result_type __b;
__is >> __a >> __b;
@@ -3788,8 +3799,9 @@
const uniform_real_distribution<_RT>& __x)
{
__save_flags<_CharT, _Traits> __lx(__os);
- __os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
- ios_base::scientific);
+ typedef basic_ostream<_CharT, _Traits> _OStream;
+ __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
+ _OStream::scientific);
_CharT __sp = __os.widen(' ');
__os.fill(__sp);
return __os << __x.a() << __sp << __x.b();
@@ -3804,7 +3816,8 @@
typedef typename _Eng::result_type result_type;
typedef typename _Eng::param_type param_type;
__save_flags<_CharT, _Traits> __lx(__is);
- __is.flags(ios_base::dec | ios_base::skipws);
+ typedef basic_istream<_CharT, _Traits> _Istream;
+ __is.flags(_Istream::dec | _Istream::skipws);
result_type __a;
result_type __b;
__is >> __a >> __b;
@@ -3899,8 +3912,9 @@
operator<<(basic_ostream<_CharT, _Traits>& __os, const bernoulli_distribution& __x)
{
__save_flags<_CharT, _Traits> __lx(__os);
- __os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
- ios_base::scientific);
+ typedef basic_ostream<_CharT, _Traits> _OStream;
+ __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
+ _OStream::scientific);
_CharT __sp = __os.widen(' ');
__os.fill(__sp);
return __os << __x.p();
@@ -3913,7 +3927,8 @@
typedef bernoulli_distribution _Eng;
typedef typename _Eng::param_type param_type;
__save_flags<_CharT, _Traits> __lx(__is);
- __is.flags(ios_base::dec | ios_base::skipws);
+ typedef basic_istream<_CharT, _Traits> _Istream;
+ __is.flags(_Istream::dec | _Istream::skipws);
double __p;
__is >> __p;
if (!__is.fail())
@@ -4083,8 +4098,9 @@
const binomial_distribution<_IntType>& __x)
{
__save_flags<_CharT, _Traits> __lx(__os);
- __os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
- ios_base::scientific);
+ typedef basic_ostream<_CharT, _Traits> _OStream;
+ __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
+ _OStream::scientific);
_CharT __sp = __os.widen(' ');
__os.fill(__sp);
return __os << __x.t() << __sp << __x.p();
@@ -4099,7 +4115,8 @@
typedef typename _Eng::result_type result_type;
typedef typename _Eng::param_type param_type;
__save_flags<_CharT, _Traits> __lx(__is);
- __is.flags(ios_base::dec | ios_base::skipws);
+ typedef basic_istream<_CharT, _Traits> _Istream;
+ __is.flags(_Istream::dec | _Istream::skipws);
result_type __t;
double __p;
__is >> __t >> __p;
@@ -4201,8 +4218,9 @@
const exponential_distribution<_RealType>& __x)
{
__save_flags<_CharT, _Traits> __lx(__os);
- __os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
- ios_base::scientific);
+ typedef basic_ostream<_CharT, _Traits> _OStream;
+ __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
+ _OStream::scientific);
return __os << __x.lambda();
}
@@ -4215,7 +4233,8 @@
typedef typename _Eng::result_type result_type;
typedef typename _Eng::param_type param_type;
__save_flags<_CharT, _Traits> __lx(__is);
- __is.flags(ios_base::dec | ios_base::skipws);
+ typedef basic_istream<_CharT, _Traits> _Istream;
+ __is.flags(_Istream::dec | _Istream::skipws);
result_type __lambda;
__is >> __lambda;
if (!__is.fail())
@@ -4355,8 +4374,9 @@
const normal_distribution<_RT>& __x)
{
__save_flags<_CharT, _Traits> __lx(__os);
- __os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
- ios_base::scientific);
+ typedef basic_ostream<_CharT, _Traits> _OStream;
+ __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
+ _OStream::scientific);
_CharT __sp = __os.widen(' ');
__os.fill(__sp);
__os << __x.mean() << __sp << __x.stddev() << __sp << __x._V_hot_;
@@ -4374,7 +4394,8 @@
typedef typename _Eng::result_type result_type;
typedef typename _Eng::param_type param_type;
__save_flags<_CharT, _Traits> __lx(__is);
- __is.flags(ios_base::dec | ios_base::skipws);
+ typedef basic_istream<_CharT, _Traits> _Istream;
+ __is.flags(_Istream::dec | _Istream::skipws);
result_type __mean;
result_type __stddev;
result_type _Vp = 0;
@@ -4729,8 +4750,9 @@
const poisson_distribution<_IntType>& __x)
{
__save_flags<_CharT, _Traits> __lx(__os);
- __os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
- ios_base::scientific);
+ typedef basic_ostream<_CharT, _Traits> _OStream;
+ __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
+ _OStream::scientific);
return __os << __x.mean();
}
@@ -4742,7 +4764,8 @@
typedef poisson_distribution<_IntType> _Eng;
typedef typename _Eng::param_type param_type;
__save_flags<_CharT, _Traits> __lx(__is);
- __is.flags(ios_base::dec | ios_base::skipws);
+ typedef basic_istream<_CharT, _Traits> _Istream;
+ __is.flags(_Istream::dec | _Istream::skipws);
double __mean;
__is >> __mean;
if (!__is.fail())
@@ -4840,8 +4863,9 @@
const weibull_distribution<_RT>& __x)
{
__save_flags<_CharT, _Traits> __lx(__os);
- __os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
- ios_base::scientific);
+ typedef basic_ostream<_CharT, _Traits> _OStream;
+ __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
+ _OStream::scientific);
_CharT __sp = __os.widen(' ');
__os.fill(__sp);
__os << __x.a() << __sp << __x.b();
@@ -4857,7 +4881,8 @@
typedef typename _Eng::result_type result_type;
typedef typename _Eng::param_type param_type;
__save_flags<_CharT, _Traits> __lx(__is);
- __is.flags(ios_base::dec | ios_base::skipws);
+ typedef basic_istream<_CharT, _Traits> _Istream;
+ __is.flags(_Istream::dec | _Istream::skipws);
result_type __a;
result_type __b;
__is >> __a >> __b;
@@ -4959,8 +4984,9 @@
const extreme_value_distribution<_RT>& __x)
{
__save_flags<_CharT, _Traits> __lx(__os);
- __os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
- ios_base::scientific);
+ typedef basic_ostream<_CharT, _Traits> _OStream;
+ __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
+ _OStream::scientific);
_CharT __sp = __os.widen(' ');
__os.fill(__sp);
__os << __x.a() << __sp << __x.b();
@@ -4976,7 +5002,8 @@
typedef typename _Eng::result_type result_type;
typedef typename _Eng::param_type param_type;
__save_flags<_CharT, _Traits> __lx(__is);
- __is.flags(ios_base::dec | ios_base::skipws);
+ typedef basic_istream<_CharT, _Traits> _Istream;
+ __is.flags(_Istream::dec | _Istream::skipws);
result_type __a;
result_type __b;
__is >> __a >> __b;
@@ -5131,8 +5158,9 @@
const gamma_distribution<_RT>& __x)
{
__save_flags<_CharT, _Traits> __lx(__os);
- __os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
- ios_base::scientific);
+ typedef basic_ostream<_CharT, _Traits> _OStream;
+ __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
+ _OStream::scientific);
_CharT __sp = __os.widen(' ');
__os.fill(__sp);
__os << __x.alpha() << __sp << __x.beta();
@@ -5148,7 +5176,8 @@
typedef typename _Eng::result_type result_type;
typedef typename _Eng::param_type param_type;
__save_flags<_CharT, _Traits> __lx(__is);
- __is.flags(ios_base::dec | ios_base::skipws);
+ typedef basic_istream<_CharT, _Traits> _Istream;
+ __is.flags(_Istream::dec | _Istream::skipws);
result_type __alpha;
result_type __beta;
__is >> __alpha >> __beta;
@@ -5267,8 +5296,9 @@
const negative_binomial_distribution<_IntType>& __x)
{
__save_flags<_CharT, _Traits> __lx(__os);
- __os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
- ios_base::scientific);
+ typedef basic_ostream<_CharT, _Traits> _OStream;
+ __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
+ _OStream::scientific);
_CharT __sp = __os.widen(' ');
__os.fill(__sp);
return __os << __x.k() << __sp << __x.p();
@@ -5283,7 +5313,8 @@
typedef typename _Eng::result_type result_type;
typedef typename _Eng::param_type param_type;
__save_flags<_CharT, _Traits> __lx(__is);
- __is.flags(ios_base::dec | ios_base::skipws);
+ typedef basic_istream<_CharT, _Traits> _Istream;
+ __is.flags(_Istream::dec | _Istream::skipws);
result_type __k;
double __p;
__is >> __k >> __p;
@@ -5373,8 +5404,9 @@
const geometric_distribution<_IntType>& __x)
{
__save_flags<_CharT, _Traits> __lx(__os);
- __os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
- ios_base::scientific);
+ typedef basic_ostream<_CharT, _Traits> _OStream;
+ __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
+ _OStream::scientific);
return __os << __x.p();
}
@@ -5386,7 +5418,8 @@
typedef geometric_distribution<_IntType> _Eng;
typedef typename _Eng::param_type param_type;
__save_flags<_CharT, _Traits> __lx(__is);
- __is.flags(ios_base::dec | ios_base::skipws);
+ typedef basic_istream<_CharT, _Traits> _Istream;
+ __is.flags(_Istream::dec | _Istream::skipws);
double __p;
__is >> __p;
if (!__is.fail())
@@ -5477,8 +5510,9 @@
const chi_squared_distribution<_RT>& __x)
{
__save_flags<_CharT, _Traits> __lx(__os);
- __os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
- ios_base::scientific);
+ typedef basic_ostream<_CharT, _Traits> _OStream;
+ __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
+ _OStream::scientific);
__os << __x.n();
return __os;
}
@@ -5492,7 +5526,8 @@
typedef typename _Eng::result_type result_type;
typedef typename _Eng::param_type param_type;
__save_flags<_CharT, _Traits> __lx(__is);
- __is.flags(ios_base::dec | ios_base::skipws);
+ typedef basic_istream<_CharT, _Traits> _Istream;
+ __is.flags(_Istream::dec | _Istream::skipws);
result_type __n;
__is >> __n;
if (!__is.fail())
@@ -5597,8 +5632,9 @@
const cauchy_distribution<_RT>& __x)
{
__save_flags<_CharT, _Traits> __lx(__os);
- __os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
- ios_base::scientific);
+ typedef basic_ostream<_CharT, _Traits> _OStream;
+ __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
+ _OStream::scientific);
_CharT __sp = __os.widen(' ');
__os.fill(__sp);
__os << __x.a() << __sp << __x.b();
@@ -5614,7 +5650,8 @@
typedef typename _Eng::result_type result_type;
typedef typename _Eng::param_type param_type;
__save_flags<_CharT, _Traits> __lx(__is);
- __is.flags(ios_base::dec | ios_base::skipws);
+ typedef basic_istream<_CharT, _Traits> _Istream;
+ __is.flags(_Istream::dec | _Istream::skipws);
result_type __a;
result_type __b;
__is >> __a >> __b;
@@ -5719,8 +5756,9 @@
const fisher_f_distribution<_RT>& __x)
{
__save_flags<_CharT, _Traits> __lx(__os);
- __os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
- ios_base::scientific);
+ typedef basic_ostream<_CharT, _Traits> _OStream;
+ __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
+ _OStream::scientific);
_CharT __sp = __os.widen(' ');
__os.fill(__sp);
__os << __x.m() << __sp << __x.n();
@@ -5736,7 +5774,8 @@
typedef typename _Eng::result_type result_type;
typedef typename _Eng::param_type param_type;
__save_flags<_CharT, _Traits> __lx(__is);
- __is.flags(ios_base::dec | ios_base::skipws);
+ typedef basic_istream<_CharT, _Traits> _Istream;
+ __is.flags(_Istream::dec | _Istream::skipws);
result_type __m;
result_type __n;
__is >> __m >> __n;
@@ -5835,8 +5874,9 @@
const student_t_distribution<_RT>& __x)
{
__save_flags<_CharT, _Traits> __lx(__os);
- __os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
- ios_base::scientific);
+ typedef basic_ostream<_CharT, _Traits> _OStream;
+ __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
+ _OStream::scientific);
__os << __x.n();
return __os;
}
@@ -5850,7 +5890,8 @@
typedef typename _Eng::result_type result_type;
typedef typename _Eng::param_type param_type;
__save_flags<_CharT, _Traits> __lx(__is);
- __is.flags(ios_base::dec | ios_base::skipws);
+ typedef basic_istream<_CharT, _Traits> _Istream;
+ __is.flags(_Istream::dec | _Istream::skipws);
result_type __n;
__is >> __n;
if (!__is.fail())
@@ -6058,8 +6099,9 @@
const discrete_distribution<_IT>& __x)
{
__save_flags<_CharT, _Traits> __lx(__os);
- __os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
- ios_base::scientific);
+ typedef basic_ostream<_CharT, _Traits> _OStream;
+ __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
+ _OStream::scientific);
_CharT __sp = __os.widen(' ');
__os.fill(__sp);
size_t __n = __x.__p_.__p_.size();
@@ -6075,7 +6117,8 @@
discrete_distribution<_IT>& __x)
{
__save_flags<_CharT, _Traits> __lx(__is);
- __is.flags(ios_base::dec | ios_base::skipws);
+ typedef basic_istream<_CharT, _Traits> _Istream;
+ __is.flags(_Istream::dec | _Istream::skipws);
size_t __n;
__is >> __n;
vector<double> __p(__n);
@@ -6360,8 +6403,9 @@
const piecewise_constant_distribution<_RT>& __x)
{
__save_flags<_CharT, _Traits> __lx(__os);
- __os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
- ios_base::scientific);
+ typedef basic_ostream<_CharT, _Traits> _OStream;
+ __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
+ _OStream::scientific);
_CharT __sp = __os.widen(' ');
__os.fill(__sp);
size_t __n = __x.__p_.__b_.size();
@@ -6387,7 +6431,8 @@
typedef piecewise_constant_distribution<_RT> _Eng;
typedef typename _Eng::result_type result_type;
__save_flags<_CharT, _Traits> __lx(__is);
- __is.flags(ios_base::dec | ios_base::skipws);
+ typedef basic_istream<_CharT, _Traits> _Istream;
+ __is.flags(_Istream::dec | _Istream::skipws);
size_t __n;
__is >> __n;
vector<result_type> __b(__n);
@@ -6700,8 +6745,9 @@
const piecewise_linear_distribution<_RT>& __x)
{
__save_flags<_CharT, _Traits> __lx(__os);
- __os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
- ios_base::scientific);
+ typedef basic_ostream<_CharT, _Traits> _OStream;
+ __os.flags(_OStream::dec | _OStream::left | _OStream::fixed |
+ _OStream::scientific);
_CharT __sp = __os.widen(' ');
__os.fill(__sp);
size_t __n = __x.__p_.__b_.size();
@@ -6727,7 +6773,8 @@
typedef piecewise_linear_distribution<_RT> _Eng;
typedef typename _Eng::result_type result_type;
__save_flags<_CharT, _Traits> __lx(__is);
- __is.flags(ios_base::dec | ios_base::skipws);
+ typedef basic_istream<_CharT, _Traits> _Istream;
+ __is.flags(_Istream::dec | _Istream::skipws);
size_t __n;
__is >> __n;
vector<result_type> __b(__n);