summaryrefslogtreecommitdiffstats
path: root/libstdc++-v3/include/tr1/random
diff options
context:
space:
mode:
authorpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>2006-06-07 01:50:09 +0000
committerpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>2006-06-07 01:50:09 +0000
commit209fd0a02ebea7a7a0f553e5a86153a571900ef2 (patch)
tree511bd30e94a3058c98d5449b7fa65b91011948a3 /libstdc++-v3/include/tr1/random
parent5fa4fc3d3a90e7b7e39774c0804b657cab733263 (diff)
downloadppe42-gcc-209fd0a02ebea7a7a0f553e5a86153a571900ef2.tar.gz
ppe42-gcc-209fd0a02ebea7a7a0f553e5a86153a571900ef2.zip
2006-06-06 Paolo Carlini <pcarlini@suse.de>
* include/tr1/random (mersenne_twister<>::operator==, operator!=, operator<<, operator>>): Implement. * testsuite/tr1/5_numerical_facilities/random/mersenne_twister/ operators/equal.cc: New. * testsuite/tr1/5_numerical_facilities/random/mersenne_twister/ operators/not_equal.cc: Likewise. * testsuite/tr1/5_numerical_facilities/random/mersenne_twister/ operators/serialize.cc: Likewise. * include/tr1/random (subtract_with_carry<>::operator==): Fix, compare the whole state; use std::equal. * include/tr1/random: Minor formatting and style changes. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@114459 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3/include/tr1/random')
-rw-r--r--libstdc++-v3/include/tr1/random172
1 files changed, 118 insertions, 54 deletions
diff --git a/libstdc++-v3/include/tr1/random b/libstdc++-v3/include/tr1/random
index a018a837064..7bdf8e6be07 100644
--- a/libstdc++-v3/include/tr1/random
+++ b/libstdc++-v3/include/tr1/random
@@ -517,6 +517,76 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
result_type
operator()();
+ /**
+ * Compares two % mersenne_twister random number generator objects of
+ * the same type for equality.
+ *
+ * @param __lhs A % mersenne_twister random number generator object.
+ * @param __rhs Another % mersenne_twister random number generator
+ * object.
+ *
+ * @returns true if the two objects are equal, false otherwise.
+ */
+ friend bool
+ operator==(const mersenne_twister& __lhs,
+ const mersenne_twister& __rhs)
+ { return std::equal(__lhs._M_x, __lhs._M_x + state_size, __rhs._M_x); }
+
+ /**
+ * Compares two % mersenne_twister random number generator objects of
+ * the same type for inequality.
+ *
+ * @param __lhs A % mersenne_twister random number generator object.
+ * @param __rhs Another % mersenne_twister random number generator
+ * object.
+ *
+ * @returns true if the two objects are not equal, false otherwise.
+ */
+ friend bool
+ operator!=(const mersenne_twister& __lhs,
+ const mersenne_twister& __rhs)
+ { return !(__lhs == __rhs); }
+
+ /**
+ * Inserts the current state of a % mersenne_twister random number
+ * generator engine @p __x into the output stream @p __os.
+ *
+ * @param __os An output stream.
+ * @param __x A % mersenne_twister random number generator engine.
+ *
+ * @returns The output stream with the state of @p __x inserted or in
+ * an error state.
+ */
+ template<typename _CharT, typename _Traits>
+ friend basic_ostream<_CharT, _Traits>&
+ operator<<(basic_ostream<_CharT, _Traits>& __os,
+ const mersenne_twister& __x)
+ {
+ std::copy(__x._M_x, __x._M_x + state_size,
+ std::ostream_iterator<_UIntType>(__os, " "));
+ return __os;
+ }
+
+ /**
+ * Extracts the current state of a % mersenne_twister random number
+ * generator engine @p __x from the input stream @p __is.
+ *
+ * @param __is An input stream.
+ * @param __x A % mersenne_twister random number generator engine.
+ *
+ * @returns The input stream with the state of @p __x extracted or in
+ * an error state.
+ */
+ template<typename _CharT, typename _Traits>
+ friend basic_istream<_CharT, _Traits>&
+ operator>>(basic_istream<_CharT, _Traits>& __is,
+ mersenne_twister& __x)
+ {
+ for (int __i = 0; __i < state_size; ++__i)
+ __is >> __x._M_x[__i];
+ return __is;
+ }
+
private:
template<class _Gen>
void
@@ -669,10 +739,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
friend bool
operator==(const subtract_with_carry& __lhs,
const subtract_with_carry& __rhs)
- {
- return ((__lhs._M_x[0] == __rhs._M_x[0])
- && (__lhs._M_x[__r - 1] == __rhs._M_x[__r - 1]));
- }
+ { return std::equal(__lhs._M_x, __lhs._M_x + long_lag, __rhs._M_x); }
/**
* Compares two % subtract_with_carry random number generator objects of
@@ -691,40 +758,40 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
/**
* Inserts the current state of a % subtract_with_carry random number
- * genator engine @p x into the output stream @p __os.
+ * generator engine @p __x into the output stream @p __os.
*
* @param __os An output stream.
* @param __x A % subtract_with_carry random number generator engine.
*
- * @returns The output stream with the state of @p x inserted or in an
- * error state.
+ * @returns The output stream with the state of @p __x inserted or in
+ * an error state.
*/
template<typename _CharT, typename _Traits>
friend basic_ostream<_CharT, _Traits>&
operator<<(basic_ostream<_CharT, _Traits>& __os,
const subtract_with_carry& __x)
{
- std::copy(__x._M_x, __x._M_x + __r,
+ std::copy(__x._M_x, __x._M_x + long_lag,
std::ostream_iterator<_IntType>(__os, " "));
return __os << __x._M_carry;
}
/**
* Extracts the current state of a % subtract_with_carry random number
- * gerator engine @p x from the input stream @p __is.
+ * generator engine @p __x from the input stream @p __is.
*
* @param __is An input stream.
* @param __x A % subtract_with_carry random number generator engine.
*
- * @returns The input stream with the state of @p x extracted or in an
- * error state.
+ * @returns The input stream with the state of @p __x extracted or in
+ * an error state.
*/
template<typename _CharT, typename _Traits>
friend basic_istream<_CharT, _Traits>&
operator>>(basic_istream<_CharT, _Traits>& __is,
subtract_with_carry& __x)
{
- for (int __i = 0; __i < __r; ++__i)
+ for (int __i = 0; __i < long_lag; ++__i)
__is >> __x._M_x[__i];
__is >> __x._M_carry;
return __is;
@@ -865,10 +932,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
*/
friend bool
operator==(const discard_block& __lhs, const discard_block& __rhs)
- {
- return ((__lhs._M_b == __rhs._M_b)
- && (__lhs._M_n == __rhs._M_n));
- }
+ { return (__lhs._M_b == __rhs._M_b) && (__lhs._M_n == __rhs._M_n); }
/**
* Compares two %discard_block random number generator objects of
@@ -886,13 +950,13 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
/**
* Inserts the current state of a %discard_block random number
- * genator engine @p x into the output stream @p __os.
+ * generator engine @p __x into the output stream @p __os.
*
* @param __os An output stream.
* @param __x A %discard_block random number generator engine.
*
- * @returns The output stream with the state of @p x inserted or in an
- * error state.
+ * @returns The output stream with the state of @p __x inserted or in
+ * an error state.
*/
template<typename _CharT, typename _Traits>
friend basic_ostream<_CharT, _Traits>&
@@ -902,13 +966,13 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
/**
* Extracts the current state of a % subtract_with_carry random number
- * gerator engine @p x from the input stream @p __is.
+ * generator engine @p __x from the input stream @p __is.
*
* @param __is An input stream.
* @param __x A %discard_block random number generator engine.
*
- * @returns The input stream with the state of @p x extracted or in an
- * error state.
+ * @returns The input stream with the state of @p __x extracted or in
+ * an error state.
*/
template<typename _CharT, typename _Traits>
friend basic_istream<_CharT, _Traits>&
@@ -1035,7 +1099,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
operator==(const xor_combine& __lhs, const xor_combine& __rhs)
{
return (__lhs.base1() == __rhs.base1())
- && (__lhs.base2() == __rhs.base2());
+ && (__lhs.base2() == __rhs.base2());
}
/**
@@ -1054,13 +1118,13 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
/**
* Inserts the current state of a %xor_combine random number
- * genator engine @p x into the output stream @p __os.
+ * generator engine @p __x into the output stream @p __os.
*
* @param __os An output stream.
* @param __x A %xor_combine random number generator engine.
*
- * @returns The output stream with the state of @p x inserted or in an
- * error state.
+ * @returns The output stream with the state of @p __x inserted or in
+ * an error state.
*/
template<typename _CharT, typename _Traits>
friend basic_ostream<_CharT, _Traits>&
@@ -1070,13 +1134,13 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
/**
* Extracts the current state of a %xor_combine random number
- * gerator engine @p x from the input stream @p __is.
+ * generator engine @p __x from the input stream @p __is.
*
* @param __is An input stream.
* @param __x A %xor_combine random number generator engine.
*
- * @returns The input stream with the state of @p x extracted or in an
- * error state.
+ * @returns The input stream with the state of @p __x extracted or in
+ * an error state.
*/
template<typename _CharT, typename _Traits>
friend basic_istream<_CharT, _Traits>&
@@ -1199,14 +1263,14 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
{ return __urng() % __n; }
/**
- * Inserts a %uniform_int random number distribution @p x into the
+ * Inserts a %uniform_int random number distribution @p __x into the
* output stream @p os.
*
* @param __os An output stream.
* @param __x A %uniform_int random number distribution.
*
- * @returns The output stream with the state of @p x inserted or in an
- * error state.
+ * @returns The output stream with the state of @p __x inserted or in
+ * an error state.
*/
template<typename _CharT, typename _Traits>
friend basic_ostream<_CharT, _Traits>&
@@ -1216,12 +1280,12 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
/**
* Extracts a %unform_int random number distribution
- * @p u from the input stream @p __is.
+ * @p __u from the input stream @p __is.
*
* @param __is An input stream.
* @param __u A %uniform_int random number generator engine.
*
- * @returns The input stream with @p u extracted or in an error state.
+ * @returns The input stream with @p __u extracted or in an error state.
*/
template<typename _CharT, typename _Traits>
friend basic_istream<_CharT, _Traits>&
@@ -1303,13 +1367,13 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
/**
* Inserts a %bernoulli_distribution random number distribution
- * @p x into the output stream @p __os.
+ * @p __x into the output stream @p __os.
*
* @param __os An output stream.
* @param __x A %bernoulli_distribution random number distribution.
*
- * @returns The output stream with the state of @p x inserted or in an
- * error state.
+ * @returns The output stream with the state of @p __x inserted or in
+ * an error state.
*/
template<typename _CharT, typename _Traits>
friend basic_ostream<_CharT, _Traits>&
@@ -1319,12 +1383,12 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
/**
* Extracts a %bernoulli_distribution random number distribution
- * @p u from the input stream @p __is.
+ * @p __u from the input stream @p __is.
*
* @param __is An input stream.
* @param __u A %bernoulli_distribution random number generator engine.
*
- * @returns The input stream with @p u extracted or in an error state.
+ * @returns The input stream with @p __u extracted or in an error state.
*/
template<typename _CharT, typename _Traits>
friend basic_istream<_CharT, _Traits>&
@@ -1393,13 +1457,13 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
/**
* Inserts a %geometric_distribution random number distribution
- * @p x into the output stream @p __os.
+ * @p __x into the output stream @p __os.
*
* @param __os An output stream.
* @param __x A %geometric_distribution random number distribution.
*
- * @returns The output stream with the state of @p x inserted or in an
- * error state.
+ * @returns The output stream with the state of @p __x inserted or in
+ * an error state.
*/
template<typename _CharT, typename _Traits>
friend basic_ostream<_CharT, _Traits>&
@@ -1409,12 +1473,12 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
/**
* Extracts a %geometric_distribution random number distribution
- * @p u from the input stream @p __is.
+ * @p __u from the input stream @p __is.
*
* @param __is An input stream.
* @param __u A %geometric_distribution random number generator engine.
*
- * @returns The input stream with @p u extracted or in an error state.
+ * @returns The input stream with @p __u extracted or in an error state.
*/
template<typename _CharT, typename _Traits>
friend basic_istream<_CharT, _Traits>&
@@ -1479,14 +1543,14 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
{ return (__urng() * (max() - min())) + min(); }
/**
- * Inserts a %uniform_real random number distribution @p x into the
+ * Inserts a %uniform_real random number distribution @p __x into the
* output stream @p __os.
*
* @param __os An output stream.
* @param __x A %uniform_real random number distribution.
*
- * @returns The output stream with the state of @p x inserted or in an
- * error state.
+ * @returns The output stream with the state of @p __x inserted or in
+ * an error state.
*/
template<typename _CharT, typename _Traits>
friend basic_ostream<_CharT, _Traits>&
@@ -1496,12 +1560,12 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
/**
* Extracts a %unform_real random number distribution
- * @p u from the input stream @p __is.
+ * @p __u from the input stream @p __is.
*
* @param __is An input stream.
* @param __u A %uniform_real random number generator engine.
*
- * @returns The input stream with @p u extracted or in an error state.
+ * @returns The input stream with @p __u extracted or in an error state.
*/
template<typename _CharT, typename _Traits>
friend basic_istream<_CharT, _Traits>&
@@ -1569,13 +1633,13 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
/**
* Inserts a %exponential_distribution random number distribution
- * @p x into the output stream @p __os.
+ * @p __x into the output stream @p __os.
*
* @param __os An output stream.
* @param __x A %exponential_distribution random number distribution.
*
- * @returns The output stream with the state of @p x inserted or in an
- * error state.
+ * @returns The output stream with the state of @p __x inserted or in
+ * an error state.
*/
template<typename _CharT, typename _Traits>
friend basic_ostream<_CharT, _Traits>&
@@ -1585,12 +1649,12 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
/**
* Extracts a %exponential_distribution random number distribution
- * @p u from the input stream @p __is.
+ * @p __u from the input stream @p __is.
*
* @param __is An input stream.
* @param __u A %exponential_distribution random number generator engine.
*
- * @returns The input stream with @p u extracted or in an error state.
+ * @returns The input stream with @p __u extracted or in an error state.
*/
template<typename _CharT, typename _Traits>
friend basic_istream<_CharT, _Traits>&
OpenPOWER on IntegriCloud