summaryrefslogtreecommitdiff
path: root/libstdc++-v3/include/bits/random.h
diff options
context:
space:
mode:
authorpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>2010-10-13 16:31:17 +0000
committerpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>2010-10-13 16:31:17 +0000
commit184886d6a4fb02ccbb21009a0bbc942c40269247 (patch)
treeee11340a00980bdc2575e8ebac1445fb12f45800 /libstdc++-v3/include/bits/random.h
parent647e976667a668f8ea754978e29e7f09eb8a40f9 (diff)
downloadgcc-184886d6a4fb02ccbb21009a0bbc942c40269247.tar.gz
2010-10-13 Paolo Carlini <paolo.carlini@oracle.com>
* include/bits/random.h (discrete_distribution<>::param_type:: param_type()): Default construct the vectors. (discrete_distribution<>::param_type::probabilities): Adjust. (discrete_distribution<>::probabilities): Likewise. (discrete_distribution<>::max): Likewise. (piecewise_constant_distribution<>::param_type:: param_type()): Default construct the vectors. (piecewise_constant_distribution<>::param_type::intervals): Adjust. (piecewise_constant_distribution<>::param_type::densities): Likewise. (piecewise_constant_distribution<>::intervals): Likewise. (piecewise_constant_distribution<>::densities): Likewise. (piecewise_constant_distribution<>::min): Likewise. (piecewise_constant_distribution<>::max): Likewise. (piecewise_linear_distribution<>::param_type:: param_type()): Default construct the vectors. (piecewise_linear_distribution<>::param_type::intervals): Adjust. (piecewise_linear_distribution<>::param_type::densities): Likewise. (piecewise_linear_distribution<>::intervals): Likewise. (piecewise_linear_distribution<>::densities): Likewise. (piecewise_linear_distribution<>::min): Likewise. (piecewise_linear_distribution<>::max): Likewise. * include/bits/random.tcc (discrete_distribution<>::param_type:: _M_initialize): Deal quickly with raw _M_prob equivalent to a default constructed param_type, just clear the vector. (discrete_distribution<>::operator()): Early return 0 for a default constructed distribution. (piecewise_constant_distribution<>::param_type::_M_initialize): Likewise for _M_int and _M_den. (piecewise_constant_distribution<>::operator()): Early return for a default constructed distribution. (piecewise_linear_distribution<>::param_type::_M_initialize): Likewise. (piecewise_linear_distribution<>::operator()): Early return for a default constructed distribution. * testsuite/26_numerics/random/discrete_distribution/operators/ call-default.cc: New. * testsuite/26_numerics/random/piecewise_constant_distribution/ operators/call-default.cc: Likewise. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@165427 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3/include/bits/random.h')
-rw-r--r--libstdc++-v3/include/bits/random.h100
1 files changed, 80 insertions, 20 deletions
diff --git a/libstdc++-v3/include/bits/random.h b/libstdc++-v3/include/bits/random.h
index 2477d57a9e1..cfb286a3c97 100644
--- a/libstdc++-v3/include/bits/random.h
+++ b/libstdc++-v3/include/bits/random.h
@@ -4697,7 +4697,7 @@ namespace std
friend class discrete_distribution<_IntType>;
param_type()
- : _M_prob(1, 1.0), _M_cp()
+ : _M_prob(), _M_cp()
{ }
template<typename _InputIterator>
@@ -4720,7 +4720,7 @@ namespace std
std::vector<double>
probabilities() const
- { return _M_prob; }
+ { return _M_prob.empty() ? std::vector<double>(1, 1.0) : _M_prob; }
friend bool
operator==(const param_type& __p1, const param_type& __p2)
@@ -4771,7 +4771,10 @@ namespace std
*/
std::vector<double>
probabilities() const
- { return _M_param.probabilities(); }
+ {
+ return _M_param._M_prob.empty()
+ ? std::vector<double>(1, 1.0) : _M_param._M_prob;
+ }
/**
* @brief Returns the parameter set of the distribution.
@@ -4800,7 +4803,10 @@ namespace std
*/
result_type
max() const
- { return this->_M_param._M_prob.size() - 1; }
+ {
+ return _M_param._M_prob.empty()
+ ? result_type(0) : result_type(_M_param._M_prob.size() - 1);
+ }
/**
* @brief Generating functions.
@@ -4893,8 +4899,8 @@ namespace std
friend class piecewise_constant_distribution<_RealType>;
param_type()
- : _M_int(2), _M_den(1, 1.0), _M_cp()
- { _M_int[1] = _RealType(1); }
+ : _M_int(), _M_den(), _M_cp()
+ { }
template<typename _InputIteratorB, typename _InputIteratorW>
param_type(_InputIteratorB __bfirst,
@@ -4914,11 +4920,20 @@ namespace std
std::vector<_RealType>
intervals() const
- { return _M_int; }
+ {
+ if (_M_int.empty())
+ {
+ std::vector<_RealType> __tmp(2);
+ __tmp[1] = _RealType(1);
+ return __tmp;
+ }
+ else
+ return _M_int;
+ }
std::vector<double>
densities() const
- { return _M_den; }
+ { return _M_den.empty() ? std::vector<double>(1, 1.0) : _M_den; }
friend bool
operator==(const param_type& __p1, const param_type& __p2)
@@ -4975,14 +4990,26 @@ namespace std
*/
std::vector<_RealType>
intervals() const
- { return _M_param.intervals(); }
+ {
+ if (_M_param._M_int.empty())
+ {
+ std::vector<_RealType> __tmp(2);
+ __tmp[1] = _RealType(1);
+ return __tmp;
+ }
+ else
+ return _M_param._M_int;
+ }
/**
* @brief Returns a vector of the probability densities.
*/
std::vector<double>
densities() const
- { return _M_param.densities(); }
+ {
+ return _M_param._M_den.empty()
+ ? std::vector<double>(1, 1.0) : _M_param._M_den;
+ }
/**
* @brief Returns the parameter set of the distribution.
@@ -5004,14 +5031,20 @@ namespace std
*/
result_type
min() const
- { return this->_M_param._M_int.front(); }
+ {
+ return _M_param._M_int.empty()
+ ? result_type(0) : _M_param._M_int.front();
+ }
/**
* @brief Returns the least upper bound value of the distribution.
*/
result_type
max() const
- { return this->_M_param._M_int.back(); }
+ {
+ return _M_param._M_int.empty()
+ ? result_type(1) : _M_param._M_int.back();
+ }
/**
* @brief Generating functions.
@@ -5105,8 +5138,8 @@ namespace std
friend class piecewise_linear_distribution<_RealType>;
param_type()
- : _M_int(2), _M_den(2, 1.0), _M_cp(), _M_m()
- { _M_int[1] = _RealType(1); }
+ : _M_int(), _M_den(), _M_cp(), _M_m()
+ { }
template<typename _InputIteratorB, typename _InputIteratorW>
param_type(_InputIteratorB __bfirst,
@@ -5126,11 +5159,20 @@ namespace std
std::vector<_RealType>
intervals() const
- { return _M_int; }
+ {
+ if (_M_int.empty())
+ {
+ std::vector<_RealType> __tmp(2);
+ __tmp[1] = _RealType(1);
+ return __tmp;
+ }
+ else
+ return _M_int;
+ }
std::vector<double>
densities() const
- { return _M_den; }
+ { return _M_den.empty() ? std::vector<double>(2, 1.0) : _M_den; }
friend bool
operator==(const param_type& __p1, const param_type& __p2)
@@ -5189,7 +5231,16 @@ namespace std
*/
std::vector<_RealType>
intervals() const
- { return _M_param.intervals(); }
+ {
+ if (_M_param._M_int.empty())
+ {
+ std::vector<_RealType> __tmp(2);
+ __tmp[1] = _RealType(1);
+ return __tmp;
+ }
+ else
+ return _M_param._M_int;
+ }
/**
* @brief Return a vector of the probability densities of the
@@ -5197,7 +5248,10 @@ namespace std
*/
std::vector<double>
densities() const
- { return _M_param.densities(); }
+ {
+ return _M_param._M_den.empty()
+ ? std::vector<double>(2, 1.0) : _M_param._M_den;
+ }
/**
* @brief Returns the parameter set of the distribution.
@@ -5219,14 +5273,20 @@ namespace std
*/
result_type
min() const
- { return this->_M_param._M_int.front(); }
+ {
+ return _M_param._M_int.empty()
+ ? result_type(0) : _M_param._M_int.front();
+ }
/**
* @brief Returns the least upper bound value of the distribution.
*/
result_type
max() const
- { return this->_M_param._M_int.back(); }
+ {
+ return _M_param._M_int.empty()
+ ? result_type(1) : _M_param._M_int.back();
+ }
/**
* @brief Generating functions.