summaryrefslogtreecommitdiff
path: root/libstdc++-v3/include/bits
diff options
context:
space:
mode:
authorbstarynk <bstarynk@138bc75d-0d04-0410-961f-82ee72b054a4>2012-08-29 12:37:05 +0000
committerbstarynk <bstarynk@138bc75d-0d04-0410-961f-82ee72b054a4>2012-08-29 12:37:05 +0000
commit12cb78d1cca1387a092ec0bd49c250340bff4afc (patch)
tree1eab97da96906e0a2786d51d9f25f20de02befcf /libstdc++-v3/include/bits
parent31879e18aea3222fe3e56f2c0319c9f230645ff3 (diff)
downloadgcc-12cb78d1cca1387a092ec0bd49c250340bff4afc.tar.gz
2012-08-29 Basile Starynkevitch <basile@starynkevitch.net>
MELT branch merged with trunk rev 190745 using svnmerge, notably C++ conversion. [gcc/] 2012-08-29 Basile Starynkevitch <basile@starynkevitch.net> {{merging with trunk, converted to C++}} * melt-runtime.h (MELT_FLEXIBLE_DIM): Set when C++. * melt-runtime.c (melt_tempdir_path): Don't use choose_tmpdir from libiberty. (meltgc_start_module_by_index): Use address-of & on VEC_index. (melt_really_initialize): When printing builtin settings, handle GCC 4.8 as with implicit ENABLE_BUILD_WITH_CXX. (meltgc_out_edge): Provide additional flag TDF_DETAILS for dump_edge_info. (melt_val2passflag): Handle PROP_referenced_vars only when defined. * melt-module.mk: Use GCCMELT_COMPILER instead of GCCMELT_CC. * melt-build-script.tpl: Transmit GCCMELT_COMPILER on every make using melt-module.mk and improve the error message. * melt-build-script.sh: Regenerate. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/melt-branch@190778 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3/include/bits')
-rw-r--r--libstdc++-v3/include/bits/alloc_traits.h26
-rw-r--r--libstdc++-v3/include/bits/atomic_base.h8
-rw-r--r--libstdc++-v3/include/bits/c++config4
-rw-r--r--libstdc++-v3/include/bits/concept_check.h4
-rw-r--r--libstdc++-v3/include/bits/hashtable.h304
-rw-r--r--libstdc++-v3/include/bits/hashtable_policy.h60
-rw-r--r--libstdc++-v3/include/bits/list.tcc44
-rw-r--r--libstdc++-v3/include/bits/ptr_traits.h5
-rw-r--r--libstdc++-v3/include/bits/random.h717
-rw-r--r--libstdc++-v3/include/bits/random.tcc682
-rw-r--r--libstdc++-v3/include/bits/shared_ptr.h13
-rw-r--r--libstdc++-v3/include/bits/shared_ptr_base.h25
-rw-r--r--libstdc++-v3/include/bits/stl_list.h62
-rw-r--r--libstdc++-v3/include/bits/stl_map.h10
-rw-r--r--libstdc++-v3/include/bits/stl_multimap.h10
-rw-r--r--libstdc++-v3/include/bits/stl_pair.h10
-rw-r--r--libstdc++-v3/include/bits/unique_ptr.h31
17 files changed, 1610 insertions, 405 deletions
diff --git a/libstdc++-v3/include/bits/alloc_traits.h b/libstdc++-v3/include/bits/alloc_traits.h
index e1f4d41a6d0..80cc956a6fb 100644
--- a/libstdc++-v3/include/bits/alloc_traits.h
+++ b/libstdc++-v3/include/bits/alloc_traits.h
@@ -1,6 +1,6 @@
// Allocator traits -*- C++ -*-
-// Copyright (C) 2011 Free Software Foundation, Inc.
+// Copyright (C) 2011-2012 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
@@ -56,6 +56,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
static const bool __value = _S_chk<_Alloc, _Tp>(nullptr);
};
+ template<typename _Alloc, typename _Tp>
+ const bool __alloctr_rebind_helper<_Alloc, _Tp>::__value;
+
template<typename _Alloc, typename _Tp,
bool = __alloctr_rebind_helper<_Alloc, _Tp>::__value>
struct __alloctr_rebind;
@@ -423,6 +426,27 @@ _GLIBCXX_ALLOC_TR_NESTED_TYPE(propagate_on_container_swap,
};
template<typename _Alloc>
+ template<typename _Alloc2>
+ const bool allocator_traits<_Alloc>::__allocate_helper<_Alloc2>::value;
+
+ template<typename _Alloc>
+ template<typename _Tp, typename... _Args>
+ const bool
+ allocator_traits<_Alloc>::__construct_helper<_Tp, _Args...>::value;
+
+ template<typename _Alloc>
+ template<typename _Tp>
+ const bool allocator_traits<_Alloc>::__destroy_helper<_Tp>::value;
+
+ template<typename _Alloc>
+ template<typename _Alloc2>
+ const bool allocator_traits<_Alloc>::__maxsize_helper<_Alloc2>::value;
+
+ template<typename _Alloc>
+ template<typename _Alloc2>
+ const bool allocator_traits<_Alloc>::__select_helper<_Alloc2>::value;
+
+ template<typename _Alloc>
inline void
__do_alloc_on_copy(_Alloc& __one, const _Alloc& __two, true_type)
{ __one = __two; }
diff --git a/libstdc++-v3/include/bits/atomic_base.h b/libstdc++-v3/include/bits/atomic_base.h
index 9d5f4eb6ff0..598e1f1e945 100644
--- a/libstdc++-v3/include/bits/atomic_base.h
+++ b/libstdc++-v3/include/bits/atomic_base.h
@@ -422,11 +422,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
bool
is_lock_free() const noexcept
- { return __atomic_is_lock_free (sizeof (_M_i), &_M_i); }
+ { return __atomic_always_lock_free(sizeof(_M_i), &_M_i); }
bool
is_lock_free() const volatile noexcept
- { return __atomic_is_lock_free (sizeof (_M_i), &_M_i); }
+ { return __atomic_always_lock_free(sizeof(_M_i), &_M_i); }
void
store(__int_type __i, memory_order __m = memory_order_seq_cst) noexcept
@@ -716,11 +716,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
bool
is_lock_free() const noexcept
- { return __atomic_is_lock_free(_M_type_size(1), &_M_p); }
+ { return __atomic_always_lock_free(_M_type_size(1), &_M_p); }
bool
is_lock_free() const volatile noexcept
- { return __atomic_is_lock_free(_M_type_size(1), &_M_p); }
+ { return __atomic_always_lock_free(_M_type_size(1), &_M_p); }
void
store(__pointer_type __p,
diff --git a/libstdc++-v3/include/bits/c++config b/libstdc++-v3/include/bits/c++config
index 18061519167..60b6f126b83 100644
--- a/libstdc++-v3/include/bits/c++config
+++ b/libstdc++-v3/include/bits/c++config
@@ -287,7 +287,7 @@ namespace std
# define _GLIBCXX_BEGIN_NAMESPACE_CONTAINER \
namespace _GLIBCXX_STD_C { _GLIBCXX_BEGIN_NAMESPACE_VERSION
# define _GLIBCXX_END_NAMESPACE_CONTAINER \
- } _GLIBCXX_END_NAMESPACE_VERSION
+ _GLIBCXX_END_NAMESPACE_VERSION }
# undef _GLIBCXX_EXTERN_TEMPLATE
# define _GLIBCXX_EXTERN_TEMPLATE -1
#endif
@@ -297,7 +297,7 @@ namespace std
# define _GLIBCXX_BEGIN_NAMESPACE_ALGO \
namespace _GLIBCXX_STD_A { _GLIBCXX_BEGIN_NAMESPACE_VERSION
# define _GLIBCXX_END_NAMESPACE_ALGO \
- } _GLIBCXX_END_NAMESPACE_VERSION
+ _GLIBCXX_END_NAMESPACE_VERSION }
#endif
#ifndef _GLIBCXX_STD_A
diff --git a/libstdc++-v3/include/bits/concept_check.h b/libstdc++-v3/include/bits/concept_check.h
index 9517e5cd737..3d74284e8cf 100644
--- a/libstdc++-v3/include/bits/concept_check.h
+++ b/libstdc++-v3/include/bits/concept_check.h
@@ -56,12 +56,12 @@
// Note that the obvious and elegant approach of
//
-//#define glibcxx_function_requires(C) boost::function_requires< boost::C >()
+//#define glibcxx_function_requires(C) debug::function_requires< debug::C >()
//
// won't work due to concept templates with more than one parameter, e.g.,
// BinaryPredicateConcept. The preprocessor tries to split things up on
// the commas in the template argument list. We can't use an inner pair of
-// parenthesis to hide the commas, because "boost::(Temp<Foo,Bar>)" isn't
+// parenthesis to hide the commas, because "debug::(Temp<Foo,Bar>)" isn't
// a valid instantiation pattern. Thus, we steal a feature from C99.
#define __glibcxx_function_requires(...) \
diff --git a/libstdc++-v3/include/bits/hashtable.h b/libstdc++-v3/include/bits/hashtable.h
index f5bc3583f22..2018575dea7 100644
--- a/libstdc++-v3/include/bits/hashtable.h
+++ b/libstdc++-v3/include/bits/hashtable.h
@@ -584,10 +584,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
__node_base*
_M_get_previous_node(size_type __bkt, __node_base* __n);
- template<typename _Arg>
- iterator
- _M_insert_bucket(_Arg&&, size_type, __hash_code);
+ // Insert node with hash code __code, in bucket bkt if no rehash (assumes
+ // no element with its key already present). Take ownership of the node,
+ // deallocate it on exception.
+ iterator
+ _M_insert_unique_node(size_type __bkt, __hash_code __code,
+ __node_type* __n);
+ // Insert node with hash code __code. Take ownership of the node,
+ // deallocate it on exception.
+ iterator
+ _M_insert_multi_node(__hash_code __code, __node_type* __n);
template<typename... _Args>
std::pair<iterator, bool>
@@ -803,11 +810,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_M_element_count(0),
_M_rehash_policy()
{
- _M_bucket_count = std::max(_M_rehash_policy._M_next_bkt(__bucket_hint),
- _M_rehash_policy.
- _M_bkt_for_elements(__detail::
- __distance_fw(__f,
- __l)));
+ _M_bucket_count =
+ _M_rehash_policy._M_bkt_for_elements(__detail::__distance_fw(__f,
+ __l));
+ if (_M_bucket_count <= __bucket_hint)
+ _M_bucket_count = _M_rehash_policy._M_next_bkt(__bucket_hint);
// We don't want the rehash policy to ask for the hashtable to
// shrink on the first insertion so we need to reset its
@@ -1214,42 +1221,29 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{
// First build the node to get access to the hash code
__node_type* __node = _M_allocate_node(std::forward<_Args>(__args)...);
+ const key_type& __k = this->_M_extract()(__node->_M_v);
+ __hash_code __code;
__try
{
- const key_type& __k = this->_M_extract()(__node->_M_v);
- __hash_code __code = this->_M_hash_code(__k);
- size_type __bkt = _M_bucket_index(__k, __code);
-
- if (__node_type* __p = _M_find_node(__bkt, __k, __code))
- {
- // There is already an equivalent node, no insertion
- _M_deallocate_node(__node);
- return std::make_pair(iterator(__p), false);
- }
-
- // We are going to insert this node
- this->_M_store_code(__node, __code);
- const __rehash_state& __saved_state
- = _M_rehash_policy._M_state();
- std::pair<bool, std::size_t> __do_rehash
- = _M_rehash_policy._M_need_rehash(_M_bucket_count,
- _M_element_count, 1);
-
- if (__do_rehash.first)
- {
- _M_rehash(__do_rehash.second, __saved_state);
- __bkt = _M_bucket_index(__k, __code);
- }
-
- _M_insert_bucket_begin(__bkt, __node);
- ++_M_element_count;
- return std::make_pair(iterator(__node), true);
+ __code = this->_M_hash_code(__k);
}
__catch(...)
{
_M_deallocate_node(__node);
__throw_exception_again;
}
+
+ size_type __bkt = _M_bucket_index(__k, __code);
+ if (__node_type* __p = _M_find_node(__bkt, __k, __code))
+ {
+ // There is already an equivalent node, no insertion
+ _M_deallocate_node(__node);
+ return std::make_pair(iterator(__p), false);
+ }
+
+ // Insert the node
+ return std::make_pair(_M_insert_unique_node(__bkt, __code, __node),
+ true);
}
template<typename _Key, typename _Value,
@@ -1264,97 +1258,110 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_H1, _H2, _Hash, _RehashPolicy, _Traits>::
_M_emplace(std::false_type, _Args&&... __args)
{
- const __rehash_state& __saved_state = _M_rehash_policy._M_state();
- std::pair<bool, std::size_t> __do_rehash
- = _M_rehash_policy._M_need_rehash(_M_bucket_count,
- _M_element_count, 1);
-
// First build the node to get its hash code.
__node_type* __node = _M_allocate_node(std::forward<_Args>(__args)...);
+
+ __hash_code __code;
__try
{
- const key_type& __k = this->_M_extract()(__node->_M_v);
- __hash_code __code = this->_M_hash_code(__k);
- this->_M_store_code(__node, __code);
-
- // Second, do rehash if necessary.
- if (__do_rehash.first)
- _M_rehash(__do_rehash.second, __saved_state);
-
- // Third, find the node before an equivalent one.
- size_type __bkt = _M_bucket_index(__k, __code);
- __node_base* __prev = _M_find_before_node(__bkt, __k, __code);
-
- if (__prev)
- {
- // Insert after the node before the equivalent one.
- __node->_M_nxt = __prev->_M_nxt;
- __prev->_M_nxt = __node;
- }
- else
- // The inserted node has no equivalent in the
- // hashtable. We must insert the new node at the
- // beginning of the bucket to preserve equivalent
- // elements relative positions.
- _M_insert_bucket_begin(__bkt, __node);
- ++_M_element_count;
- return iterator(__node);
+ __code = this->_M_hash_code(this->_M_extract()(__node->_M_v));
}
__catch(...)
{
_M_deallocate_node(__node);
__throw_exception_again;
}
+
+ return _M_insert_multi_node(__code, __node);
}
- // Insert v in bucket n (assumes no element with its key already present).
template<typename _Key, typename _Value,
typename _Alloc, typename _ExtractKey, typename _Equal,
typename _H1, typename _H2, typename _Hash, typename _RehashPolicy,
typename _Traits>
- template<typename _Arg>
- typename _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
- _H1, _H2, _Hash, _RehashPolicy,
- _Traits>::iterator
- _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
- _H1, _H2, _Hash, _RehashPolicy, _Traits>::
- _M_insert_bucket(_Arg&& __v, size_type __n, __hash_code __code)
- {
- const __rehash_state& __saved_state = _M_rehash_policy._M_state();
- std::pair<bool, std::size_t> __do_rehash
- = _M_rehash_policy._M_need_rehash(_M_bucket_count,
- _M_element_count, 1);
-
- if (__do_rehash.first)
- {
- const key_type& __k = this->_M_extract()(__v);
- __n = __hash_code_base::_M_bucket_index(__k, __code,
- __do_rehash.second);
- }
+ typename _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
+ _H1, _H2, _Hash, _RehashPolicy,
+ _Traits>::iterator
+ _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
+ _H1, _H2, _Hash, _RehashPolicy, _Traits>::
+ _M_insert_unique_node(size_type __bkt, __hash_code __code,
+ __node_type* __node)
+ {
+ const __rehash_state& __saved_state = _M_rehash_policy._M_state();
+ std::pair<bool, std::size_t> __do_rehash
+ = _M_rehash_policy._M_need_rehash(_M_bucket_count, _M_element_count, 1);
- __node_type* __node = nullptr;
- __try
- {
- // Allocate the new node before doing the rehash so that we
- // don't do a rehash if the allocation throws.
- __node = _M_allocate_node(std::forward<_Arg>(__v));
- this->_M_store_code(__node, __code);
- if (__do_rehash.first)
+ __try
+ {
+ if (__do_rehash.first)
+ {
_M_rehash(__do_rehash.second, __saved_state);
+ __bkt = _M_bucket_index(this->_M_extract()(__node->_M_v), __code);
+ }
- _M_insert_bucket_begin(__n, __node);
- ++_M_element_count;
- return iterator(__node);
- }
- __catch(...)
- {
- if (!__node)
- _M_rehash_policy._M_reset(__saved_state);
- else
- _M_deallocate_node(__node);
- __throw_exception_again;
- }
- }
+ this->_M_store_code(__node, __code);
+
+ // Always insert at the begining of the bucket.
+ _M_insert_bucket_begin(__bkt, __node);
+ ++_M_element_count;
+ return iterator(__node);
+ }
+ __catch(...)
+ {
+ _M_deallocate_node(__node);
+ __throw_exception_again;
+ }
+ }
+
+ // Insert node, in bucket bkt if no rehash (assumes no element with its key
+ // already present). Take ownership of the node, deallocate it on exception.
+ template<typename _Key, typename _Value,
+ typename _Alloc, typename _ExtractKey, typename _Equal,
+ typename _H1, typename _H2, typename _Hash, typename _RehashPolicy,
+ typename _Traits>
+ typename _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
+ _H1, _H2, _Hash, _RehashPolicy,
+ _Traits>::iterator
+ _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
+ _H1, _H2, _Hash, _RehashPolicy, _Traits>::
+ _M_insert_multi_node(__hash_code __code, __node_type* __node)
+ {
+ const __rehash_state& __saved_state = _M_rehash_policy._M_state();
+ std::pair<bool, std::size_t> __do_rehash
+ = _M_rehash_policy._M_need_rehash(_M_bucket_count, _M_element_count, 1);
+
+ __try
+ {
+ if (__do_rehash.first)
+ _M_rehash(__do_rehash.second, __saved_state);
+
+ this->_M_store_code(__node, __code);
+ const key_type& __k = this->_M_extract()(__node->_M_v);
+ size_type __bkt = _M_bucket_index(__k, __code);
+
+ // Find the node before an equivalent one.
+ __node_base* __prev = _M_find_before_node(__bkt, __k, __code);
+ if (__prev)
+ {
+ // Insert after the node before the equivalent one.
+ __node->_M_nxt = __prev->_M_nxt;
+ __prev->_M_nxt = __node;
+ }
+ else
+ // The inserted node has no equivalent in the
+ // hashtable. We must insert the new node at the
+ // beginning of the bucket to preserve equivalent
+ // elements relative positions.
+ _M_insert_bucket_begin(__bkt, __node);
+ ++_M_element_count;
+ return iterator(__node);
+ }
+ __catch(...)
+ {
+ _M_deallocate_node(__node);
+ __throw_exception_again;
+ }
+ }
// Insert v if no element with its key is already present.
template<typename _Key, typename _Value,
@@ -1372,12 +1379,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{
const key_type& __k = this->_M_extract()(__v);
__hash_code __code = this->_M_hash_code(__k);
- size_type __n = _M_bucket_index(__k, __code);
+ size_type __bkt = _M_bucket_index(__k, __code);
+
+ __node_type* __n = _M_find_node(__bkt, __k, __code);
+ if (__n)
+ return std::make_pair(iterator(__n), false);
- if (__node_type* __p = _M_find_node(__n, __k, __code))
- return std::make_pair(iterator(__p), false);
- return std::make_pair(_M_insert_bucket(std::forward<_Arg>(__v),
- __n, __code), true);
+ __n = _M_allocate_node(std::forward<_Arg>(__v));
+ return std::make_pair(_M_insert_unique_node(__bkt, __code, __n), true);
}
// Insert v unconditionally.
@@ -1393,54 +1402,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_H1, _H2, _Hash, _RehashPolicy, _Traits>::
_M_insert(_Arg&& __v, std::false_type)
{
- const __rehash_state& __saved_state = _M_rehash_policy._M_state();
- std::pair<bool, std::size_t> __do_rehash
- = _M_rehash_policy._M_need_rehash(_M_bucket_count,
- _M_element_count, 1);
-
- // First compute the hash code so that we don't do anything if
- // it throws.
+ // First compute the hash code so that we don't do anything if it
+ // throws.
__hash_code __code = this->_M_hash_code(this->_M_extract()(__v));
- __node_type* __node = nullptr;
- __try
- {
- // Second allocate new node so that we don't rehash if it throws.
- __node = _M_allocate_node(std::forward<_Arg>(__v));
- this->_M_store_code(__node, __code);
- if (__do_rehash.first)
- _M_rehash(__do_rehash.second, __saved_state);
-
- // Third, find the node before an equivalent one.
- size_type __bkt = _M_bucket_index(__node);
- __node_base* __prev
- = _M_find_before_node(__bkt, this->_M_extract()(__node->_M_v),
- __code);
- if (__prev)
- {
- // Insert after the node before the equivalent one.
- __node->_M_nxt = __prev->_M_nxt;
- __prev->_M_nxt = __node;
- }
- else
- // The inserted node has no equivalent in the
- // hashtable. We must insert the new node at the
- // beginning of the bucket to preserve equivalent
- // elements relative positions.
- _M_insert_bucket_begin(__bkt, __node);
- ++_M_element_count;
- return iterator(__node);
- }
- __catch(...)
- {
- if (!__node)
- _M_rehash_policy._M_reset(__saved_state);
- else
- _M_deallocate_node(__node);
- __throw_exception_again;
- }
- }
+ // Second allocate new node so that we don't rehash if it throws.
+ __node_type* __node = _M_allocate_node(std::forward<_Arg>(__v));
+ return _M_insert_multi_node(__code, __node);
+ }
template<typename _Key, typename _Value,
typename _Alloc, typename _ExtractKey, typename _Equal,
@@ -1609,10 +1579,20 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
rehash(size_type __n)
{
const __rehash_state& __saved_state = _M_rehash_policy._M_state();
- _M_rehash(std::max(_M_rehash_policy._M_next_bkt(__n),
- _M_rehash_policy._M_bkt_for_elements(_M_element_count
- + 1)),
- __saved_state);
+ std::size_t __buckets
+ = _M_rehash_policy._M_bkt_for_elements(_M_element_count + 1);
+ if (__buckets <= __n)
+ __buckets = _M_rehash_policy._M_next_bkt(__n);
+
+ if (__buckets != _M_bucket_count)
+ {
+ _M_rehash(__buckets, __saved_state);
+
+ // We don't want the rehash policy to ask for the hashtable to shrink
+ // on the next insertion so we need to reset its previous resize
+ // level.
+ _M_rehash_policy._M_prev_resize = 0;
+ }
}
template<typename _Key, typename _Value,
diff --git a/libstdc++-v3/include/bits/hashtable_policy.h b/libstdc++-v3/include/bits/hashtable_policy.h
index 27badbcb104..6350ae622e4 100644
--- a/libstdc++-v3/include/bits/hashtable_policy.h
+++ b/libstdc++-v3/include/bits/hashtable_policy.h
@@ -395,6 +395,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
enum { _S_n_primes = sizeof(unsigned long) != 8 ? 256 : 256 + 48 };
+ static const std::size_t _S_growth_factor = 2;
+
float _M_max_load_factor;
mutable std::size_t _M_prev_resize;
mutable std::size_t _M_next_resize;
@@ -415,28 +417,27 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
static const unsigned char __fast_bkt[12]
= { 2, 2, 2, 3, 5, 5, 7, 7, 11, 11, 11, 11 };
- if (__n <= 11)
+ const std::size_t __grown_n = __n * _S_growth_factor;
+ if (__grown_n <= 11)
{
_M_prev_resize = 0;
_M_next_resize
- = __builtin_ceil(__fast_bkt[__n] * (long double)_M_max_load_factor);
- return __fast_bkt[__n];
+ = __builtin_ceil(__fast_bkt[__grown_n]
+ * (long double)_M_max_load_factor);
+ return __fast_bkt[__grown_n];
}
- const unsigned long* __p
- = std::lower_bound(__prime_list + 5, __prime_list + _S_n_primes, __n);
+ const unsigned long* __next_bkt
+ = std::lower_bound(__prime_list + 5, __prime_list + _S_n_primes,
+ __grown_n);
+ const unsigned long* __prev_bkt
+ = std::lower_bound(__prime_list + 1, __next_bkt, __n / _S_growth_factor);
- // Shrink will take place only if the number of elements is small enough
- // so that the prime number 2 steps before __p is large enough to still
- // conform to the max load factor:
_M_prev_resize
- = __builtin_floor(*(__p - 2) * (long double)_M_max_load_factor);
-
- // Let's guaranty that a minimal grow step of 11 is used
- if (*__p - __n < 11)
- __p = std::lower_bound(__p, __prime_list + _S_n_primes, __n + 11);
- _M_next_resize = __builtin_ceil(*__p * (long double)_M_max_load_factor);
- return *__p;
+ = __builtin_floor(*(__prev_bkt - 1) * (long double)_M_max_load_factor);
+ _M_next_resize
+ = __builtin_ceil(*__next_bkt * (long double)_M_max_load_factor);
+ return *__next_bkt;
}
// Return the smallest prime p such that alpha p >= n, where alpha
@@ -576,8 +577,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
__node_type* __p = __h->_M_find_node(__n, __k, __code);
if (!__p)
- return __h->_M_insert_bucket(std::make_pair(__k, mapped_type()),
- __n, __code)->second;
+ {
+ __p = __h->_M_allocate_node(std::piecewise_construct,
+ std::tuple<const key_type&>(__k),
+ std::tuple<>());
+ return __h->_M_insert_unique_node(__n, __code, __p)->second;
+ }
+
return (__p->_M_v).second;
}
@@ -597,9 +603,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
__node_type* __p = __h->_M_find_node(__n, __k, __code);
if (!__p)
- return __h->_M_insert_bucket(std::make_pair(std::move(__k),
- mapped_type()),
- __n, __code)->second;
+ {
+ __p = __h->_M_allocate_node(std::piecewise_construct,
+ std::forward_as_tuple(std::move(__k)),
+ std::tuple<>());
+ return __h->_M_insert_unique_node(__n, __code, __p)->second;
+ }
+
return (__p->_M_v).second;
}
@@ -831,15 +841,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
using __base_type::insert;
template<typename _Pair>
- using __is_conv = std::is_convertible<_Pair, value_type>;
+ using __is_cons = std::is_constructible<value_type, _Pair&&>;
template<typename _Pair>
- using _IFconv = std::enable_if<__is_conv<_Pair>::value>;
+ using _IFcons = std::enable_if<__is_cons<_Pair>::value>;
template<typename _Pair>
- using _IFconvp = typename _IFconv<_Pair>::type;
+ using _IFconsp = typename _IFcons<_Pair>::type;
- template<typename _Pair, typename = _IFconvp<_Pair>>
+ template<typename _Pair, typename = _IFconsp<_Pair>>
__ireturn_type
insert(_Pair&& __v)
{
@@ -847,7 +857,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
return __h._M_insert(std::forward<_Pair>(__v), __unique_keys());
}
- template<typename _Pair, typename = _IFconvp<_Pair>>
+ template<typename _Pair, typename = _IFconsp<_Pair>>
iterator
insert(const_iterator, _Pair&& __v)
{ return __iconv_type()(insert(std::forward<_Pair>(__v))); }
diff --git a/libstdc++-v3/include/bits/list.tcc b/libstdc++-v3/include/bits/list.tcc
index 55156bbf062..727e82d3d8d 100644
--- a/libstdc++-v3/include/bits/list.tcc
+++ b/libstdc++-v3/include/bits/list.tcc
@@ -1,7 +1,7 @@
// List implementation (out of line) -*- C++ -*-
// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
-// 2011 Free Software Foundation, Inc.
+// 2011, 2012 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
@@ -139,14 +139,14 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
list<_Tp, _Alloc>::
resize(size_type __new_size)
{
- if (__new_size > size())
- _M_default_append(__new_size - size());
- else if (__new_size < size())
- {
- iterator __i = begin();
- std::advance(__i, __new_size);
- erase(__i, end());
- }
+ iterator __i = begin();
+ size_type __len = 0;
+ for (; __i != end() && __len < __new_size; ++__i, ++__len)
+ ;
+ if (__len == __new_size)
+ erase(__i, end());
+ else // __i == end()
+ _M_default_append(__new_size - __len);
}
template<typename _Tp, typename _Alloc>
@@ -154,14 +154,14 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
list<_Tp, _Alloc>::
resize(size_type __new_size, const value_type& __x)
{
- if (__new_size > size())
- insert(end(), __new_size - size(), __x);
- else if (__new_size < size())
- {
- iterator __i = begin();
- std::advance(__i, __new_size);
- erase(__i, end());
- }
+ iterator __i = begin();
+ size_type __len = 0;
+ for (; __i != end() && __len < __new_size; ++__i, ++__len)
+ ;
+ if (__len == __new_size)
+ erase(__i, end());
+ else // __i == end()
+ insert(end(), __new_size - __len, __x);
}
#else
template<typename _Tp, typename _Alloc>
@@ -312,11 +312,6 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
++__first1;
if (__first2 != __last2)
_M_transfer(__last1, __first2, __last2);
-
-#ifdef __GXX_EXPERIMENTAL_CXX0X__
- this->_M_impl._M_size += __x.size();
- __x._M_impl._M_size = 0;
-#endif
}
}
@@ -351,11 +346,6 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
++__first1;
if (__first2 != __last2)
_M_transfer(__last1, __first2, __last2);
-
-#ifdef __GXX_EXPERIMENTAL_CXX0X__
- this->_M_impl._M_size += __x.size();
- __x._M_impl._M_size = 0;
-#endif
}
}
diff --git a/libstdc++-v3/include/bits/ptr_traits.h b/libstdc++-v3/include/bits/ptr_traits.h
index bba9b49bfc6..552f48745f3 100644
--- a/libstdc++-v3/include/bits/ptr_traits.h
+++ b/libstdc++-v3/include/bits/ptr_traits.h
@@ -1,6 +1,6 @@
// Pointer Traits -*- C++ -*-
-// Copyright (C) 2011 Free Software Foundation, Inc.
+// Copyright (C) 2011-2012 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
@@ -86,6 +86,9 @@ _GLIBCXX_HAS_NESTED_TYPE(difference_type)
static const bool __value = _S_chk<_Ptr, _Up>(nullptr);
};
+ template<typename _Ptr, typename _Up>
+ const bool __ptrtr_rebind_helper<_Ptr, _Up>::__value;
+
template<typename _Tp, typename _Up,
bool = __ptrtr_rebind_helper<_Tp, _Up>::__value>
struct __ptrtr_rebind;
diff --git a/libstdc++-v3/include/bits/random.h b/libstdc++-v3/include/bits/random.h
index 4361296bca0..6bedc4250fb 100644
--- a/libstdc++-v3/include/bits/random.h
+++ b/libstdc++-v3/include/bits/random.h
@@ -530,11 +530,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* @brief Discard a sequence of random numbers.
*/
void
- discard(unsigned long long __z)
- {
- for (; __z != 0ULL; --__z)
- (*this)();
- }
+ discard(unsigned long long __z);
result_type
operator()();
@@ -610,6 +606,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
__l1, __f1>& __x);
private:
+ void _M_gen_rand();
+
_UIntType _M_x[state_size];
size_t _M_p;
};
@@ -1784,6 +1782,36 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
operator()(_UniformRandomNumberGenerator& __urng,
const param_type& __p);
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng)
+ { this->__generate(__f, __t, __urng, this->param()); }
+
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ { this->__generate_impl(__f, __t, __urng, __p); }
+
+ template<typename _UniformRandomNumberGenerator>
+ void
+ __generate(result_type* __f, result_type* __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ { this->__generate_impl(__f, __t, __urng, __p); }
+
+ private:
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p);
+
param_type _M_param;
};
@@ -1964,7 +1992,36 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
return (__aurng() * (__p.b() - __p.a())) + __p.a();
}
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng)
+ { this->__generate(__f, __t, __urng, this->param()); }
+
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ { this->__generate_impl(__f, __t, __urng, __p); }
+
+ template<typename _UniformRandomNumberGenerator>
+ void
+ __generate(result_type* __f, result_type* __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ { this->__generate_impl(__f, __t, __urng, __p); }
+
private:
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p);
+
param_type _M_param;
};
@@ -2153,6 +2210,28 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
operator()(_UniformRandomNumberGenerator& __urng,
const param_type& __p);
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng)
+ { this->__generate(__f, __t, __urng, this->param()); }
+
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ { this->__generate_impl(__f, __t, __urng, __p); }
+
+ template<typename _UniformRandomNumberGenerator>
+ void
+ __generate(result_type* __f, result_type* __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ { this->__generate_impl(__f, __t, __urng, __p); }
+
/**
* @brief Return true if two normal distributions have
* the same parameters and the sequences that would
@@ -2194,6 +2273,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
std::normal_distribution<_RealType1>& __x);
private:
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p);
+
param_type _M_param;
result_type _M_saved;
bool _M_saved_available;
@@ -2327,17 +2413,38 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
const param_type& __p)
{ return std::exp(__p.s() * _M_nd(__urng) + __p.m()); }
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng)
+ { this->__generate(__f, __t, __urng, this->param()); }
+
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ { this->__generate_impl(__f, __t, __urng, __p); }
+
+ template<typename _UniformRandomNumberGenerator>
+ void
+ __generate(result_type* __f, result_type* __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ { this->__generate_impl(__f, __t, __urng, __p); }
+
/**
* @brief Return true if two lognormal distributions have
* the same parameters and the sequences that would
* be generated are equal.
*/
- template<typename _RealType1>
- friend bool
- operator==(const std::lognormal_distribution<_RealType1>& __d1,
- const std::lognormal_distribution<_RealType1>& __d2)
- { return (__d1.param() == __d2.param()
- && __d1._M_nd == __d2._M_nd); }
+ friend bool
+ operator==(const lognormal_distribution& __d1,
+ const lognormal_distribution& __d2)
+ { return (__d1.param() == __d2.param()
+ && __d1._M_nd == __d2._M_nd); }
/**
* @brief Inserts a %lognormal_distribution random number distribution
@@ -2370,6 +2477,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
std::lognormal_distribution<_RealType1>& __x);
private:
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p);
+
param_type _M_param;
std::normal_distribution<result_type> _M_nd;
@@ -2520,17 +2634,38 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
operator()(_UniformRandomNumberGenerator& __urng,
const param_type& __p);
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng)
+ { this->__generate(__f, __t, __urng, this->param()); }
+
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ { this->__generate_impl(__f, __t, __urng, __p); }
+
+ template<typename _UniformRandomNumberGenerator>
+ void
+ __generate(result_type* __f, result_type* __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ { this->__generate_impl(__f, __t, __urng, __p); }
+
/**
* @brief Return true if two gamma distributions have the same
* parameters and the sequences that would be generated
* are equal.
*/
- template<typename _RealType1>
- friend bool
- operator==(const std::gamma_distribution<_RealType1>& __d1,
- const std::gamma_distribution<_RealType1>& __d2)
- { return (__d1.param() == __d2.param()
- && __d1._M_nd == __d2._M_nd); }
+ friend bool
+ operator==(const gamma_distribution& __d1,
+ const gamma_distribution& __d2)
+ { return (__d1.param() == __d2.param()
+ && __d1._M_nd == __d2._M_nd); }
/**
* @brief Inserts a %gamma_distribution random number distribution
@@ -2562,6 +2697,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
std::gamma_distribution<_RealType1>& __x);
private:
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p);
+
param_type _M_param;
std::normal_distribution<result_type> _M_nd;
@@ -2571,7 +2713,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* @brief Return true if two gamma distributions are different.
*/
template<typename _RealType>
- inline bool
+ inline bool
operator!=(const std::gamma_distribution<_RealType>& __d1,
const std::gamma_distribution<_RealType>& __d2)
{ return !(__d1 == __d2); }
@@ -2685,16 +2827,49 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
return 2 * _M_gd(__urng, param_type(__p.n() / 2));
}
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng)
+ { this->__generate_impl(__f, __t, __urng, _M_gd.param()); }
+
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ { typename std::gamma_distribution<result_type>::param_type
+ __p2(__p.n() / 2);
+ this->__generate_impl(__f, __t, __urng, __p2); }
+
+ template<typename _UniformRandomNumberGenerator>
+ void
+ __generate(result_type* __f, result_type* __t,
+ _UniformRandomNumberGenerator& __urng)
+ { typename std::gamma_distribution<result_type>::param_type
+ __p2(_M_gd.param());
+ this->__generate_impl(__f, __t, __urng, __p2); }
+
+ template<typename _UniformRandomNumberGenerator>
+ void
+ __generate(result_type* __f, result_type* __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ { typename std::gamma_distribution<result_type>::param_type
+ __p2(__p.n() / 2);
+ this->__generate_impl(__f, __t, __urng, __p2); }
+
/**
* @brief Return true if two Chi-squared distributions have
* the same parameters and the sequences that would be
* generated are equal.
*/
- template<typename _RealType1>
- friend bool
- operator==(const std::chi_squared_distribution<_RealType1>& __d1,
- const std::chi_squared_distribution<_RealType1>& __d2)
- { return __d1.param() == __d2.param() && __d1._M_gd == __d2._M_gd; }
+ friend bool
+ operator==(const chi_squared_distribution& __d1,
+ const chi_squared_distribution& __d2)
+ { return __d1.param() == __d2.param() && __d1._M_gd == __d2._M_gd; }
/**
* @brief Inserts a %chi_squared_distribution random number distribution
@@ -2727,6 +2902,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
std::chi_squared_distribution<_RealType1>& __x);
private:
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ typename std::gamma_distribution<result_type>::param_type&
+ __p);
+
param_type _M_param;
std::gamma_distribution<result_type> _M_gd;
@@ -2856,7 +3039,36 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
operator()(_UniformRandomNumberGenerator& __urng,
const param_type& __p);
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng)
+ { this->__generate(__f, __t, __urng, this->param()); }
+
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ { this->__generate_impl(__f, __t, __urng, __p); }
+
+ template<typename _UniformRandomNumberGenerator>
+ void
+ __generate(result_type* __f, result_type* __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ { this->__generate_impl(__f, __t, __urng, __p); }
+
private:
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p);
+
param_type _M_param;
};
@@ -3038,18 +3250,45 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
/ (_M_gd_y(__urng, param_type(__p.n() / 2)) * m()));
}
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng)
+ { this->__generate_impl(__f, __t, __urng); }
+
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ { this->__generate_impl(__f, __t, __urng, __p); }
+
+ template<typename _UniformRandomNumberGenerator>
+ void
+ __generate(result_type* __f, result_type* __t,
+ _UniformRandomNumberGenerator& __urng)
+ { this->__generate_impl(__f, __t, __urng); }
+
+ template<typename _UniformRandomNumberGenerator>
+ void
+ __generate(result_type* __f, result_type* __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ { this->__generate_impl(__f, __t, __urng, __p); }
+
/**
* @brief Return true if two Fisher f distributions have
* the same parameters and the sequences that would
* be generated are equal.
*/
- template<typename _RealType1>
- friend bool
- operator==(const std::fisher_f_distribution<_RealType1>& __d1,
- const std::fisher_f_distribution<_RealType1>& __d2)
- { return (__d1.param() == __d2.param()
- && __d1._M_gd_x == __d2._M_gd_x
- && __d1._M_gd_y == __d2._M_gd_y); }
+ friend bool
+ operator==(const fisher_f_distribution& __d1,
+ const fisher_f_distribution& __d2)
+ { return (__d1.param() == __d2.param()
+ && __d1._M_gd_x == __d2._M_gd_x
+ && __d1._M_gd_y == __d2._M_gd_y); }
/**
* @brief Inserts a %fisher_f_distribution random number distribution
@@ -3082,6 +3321,19 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
std::fisher_f_distribution<_RealType1>& __x);
private:
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng);
+
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p);
+
param_type _M_param;
std::gamma_distribution<result_type> _M_gd_x, _M_gd_y;
@@ -3212,17 +3464,44 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
return _M_nd(__urng) * std::sqrt(__p.n() / __g);
}
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng)
+ { this->__generate_impl(__f, __t, __urng); }
+
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ { this->__generate_impl(__f, __t, __urng, __p); }
+
+ template<typename _UniformRandomNumberGenerator>
+ void
+ __generate(result_type* __f, result_type* __t,
+ _UniformRandomNumberGenerator& __urng)
+ { this->__generate_impl(__f, __t, __urng); }
+
+ template<typename _UniformRandomNumberGenerator>
+ void
+ __generate(result_type* __f, result_type* __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ { this->__generate_impl(__f, __t, __urng, __p); }
+
/**
* @brief Return true if two Student t distributions have
* the same parameters and the sequences that would
* be generated are equal.
*/
- template<typename _RealType1>
- friend bool
- operator==(const std::student_t_distribution<_RealType1>& __d1,
- const std::student_t_distribution<_RealType1>& __d2)
- { return (__d1.param() == __d2.param()
- && __d1._M_nd == __d2._M_nd && __d1._M_gd == __d2._M_gd); }
+ friend bool
+ operator==(const student_t_distribution& __d1,
+ const student_t_distribution& __d2)
+ { return (__d1.param() == __d2.param()
+ && __d1._M_nd == __d2._M_nd && __d1._M_gd == __d2._M_gd); }
/**
* @brief Inserts a %student_t_distribution random number distribution
@@ -3255,6 +3534,18 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
std::student_t_distribution<_RealType1>& __x);
private:
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng);
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p);
+
param_type _M_param;
std::normal_distribution<result_type> _M_nd;
@@ -3396,7 +3687,35 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
return false;
}
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng)
+ { this->__generate(__f, __t, __urng, this->param()); }
+
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng, const param_type& __p)
+ { this->__generate_impl(__f, __t, __urng, __p); }
+
+ template<typename _UniformRandomNumberGenerator>
+ void
+ __generate(result_type* __f, result_type* __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ { this->__generate_impl(__f, __t, __urng, __p); }
+
private:
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p);
+
param_type _M_param;
};
@@ -3588,15 +3907,36 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
operator()(_UniformRandomNumberGenerator& __urng,
const param_type& __p);
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng)
+ { this->__generate(__f, __t, __urng, this->param()); }
+
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ { this->__generate_impl(__f, __t, __urng, __p); }
+
+ template<typename _UniformRandomNumberGenerator>
+ void
+ __generate(result_type* __f, result_type* __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ { this->__generate_impl(__f, __t, __urng, __p); }
+
/**
* @brief Return true if two binomial distributions have
* the same parameters and the sequences that would
* be generated are equal.
*/
- template<typename _IntType1>
friend bool
- operator==(const std::binomial_distribution<_IntType1>& __d1,
- const std::binomial_distribution<_IntType1>& __d2)
+ operator==(const binomial_distribution& __d1,
+ const binomial_distribution& __d2)
#ifdef _GLIBCXX_USE_C99_MATH_TR1
{ return __d1.param() == __d2.param() && __d1._M_nd == __d2._M_nd; }
#else
@@ -3636,6 +3976,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
std::binomial_distribution<_IntType1>& __x);
private:
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p);
+
template<typename _UniformRandomNumberGenerator>
result_type
_M_waiting(_UniformRandomNumberGenerator& __urng, _IntType __t);
@@ -3772,7 +4119,36 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
operator()(_UniformRandomNumberGenerator& __urng,
const param_type& __p);
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng)
+ { this->__generate(__f, __t, __urng, this->param()); }
+
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ { this->__generate_impl(__f, __t, __urng, __p); }
+
+ template<typename _UniformRandomNumberGenerator>
+ void
+ __generate(result_type* __f, result_type* __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ { this->__generate_impl(__f, __t, __urng, __p); }
+
private:
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p);
+
param_type _M_param;
};
@@ -3945,16 +4321,43 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
operator()(_UniformRandomNumberGenerator& __urng,
const param_type& __p);
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng)
+ { this->__generate_impl(__f, __t, __urng); }
+
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ { this->__generate_impl(__f, __t, __urng, __p); }
+
+ template<typename _UniformRandomNumberGenerator>
+ void
+ __generate(result_type* __f, result_type* __t,
+ _UniformRandomNumberGenerator& __urng)
+ { this->__generate_impl(__f, __t, __urng); }
+
+ template<typename _UniformRandomNumberGenerator>
+ void
+ __generate(result_type* __f, result_type* __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ { this->__generate_impl(__f, __t, __urng, __p); }
+
/**
* @brief Return true if two negative binomial distributions have
* the same parameters and the sequences that would be
* generated are equal.
*/
- template<typename _IntType1>
- friend bool
- operator==(const std::negative_binomial_distribution<_IntType1>& __d1,
- const std::negative_binomial_distribution<_IntType1>& __d2)
- { return __d1.param() == __d2.param() && __d1._M_gd == __d2._M_gd; }
+ friend bool
+ operator==(const negative_binomial_distribution& __d1,
+ const negative_binomial_distribution& __d2)
+ { return __d1.param() == __d2.param() && __d1._M_gd == __d2._M_gd; }
/**
* @brief Inserts a %negative_binomial_distribution random
@@ -3988,6 +4391,18 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
std::negative_binomial_distribution<_IntType1>& __x);
private:
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng);
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p);
+
param_type _M_param;
std::gamma_distribution<double> _M_gd;
@@ -4129,19 +4544,40 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
operator()(_UniformRandomNumberGenerator& __urng,
const param_type& __p);
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng)
+ { this->__generate(__f, __t, __urng, this->param()); }
+
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ { this->__generate_impl(__f, __t, __urng, __p); }
+
+ template<typename _UniformRandomNumberGenerator>
+ void
+ __generate(result_type* __f, result_type* __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ { this->__generate_impl(__f, __t, __urng, __p); }
+
/**
* @brief Return true if two Poisson distributions have the same
* parameters and the sequences that would be generated
* are equal.
*/
- template<typename _IntType1>
- friend bool
- operator==(const std::poisson_distribution<_IntType1>& __d1,
- const std::poisson_distribution<_IntType1>& __d2)
+ friend bool
+ operator==(const poisson_distribution& __d1,
+ const poisson_distribution& __d2)
#ifdef _GLIBCXX_USE_C99_MATH_TR1
- { return __d1.param() == __d2.param() && __d1._M_nd == __d2._M_nd; }
+ { return __d1.param() == __d2.param() && __d1._M_nd == __d2._M_nd; }
#else
- { return __d1.param() == __d2.param(); }
+ { return __d1.param() == __d2.param(); }
#endif
/**
@@ -4175,6 +4611,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
std::poisson_distribution<_IntType1>& __x);
private:
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p);
+
param_type _M_param;
// NB: Unused when _GLIBCXX_USE_C99_MATH_TR1 is undefined.
@@ -4316,7 +4759,36 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
return -std::log(__aurng()) / __p.lambda();
}
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng)
+ { this->__generate(__f, __t, __urng, this->param()); }
+
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ { this->__generate_impl(__f, __t, __urng, __p); }
+
+ template<typename _UniformRandomNumberGenerator>
+ void
+ __generate(result_type* __f, result_type* __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ { this->__generate_impl(__f, __t, __urng, __p); }
+
private:
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p);
+
param_type _M_param;
};
@@ -4491,7 +4963,36 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
operator()(_UniformRandomNumberGenerator& __urng,
const param_type& __p);
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng)
+ { this->__generate(__f, __t, __urng, this->param()); }
+
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ { this->__generate_impl(__f, __t, __urng, __p); }
+
+ template<typename _UniformRandomNumberGenerator>
+ void
+ __generate(result_type* __f, result_type* __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ { this->__generate_impl(__f, __t, __urng, __p); }
+
private:
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p);
+
param_type _M_param;
};
@@ -4666,7 +5167,36 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
operator()(_UniformRandomNumberGenerator& __urng,
const param_type& __p);
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng)
+ { this->__generate(__f, __t, __urng, this->param()); }
+
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ { this->__generate_impl(__f, __t, __urng, __p); }
+
+ template<typename _UniformRandomNumberGenerator>
+ void
+ __generate(result_type* __f, result_type* __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ { this->__generate_impl(__f, __t, __urng, __p); }
+
private:
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p);
+
param_type _M_param;
};
@@ -4867,6 +5397,28 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
operator()(_UniformRandomNumberGenerator& __urng,
const param_type& __p);
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng)
+ { this->__generate(__f, __t, __urng, this->param()); }
+
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ { this->__generate_impl(__f, __t, __urng, __p); }
+
+ template<typename _UniformRandomNumberGenerator>
+ void
+ __generate(result_type* __f, result_type* __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ { this->__generate_impl(__f, __t, __urng, __p); }
+
/**
* @brief Inserts a %discrete_distribution random number distribution
* @p __x into the output stream @p __os.
@@ -4899,6 +5451,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
std::discrete_distribution<_IntType1>& __x);
private:
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p);
+
param_type _M_param;
};
@@ -5105,6 +5664,28 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
operator()(_UniformRandomNumberGenerator& __urng,
const param_type& __p);
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng)
+ { this->__generate(__f, __t, __urng, this->param()); }
+
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ { this->__generate_impl(__f, __t, __urng, __p); }
+
+ template<typename _UniformRandomNumberGenerator>
+ void
+ __generate(result_type* __f, result_type* __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ { this->__generate_impl(__f, __t, __urng, __p); }
+
/**
* @brief Inserts a %piecewise_constan_distribution random
* number distribution @p __x into the output stream @p __os.
@@ -5138,6 +5719,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
std::piecewise_constant_distribution<_RealType1>& __x);
private:
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p);
+
param_type _M_param;
};
@@ -5347,6 +5935,28 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
operator()(_UniformRandomNumberGenerator& __urng,
const param_type& __p);
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng)
+ { this->__generate(__f, __t, __urng, this->param()); }
+
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ { this->__generate_impl(__f, __t, __urng, __p); }
+
+ template<typename _UniformRandomNumberGenerator>
+ void
+ __generate(result_type* __f, result_type* __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ { this->__generate_impl(__f, __t, __urng, __p); }
+
/**
* @brief Inserts a %piecewise_linear_distribution random number
* distribution @p __x into the output stream @p __os.
@@ -5380,6 +5990,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
std::piecewise_linear_distribution<_RealType1>& __x);
private:
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p);
+
param_type _M_param;
};
diff --git a/libstdc++-v3/include/bits/random.tcc b/libstdc++-v3/include/bits/random.tcc
index a3924bea681..9ae5e1283ba 100644
--- a/libstdc++-v3/include/bits/random.tcc
+++ b/libstdc++-v3/include/bits/random.tcc
@@ -89,6 +89,12 @@ namespace std _GLIBCXX_VISIBILITY(default)
return __result;
}
+ template<typename _Tp>
+ bool _Power_of_2(_Tp __x)
+ {
+ return ((__x - 1) & __x) == 0;
+ };
+
_GLIBCXX_END_NAMESPACE_VERSION
} // namespace __detail
@@ -392,6 +398,60 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_UIntType __a, size_t __u, _UIntType __d, size_t __s,
_UIntType __b, size_t __t, _UIntType __c, size_t __l,
_UIntType __f>
+ void
+ mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
+ __s, __b, __t, __c, __l, __f>::
+ _M_gen_rand(void)
+ {
+ const _UIntType __upper_mask = (~_UIntType()) << __r;
+ const _UIntType __lower_mask = ~__upper_mask;
+
+ for (size_t __k = 0; __k < (__n - __m); ++__k)
+ {
+ _UIntType __y = ((_M_x[__k] & __upper_mask)
+ | (_M_x[__k + 1] & __lower_mask));
+ _M_x[__k] = (_M_x[__k + __m] ^ (__y >> 1)
+ ^ ((__y & 0x01) ? __a : 0));
+ }
+
+ for (size_t __k = (__n - __m); __k < (__n - 1); ++__k)
+ {
+ _UIntType __y = ((_M_x[__k] & __upper_mask)
+ | (_M_x[__k + 1] & __lower_mask));
+ _M_x[__k] = (_M_x[__k + (__m - __n)] ^ (__y >> 1)
+ ^ ((__y & 0x01) ? __a : 0));
+ }
+
+ _UIntType __y = ((_M_x[__n - 1] & __upper_mask)
+ | (_M_x[0] & __lower_mask));
+ _M_x[__n - 1] = (_M_x[__m - 1] ^ (__y >> 1)
+ ^ ((__y & 0x01) ? __a : 0));
+ _M_p = 0;
+ }
+
+ template<typename _UIntType, size_t __w,
+ size_t __n, size_t __m, size_t __r,
+ _UIntType __a, size_t __u, _UIntType __d, size_t __s,
+ _UIntType __b, size_t __t, _UIntType __c, size_t __l,
+ _UIntType __f>
+ void
+ mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
+ __s, __b, __t, __c, __l, __f>::
+ discard(unsigned long long __z)
+ {
+ while (__z > state_size - _M_p)
+ {
+ __z -= state_size - _M_p;
+ _M_gen_rand();
+ }
+ _M_p += __z;
+ }
+
+ template<typename _UIntType, size_t __w,
+ size_t __n, size_t __m, size_t __r,
+ _UIntType __a, size_t __u, _UIntType __d, size_t __s,
+ _UIntType __b, size_t __t, _UIntType __c, size_t __l,
+ _UIntType __f>
typename
mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d,
__s, __b, __t, __c, __l, __f>::result_type
@@ -401,32 +461,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{
// Reload the vector - cost is O(n) amortized over n calls.
if (_M_p >= state_size)
- {
- const _UIntType __upper_mask = (~_UIntType()) << __r;
- const _UIntType __lower_mask = ~__upper_mask;
-
- for (size_t __k = 0; __k < (__n - __m); ++__k)
- {
- _UIntType __y = ((_M_x[__k] & __upper_mask)
- | (_M_x[__k + 1] & __lower_mask));
- _M_x[__k] = (_M_x[__k + __m] ^ (__y >> 1)
- ^ ((__y & 0x01) ? __a : 0));
- }
-
- for (size_t __k = (__n - __m); __k < (__n - 1); ++__k)
- {
- _UIntType __y = ((_M_x[__k] & __upper_mask)
- | (_M_x[__k + 1] & __lower_mask));
- _M_x[__k] = (_M_x[__k + (__m - __n)] ^ (__y >> 1)
- ^ ((__y & 0x01) ? __a : 0));
- }
-
- _UIntType __y = ((_M_x[__n - 1] & __upper_mask)
- | (_M_x[0] & __lower_mask));
- _M_x[__n - 1] = (_M_x[__m - 1] ^ (__y >> 1)
- ^ ((__y & 0x01) ? __a : 0));
- _M_p = 0;
- }
+ _M_gen_rand();
// Calculate o(x(i)).
result_type __z = _M_x[_M_p++];
@@ -907,6 +942,93 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
return __ret + __param.a();
}
+
+ template<typename _IntType>
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ uniform_int_distribution<_IntType>::
+ __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __param)
+ {
+ __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
+ typedef typename _UniformRandomNumberGenerator::result_type
+ _Gresult_type;
+ typedef typename std::make_unsigned<result_type>::type __utype;
+ typedef typename std::common_type<_Gresult_type, __utype>::type
+ __uctype;
+
+ const __uctype __urngmin = __urng.min();
+ const __uctype __urngmax = __urng.max();
+ const __uctype __urngrange = __urngmax - __urngmin;
+ const __uctype __urange
+ = __uctype(__param.b()) - __uctype(__param.a());
+
+ __uctype __ret;
+
+ if (__urngrange > __urange)
+ {
+ if (__detail::_Power_of_2(__urngrange + 1)
+ && __detail::_Power_of_2(__urange + 1))
+ {
+ while (__f != __t)
+ {
+ __ret = __uctype(__urng()) - __urngmin;
+ *__f++ = (__ret & __urange) + __param.a();
+ }
+ }
+ else
+ {
+ // downscaling
+ const __uctype __uerange = __urange + 1; // __urange can be zero
+ const __uctype __scaling = __urngrange / __uerange;
+ const __uctype __past = __uerange * __scaling;
+ while (__f != __t)
+ {
+ do
+ __ret = __uctype(__urng()) - __urngmin;
+ while (__ret >= __past);
+ *__f++ = __ret / __scaling + __param.a();
+ }
+ }
+ }
+ else if (__urngrange < __urange)
+ {
+ // upscaling
+ /*
+ Note that every value in [0, urange]
+ can be written uniquely as
+
+ (urngrange + 1) * high + low
+
+ where
+
+ high in [0, urange / (urngrange + 1)]
+
+ and
+
+ low in [0, urngrange].
+ */
+ __uctype __tmp; // wraparound control
+ while (__f != __t)
+ {
+ do
+ {
+ const __uctype __uerngrange = __urngrange + 1;
+ __tmp = (__uerngrange * operator()
+ (__urng, param_type(0, __urange / __uerngrange)));
+ __ret = __tmp + (__uctype(__urng()) - __urngmin);
+ }
+ while (__ret > __urange || __ret < __tmp);
+ *__f++ = __ret;
+ }
+ }
+ else
+ while (__f != __t)
+ *__f++ = __uctype(__urng()) - __urngmin + __param.a();
+ }
+
template<typename _IntType, typename _CharT, typename _Traits>
std::basic_ostream<_CharT, _Traits>&
operator<<(std::basic_ostream<_CharT, _Traits>& __os,
@@ -949,6 +1071,23 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
}
+ template<typename _RealType>
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ uniform_real_distribution<_RealType>::
+ __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ {
+ __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
+ __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
+ __aurng(__urng);
+ auto __range = __p.b() - __p.a();
+ while (__f != __t)
+ *__f++ = __aurng() * __range + __p.a();
+ }
+
template<typename _RealType, typename _CharT, typename _Traits>
std::basic_ostream<_CharT, _Traits>&
operator<<(std::basic_ostream<_CharT, _Traits>& __os,
@@ -994,6 +1133,23 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
}
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ std::bernoulli_distribution::
+ __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ {
+ __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
+ __detail::_Adaptor<_UniformRandomNumberGenerator, double>
+ __aurng(__urng);
+ auto __limit = __p.p() * (__aurng.max() - __aurng.min());
+
+ while (__f != __t)
+ *__f++ = (__aurng() - __aurng.min()) < __limit;
+ }
+
template<typename _CharT, typename _Traits>
std::basic_ostream<_CharT, _Traits>&
operator<<(std::basic_ostream<_CharT, _Traits>& __os,
@@ -1043,6 +1199,37 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
return result_type(__cand + __naf);
}
+ template<typename _IntType>
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ geometric_distribution<_IntType>::
+ __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __param)
+ {
+ __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
+ // About the epsilon thing see this thread:
+ // http://gcc.gnu.org/ml/gcc-patches/2006-10/msg00971.html
+ const double __naf =
+ (1 - std::numeric_limits<double>::epsilon()) / 2;
+ // The largest _RealType convertible to _IntType.
+ const double __thr =
+ std::numeric_limits<_IntType>::max() + __naf;
+ __detail::_Adaptor<_UniformRandomNumberGenerator, double>
+ __aurng(__urng);
+
+ while (__f != __t)
+ {
+ double __cand;
+ do
+ __cand = std::floor(std::log(__aurng()) / __param._M_log_1_p);
+ while (__cand >= __thr);
+
+ *__f++ = __cand + __naf;
+ }
+ }
+
template<typename _IntType,
typename _CharT, typename _Traits>
std::basic_ostream<_CharT, _Traits>&
@@ -1118,6 +1305,47 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
return __poisson(__urng);
}
+ template<typename _IntType>
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ negative_binomial_distribution<_IntType>::
+ __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng)
+ {
+ __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
+ while (__f != __t)
+ {
+ const double __y = _M_gd(__urng);
+
+ // XXX Is the constructor too slow?
+ std::poisson_distribution<result_type> __poisson(__y);
+ *__f++ = __poisson(__urng);
+ }
+ }
+
+ template<typename _IntType>
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ negative_binomial_distribution<_IntType>::
+ __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ {
+ __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
+ typename std::gamma_distribution<result_type>::param_type
+ __p2(__p.k(), (1.0 - __p.p()) / __p.p());
+
+ while (__f != __t)
+ {
+ const double __y = _M_gd(__urng, __p2);
+
+ std::poisson_distribution<result_type> __poisson(__y);
+ *__f++ = __poisson(__urng);
+ }
+ }
+
template<typename _IntType, typename _CharT, typename _Traits>
std::basic_ostream<_CharT, _Traits>&
operator<<(std::basic_ostream<_CharT, _Traits>& __os,
@@ -1307,6 +1535,21 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
}
}
+ template<typename _IntType>
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ poisson_distribution<_IntType>::
+ __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __param)
+ {
+ __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
+ // We could duplicate everything from operator()...
+ while (__f != __t)
+ *__f++ = this->operator()(__urng, __param);
+ }
+
template<typename _IntType,
typename _CharT, typename _Traits>
std::basic_ostream<_CharT, _Traits>&
@@ -1555,6 +1798,21 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
return __ret;
}
+ template<typename _IntType>
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ binomial_distribution<_IntType>::
+ __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __param)
+ {
+ __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
+ // We could duplicate everything from operator()...
+ while (__f != __t)
+ *__f++ = this->operator()(__urng, __param);
+ }
+
template<typename _IntType,
typename _CharT, typename _Traits>
std::basic_ostream<_CharT, _Traits>&
@@ -1604,6 +1862,22 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
}
+ template<typename _RealType>
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ std::exponential_distribution<_RealType>::
+ __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ {
+ __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
+ __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
+ __aurng(__urng);
+ while (__f != __t)
+ *__f++ = -std::log(__aurng()) / __p.lambda();
+ }
+
template<typename _RealType, typename _CharT, typename _Traits>
std::basic_ostream<_CharT, _Traits>&
operator<<(std::basic_ostream<_CharT, _Traits>& __os,
@@ -1692,6 +1966,66 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
}
template<typename _RealType>
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ normal_distribution<_RealType>::
+ __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __param)
+ {
+ __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
+
+ if (__f == __t)
+ return;
+
+ if (_M_saved_available)
+ {
+ _M_saved_available = false;
+ *__f++ = _M_saved * __param.stddev() + __param.mean();
+
+ if (__f == __t)
+ return;
+ }
+
+ __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
+ __aurng(__urng);
+
+ while (__f + 1 < __t)
+ {
+ result_type __x, __y, __r2;
+ do
+ {
+ __x = result_type(2.0) * __aurng() - 1.0;
+ __y = result_type(2.0) * __aurng() - 1.0;
+ __r2 = __x * __x + __y * __y;
+ }
+ while (__r2 > 1.0 || __r2 == 0.0);
+
+ const result_type __mult = std::sqrt(-2 * std::log(__r2) / __r2);
+ *__f++ = __y * __mult * __param.stddev() + __param.mean();
+ *__f++ = __x * __mult * __param.stddev() + __param.mean();
+ }
+
+ if (__f != __t)
+ {
+ result_type __x, __y, __r2;
+ do
+ {
+ __x = result_type(2.0) * __aurng() - 1.0;
+ __y = result_type(2.0) * __aurng() - 1.0;
+ __r2 = __x * __x + __y * __y;
+ }
+ while (__r2 > 1.0 || __r2 == 0.0);
+
+ const result_type __mult = std::sqrt(-2 * std::log(__r2) / __r2);
+ _M_saved = __x * __mult;
+ _M_saved_available = true;
+ *__f = __y * __mult * __param.stddev() + __param.mean();
+ }
+ }
+
+ template<typename _RealType>
bool
operator==(const std::normal_distribution<_RealType>& __d1,
const std::normal_distribution<_RealType>& __d2)
@@ -1762,6 +2096,20 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
}
+ template<typename _RealType>
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ lognormal_distribution<_RealType>::
+ __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ {
+ __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
+ while (__f != __t)
+ *__f++ = std::exp(__p.s() * _M_nd(__urng) + __p.m());
+ }
+
template<typename _RealType, typename _CharT, typename _Traits>
std::basic_ostream<_CharT, _Traits>&
operator<<(std::basic_ostream<_CharT, _Traits>& __os,
@@ -1808,6 +2156,21 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
}
+ template<typename _RealType>
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ std::chi_squared_distribution<_RealType>::
+ __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ typename std::gamma_distribution<result_type>::param_type&
+ __p)
+ {
+ __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
+ while (__f != __t)
+ *__f++ = 2 * _M_gd(__urng, __p);
+ }
+
template<typename _RealType, typename _CharT, typename _Traits>
std::basic_ostream<_CharT, _Traits>&
operator<<(std::basic_ostream<_CharT, _Traits>& __os,
@@ -1871,6 +2234,30 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
return __p.a() + __p.b() * std::tan(__pi * __u);
}
+ template<typename _RealType>
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ cauchy_distribution<_RealType>::
+ __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ {
+ __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
+ const _RealType __pi = 3.1415926535897932384626433832795029L;
+ __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
+ __aurng(__urng);
+ while (__f != __t)
+ {
+ _RealType __u;
+ do
+ __u = __aurng();
+ while (__u == 0.5);
+
+ *__f++ = __p.a() + __p.b() * std::tan(__pi * __u);
+ }
+ }
+
template<typename _RealType, typename _CharT, typename _Traits>
std::basic_ostream<_CharT, _Traits>&
operator<<(std::basic_ostream<_CharT, _Traits>& __os,
@@ -1916,6 +2303,38 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
}
+ template<typename _RealType>
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ std::fisher_f_distribution<_RealType>::
+ __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng)
+ {
+ __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
+ while (__f != __t)
+ *__f++ = ((_M_gd_x(__urng) * n()) / (_M_gd_y(__urng) * m()));
+ }
+
+ template<typename _RealType>
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ std::fisher_f_distribution<_RealType>::
+ __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ {
+ __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
+ typedef typename std::gamma_distribution<result_type>::param_type
+ param_type;
+ param_type __p1(__p.m() / 2);
+ param_type __p2(__p.n() / 2);
+ while (__f != __t)
+ *__f++ = ((_M_gd_x(__urng, __p1) * n())
+ / (_M_gd_y(__urng, __p2) * m()));
+ }
+
template<typename _RealType, typename _CharT, typename _Traits>
std::basic_ostream<_CharT, _Traits>&
operator<<(std::basic_ostream<_CharT, _Traits>& __os,
@@ -1962,6 +2381,35 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
}
+ template<typename _RealType>
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ std::student_t_distribution<_RealType>::
+ __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng)
+ {
+ __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
+ while (__f != __t)
+ *__f++ = _M_nd(__urng) * std::sqrt(n() / _M_gd(__urng));
+ }
+
+ template<typename _RealType>
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ std::student_t_distribution<_RealType>::
+ __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ {
+ __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
+ typename std::gamma_distribution<result_type>::param_type
+ __p2(__p.n() / 2, 2);
+ while (__f != __t)
+ *__f++ = _M_nd(__urng) * std::sqrt(__p.n() / _M_gd(__urng, __p2));
+ }
+
template<typename _RealType, typename _CharT, typename _Traits>
std::basic_ostream<_CharT, _Traits>&
operator<<(std::basic_ostream<_CharT, _Traits>& __os,
@@ -2065,6 +2513,72 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
}
}
+ template<typename _RealType>
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ gamma_distribution<_RealType>::
+ __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __param)
+ {
+ __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
+ __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
+ __aurng(__urng);
+
+ result_type __u, __v, __n;
+ const result_type __a1 = (__param._M_malpha
+ - _RealType(1.0) / _RealType(3.0));
+
+ if (__param.alpha() == __param._M_malpha)
+ while (__f != __t)
+ {
+ do
+ {
+ do
+ {
+ __n = _M_nd(__urng);
+ __v = result_type(1.0) + __param._M_a2 * __n;
+ }
+ while (__v <= 0.0);
+
+ __v = __v * __v * __v;
+ __u = __aurng();
+ }
+ while (__u > result_type(1.0) - 0.331 * __n * __n * __n * __n
+ && (std::log(__u) > (0.5 * __n * __n + __a1
+ * (1.0 - __v + std::log(__v)))));
+
+ *__f++ = __a1 * __v * __param.beta();
+ }
+ else
+ while (__f != __t)
+ {
+ do
+ {
+ do
+ {
+ __n = _M_nd(__urng);
+ __v = result_type(1.0) + __param._M_a2 * __n;
+ }
+ while (__v <= 0.0);
+
+ __v = __v * __v * __v;
+ __u = __aurng();
+ }
+ while (__u > result_type(1.0) - 0.331 * __n * __n * __n * __n
+ && (std::log(__u) > (0.5 * __n * __n + __a1
+ * (1.0 - __v + std::log(__v)))));
+
+ do
+ __u = __aurng();
+ while (__u == 0.0);
+
+ *__f++ = (std::pow(__u, result_type(1.0) / __param.alpha())
+ * __a1 * __v * __param.beta());
+ }
+ }
+
template<typename _RealType, typename _CharT, typename _Traits>
std::basic_ostream<_CharT, _Traits>&
operator<<(std::basic_ostream<_CharT, _Traits>& __os,
@@ -2124,6 +2638,24 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
result_type(1) / __p.a());
}
+ template<typename _RealType>
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ weibull_distribution<_RealType>::
+ __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ {
+ __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
+ __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
+ __aurng(__urng);
+ auto inv_a = result_type(1) / __p.a();
+
+ while (__f != __t)
+ *__f++ = __p.b() * std::pow(-std::log(__aurng()), inv_a);
+ }
+
template<typename _RealType, typename _CharT, typename _Traits>
std::basic_ostream<_CharT, _Traits>&
operator<<(std::basic_ostream<_CharT, _Traits>& __os,
@@ -2181,6 +2713,23 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
return __p.a() - __p.b() * std::log(-std::log(__aurng()));
}
+ template<typename _RealType>
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ extreme_value_distribution<_RealType>::
+ __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __p)
+ {
+ __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
+ __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
+ __aurng(__urng);
+
+ while (__f != __t)
+ *__f++ = __p.a() - __p.b() * std::log(-std::log(__aurng()));
+ }
+
template<typename _RealType, typename _CharT, typename _Traits>
std::basic_ostream<_CharT, _Traits>&
operator<<(std::basic_ostream<_CharT, _Traits>& __os,
@@ -2286,6 +2835,37 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
return __pos - __param._M_cp.begin();
}
+ template<typename _IntType>
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ discrete_distribution<_IntType>::
+ __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __param)
+ {
+ __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
+
+ if (__param._M_cp.empty())
+ {
+ while (__f != __t)
+ *__f++ = result_type(0);
+ return;
+ }
+
+ __detail::_Adaptor<_UniformRandomNumberGenerator, double>
+ __aurng(__urng);
+
+ while (__f != __t)
+ {
+ const double __p = __aurng();
+ auto __pos = std::lower_bound(__param._M_cp.begin(),
+ __param._M_cp.end(), __p);
+
+ *__f++ = __pos - __param._M_cp.begin();
+ }
+ }
+
template<typename _IntType, typename _CharT, typename _Traits>
std::basic_ostream<_CharT, _Traits>&
operator<<(std::basic_ostream<_CharT, _Traits>& __os,
@@ -2461,6 +3041,41 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
return __param._M_int[__i] + (__p - __pref) / __param._M_den[__i];
}
+ template<typename _RealType>
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ piecewise_constant_distribution<_RealType>::
+ __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __param)
+ {
+ __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
+ __detail::_Adaptor<_UniformRandomNumberGenerator, double>
+ __aurng(__urng);
+
+ if (__param._M_cp.empty())
+ {
+ while (__f != __t)
+ *__f++ = __aurng();
+ return;
+ }
+
+ while (__f != __t)
+ {
+ const double __p = __aurng();
+
+ auto __pos = std::lower_bound(__param._M_cp.begin(),
+ __param._M_cp.end(), __p);
+ const size_t __i = __pos - __param._M_cp.begin();
+
+ const double __pref = __i > 0 ? __param._M_cp[__i - 1] : 0.0;
+
+ *__f++ = (__param._M_int[__i]
+ + (__p - __pref) / __param._M_den[__i]);
+ }
+ }
+
template<typename _RealType, typename _CharT, typename _Traits>
std::basic_ostream<_CharT, _Traits>&
operator<<(std::basic_ostream<_CharT, _Traits>& __os,
@@ -2663,6 +3278,21 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
return __x;
}
+ template<typename _RealType>
+ template<typename _ForwardIterator,
+ typename _UniformRandomNumberGenerator>
+ void
+ piecewise_linear_distribution<_RealType>::
+ __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
+ _UniformRandomNumberGenerator& __urng,
+ const param_type& __param)
+ {
+ __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
+ // We could duplicate everything from operator()...
+ while (__f != __t)
+ *__f++ = this->operator()(__urng, __param);
+ }
+
template<typename _RealType, typename _CharT, typename _Traits>
std::basic_ostream<_CharT, _Traits>&
operator<<(std::basic_ostream<_CharT, _Traits>& __os,
diff --git a/libstdc++-v3/include/bits/shared_ptr.h b/libstdc++-v3/include/bits/shared_ptr.h
index 070d2d1360b..784336505b2 100644
--- a/libstdc++-v3/include/bits/shared_ptr.h
+++ b/libstdc++-v3/include/bits/shared_ptr.h
@@ -1,6 +1,6 @@
// shared_ptr and weak_ptr implementation -*- C++ -*-
-// Copyright (C) 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
+// Copyright (C) 2007-2012 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
@@ -250,8 +250,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
#if _GLIBCXX_USE_DEPRECATED
template<typename _Tp1>
- shared_ptr(std::auto_ptr<_Tp1>&& __r)
- : __shared_ptr<_Tp>(std::move(__r)) { }
+ shared_ptr(std::auto_ptr<_Tp1>&& __r);
#endif
template<typename _Tp1, typename _Del>
@@ -322,7 +321,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
allocate_shared(const _Alloc& __a, _Args&&... __args);
};
- // 20.8.13.2.7 shared_ptr comparisons
+ // 20.7.2.2.7 shared_ptr comparisons
template<typename _Tp1, typename _Tp2>
inline bool
operator==(const shared_ptr<_Tp1>& __a,
@@ -426,13 +425,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
struct less<shared_ptr<_Tp>> : public _Sp_less<shared_ptr<_Tp>>
{ };
- // 20.8.13.2.9 shared_ptr specialized algorithms.
+ // 20.7.2.2.8 shared_ptr specialized algorithms.
template<typename _Tp>
inline void
swap(shared_ptr<_Tp>& __a, shared_ptr<_Tp>& __b) noexcept
{ __a.swap(__b); }
- // 20.8.13.2.10 shared_ptr casts.
+ // 20.7.2.2.9 shared_ptr casts.
template<typename _Tp, typename _Tp1>
inline shared_ptr<_Tp>
static_pointer_cast(const shared_ptr<_Tp1>& __r) noexcept
@@ -512,7 +511,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
}
};
- // 20.8.13.3.7 weak_ptr specialized algorithms.
+ // 20.7.2.3.6 weak_ptr specialized algorithms.
template<typename _Tp>
inline void
swap(weak_ptr<_Tp>& __a, weak_ptr<_Tp>& __b) noexcept
diff --git a/libstdc++-v3/include/bits/shared_ptr_base.h b/libstdc++-v3/include/bits/shared_ptr_base.h
index 39449f1b4bb..07ac000d90b 100644
--- a/libstdc++-v3/include/bits/shared_ptr_base.h
+++ b/libstdc++-v3/include/bits/shared_ptr_base.h
@@ -1,7 +1,6 @@
// shared_ptr and weak_ptr implementation details -*- C++ -*-
-// Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012
-// Free Software Foundation, Inc.
+// Copyright (C) 2007-2012 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
@@ -54,6 +53,10 @@ namespace std _GLIBCXX_VISIBILITY(default)
{
_GLIBCXX_BEGIN_NAMESPACE_VERSION
+#if _GLIBCXX_USE_DEPRECATED
+ template<typename> class auto_ptr;
+#endif
+
/**
* @brief Exception possibly thrown by @c shared_ptr.
* @ingroup exceptions
@@ -537,9 +540,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
// Special case for auto_ptr<_Tp> to provide the strong guarantee.
template<typename _Tp>
explicit
- __shared_count(std::auto_ptr<_Tp>&& __r)
- : _M_pi(new _Sp_counted_ptr<_Tp*, _Lp>(__r.get()))
- { __r.release(); }
+ __shared_count(std::auto_ptr<_Tp>&& __r);
#endif
// Special case for unique_ptr<_Tp,_Del> to provide the strong guarantee.
@@ -859,15 +860,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
#if _GLIBCXX_USE_DEPRECATED
// Postcondition: use_count() == 1 and __r.get() == 0
template<typename _Tp1>
- __shared_ptr(std::auto_ptr<_Tp1>&& __r)
- : _M_ptr(__r.get()), _M_refcount()
- {
- __glibcxx_function_requires(_ConvertibleConcept<_Tp1*, _Tp*>)
- static_assert( sizeof(_Tp1) > 0, "incomplete type" );
- _Tp1* __tmp = __r.get();
- _M_refcount = __shared_count<_Lp>(std::move(__r));
- __enable_shared_from_this_helper(_M_refcount, __tmp, __tmp);
- }
+ __shared_ptr(std::auto_ptr<_Tp1>&& __r);
#endif
/* TODO: use delegating constructor */
@@ -1063,7 +1056,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
};
- // 20.8.13.2.7 shared_ptr comparisons
+ // 20.7.2.2.7 shared_ptr comparisons
template<typename _Tp1, typename _Tp2, _Lock_policy _Lp>
inline bool
operator==(const __shared_ptr<_Tp1, _Lp>& __a,
@@ -1355,7 +1348,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
__weak_count<_Lp> _M_refcount; // Reference counter.
};
- // 20.8.13.3.7 weak_ptr specialized algorithms.
+ // 20.7.2.3.6 weak_ptr specialized algorithms.
template<typename _Tp, _Lock_policy _Lp>
inline void
swap(__weak_ptr<_Tp, _Lp>& __a, __weak_ptr<_Tp, _Lp>& __b) noexcept
diff --git a/libstdc++-v3/include/bits/stl_list.h b/libstdc++-v3/include/bits/stl_list.h
index b568cd701b0..5fdaec91d17 100644
--- a/libstdc++-v3/include/bits/stl_list.h
+++ b/libstdc++-v3/include/bits/stl_list.h
@@ -313,10 +313,6 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
{
__detail::_List_node_base _M_node;
-#ifdef __GXX_EXPERIMENTAL_CXX0X__
- size_t _M_size = 0;
-#endif
-
_List_impl()
: _Node_alloc_type(), _M_node()
{ }
@@ -336,23 +332,12 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
_List_node<_Tp>*
_M_get_node()
- {
- _List_node<_Tp>* __tmp = _M_impl._Node_alloc_type::allocate(1);
-#ifdef __GXX_EXPERIMENTAL_CXX0X__
- ++_M_impl._M_size;
-#endif
- return __tmp;
- }
+ { return _M_impl._Node_alloc_type::allocate(1); }
void
_M_put_node(_List_node<_Tp>* __p)
- {
- _M_impl._Node_alloc_type::deallocate(__p, 1);
-#ifdef __GXX_EXPERIMENTAL_CXX0X__
- --_M_impl._M_size;
-#endif
- }
-
+ { _M_impl._Node_alloc_type::deallocate(__p, 1); }
+
public:
typedef _Alloc allocator_type;
@@ -386,7 +371,6 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
{
_M_init();
__detail::_List_node_base::swap(_M_impl._M_node, __x._M_impl._M_node);
- std::swap(_M_impl._M_size, __x._M_impl._M_size);
}
#endif
@@ -888,13 +872,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
/** Returns the number of elements in the %list. */
size_type
size() const _GLIBCXX_NOEXCEPT
- {
-#ifdef __GXX_EXPERIMENTAL_CXX0X__
- return this->_M_impl._M_size;
-#else
- return std::distance(begin(), end());
-#endif
- }
+ { return std::distance(begin(), end()); }
/** Returns the size() of the largest possible %list. */
size_type
@@ -1234,9 +1212,6 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
{
__detail::_List_node_base::swap(this->_M_impl._M_node,
__x._M_impl._M_node);
-#ifdef __GXX_EXPERIMENTAL_CXX0X__
- std::swap(this->_M_impl._M_size, __x._M_impl._M_size);
-#endif
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 431. Swapping containers with unequal allocators.
@@ -1281,11 +1256,6 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
_M_check_equal_allocators(__x);
this->_M_transfer(__position, __x.begin(), __x.end());
-
-#ifdef __GXX_EXPERIMENTAL_CXX0X__
- this->_M_impl._M_size += __x.size();
- __x._M_impl._M_size = 0;
-#endif
}
}
@@ -1317,14 +1287,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
return;
if (this != &__x)
- {
- _M_check_equal_allocators(__x);
-
-#ifdef __GXX_EXPERIMENTAL_CXX0X__
- ++this->_M_impl._M_size;
- --__x._M_impl._M_size;
-#endif
- }
+ _M_check_equal_allocators(__x);
this->_M_transfer(__position, __i, __j);
}
@@ -1359,15 +1322,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
if (__first != __last)
{
if (this != &__x)
- {
- _M_check_equal_allocators(__x);
-
-#ifdef __GXX_EXPERIMENTAL_CXX0X__
- const size_type __size = std::distance(__first, __last);
- this->_M_impl._M_size += __size;
- __x._M_impl._M_size -= __size;
-#endif
- }
+ _M_check_equal_allocators(__x);
this->_M_transfer(__position, __first, __last);
}
@@ -1643,10 +1598,6 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
inline bool
operator==(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
{
-#ifdef __GXX_EXPERIMENTAL_CXX0X__
- return (__x.size() == __y.size()
- && std::equal(__x.begin(), __x.end(), __y.begin()));
-#else
typedef typename list<_Tp, _Alloc>::const_iterator const_iterator;
const_iterator __end1 = __x.end();
const_iterator __end2 = __y.end();
@@ -1659,7 +1610,6 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
++__i2;
}
return __i1 == __end1 && __i2 == __end2;
-#endif
}
/**
diff --git a/libstdc++-v3/include/bits/stl_map.h b/libstdc++-v3/include/bits/stl_map.h
index 881f938063d..cfd478a3b92 100644
--- a/libstdc++-v3/include/bits/stl_map.h
+++ b/libstdc++-v3/include/bits/stl_map.h
@@ -1,7 +1,7 @@
// Map implementation -*- C++ -*-
// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
-// 2011 Free Software Foundation, Inc.
+// 2011, 2012 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
@@ -530,8 +530,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
#ifdef __GXX_EXPERIMENTAL_CXX0X__
template<typename _Pair, typename = typename
- std::enable_if<std::is_convertible<_Pair,
- value_type>::value>::type>
+ std::enable_if<std::is_constructible<value_type,
+ _Pair&&>::value>::type>
std::pair<iterator, bool>
insert(_Pair&& __x)
{ return _M_t._M_insert_unique(std::forward<_Pair>(__x)); }
@@ -583,8 +583,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
#ifdef __GXX_EXPERIMENTAL_CXX0X__
template<typename _Pair, typename = typename
- std::enable_if<std::is_convertible<_Pair,
- value_type>::value>::type>
+ std::enable_if<std::is_constructible<value_type,
+ _Pair&&>::value>::type>
iterator
insert(const_iterator __position, _Pair&& __x)
{ return _M_t._M_insert_unique_(__position,
diff --git a/libstdc++-v3/include/bits/stl_multimap.h b/libstdc++-v3/include/bits/stl_multimap.h
index 6c92bcd198e..6fc47877454 100644
--- a/libstdc++-v3/include/bits/stl_multimap.h
+++ b/libstdc++-v3/include/bits/stl_multimap.h
@@ -1,7 +1,7 @@
// Multimap implementation -*- C++ -*-
// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
-// 2011 Free Software Foundation, Inc.
+// 2011, 2012 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
@@ -451,8 +451,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
#ifdef __GXX_EXPERIMENTAL_CXX0X__
template<typename _Pair, typename = typename
- std::enable_if<std::is_convertible<_Pair,
- value_type>::value>::type>
+ std::enable_if<std::is_constructible<value_type,
+ _Pair&&>::value>::type>
iterator
insert(_Pair&& __x)
{ return _M_t._M_insert_equal(std::forward<_Pair>(__x)); }
@@ -488,8 +488,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
#ifdef __GXX_EXPERIMENTAL_CXX0X__
template<typename _Pair, typename = typename
- std::enable_if<std::is_convertible<_Pair,
- value_type>::value>::type>
+ std::enable_if<std::is_constructible<value_type,
+ _Pair&&>::value>::type>
iterator
insert(const_iterator __position, _Pair&& __x)
{ return _M_t._M_insert_equal_(__position,
diff --git a/libstdc++-v3/include/bits/stl_pair.h b/libstdc++-v3/include/bits/stl_pair.h
index 45a1c61fea1..4ece92aac12 100644
--- a/libstdc++-v3/include/bits/stl_pair.h
+++ b/libstdc++-v3/include/bits/stl_pair.h
@@ -1,7 +1,7 @@
// Pair implementation -*- C++ -*-
// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
-// 2010, 2011
+// 2010, 2011, 2012
// Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
@@ -122,13 +122,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
: first(__p.first), second(__p.second) { }
constexpr pair(const pair&) = default;
-
- // XXX Defaulted?!? Breaks std::map!!!
- pair(pair&& __p)
- noexcept(__and_<is_nothrow_move_constructible<_T1>,
- is_nothrow_move_constructible<_T2>>::value)
- : first(std::forward<first_type>(__p.first)),
- second(std::forward<second_type>(__p.second)) { }
+ constexpr pair(pair&&) = default;
// DR 811.
template<class _U1, class = typename
diff --git a/libstdc++-v3/include/bits/unique_ptr.h b/libstdc++-v3/include/bits/unique_ptr.h
index 0a127996e52..37eae257232 100644
--- a/libstdc++-v3/include/bits/unique_ptr.h
+++ b/libstdc++-v3/include/bits/unique_ptr.h
@@ -1,6 +1,6 @@
// unique_ptr implementation -*- C++ -*-
-// Copyright (C) 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
+// Copyright (C) 2008-2012 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
@@ -45,6 +45,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* @{
*/
+#if _GLIBCXX_USE_DEPRECATED
+ template<typename> class auto_ptr;
+#endif
+
/// Primary template, default_delete.
template<typename _Tp>
struct default_delete
@@ -83,7 +87,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<typename _Up> void operator()(_Up*) const = delete;
};
- /// 20.7.12.2 unique_ptr for single objects.
+ /// 20.7.1.2 unique_ptr for single objects.
template <typename _Tp, typename _Dp = default_delete<_Tp> >
class unique_ptr
{
@@ -161,12 +165,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
std::enable_if<std::is_convertible<_Up*, _Tp*>::value
&& std::is_same<_Dp,
default_delete<_Tp>>::value>::type>
- unique_ptr(auto_ptr<_Up>&& __u) noexcept
- : _M_t(__u.release(), deleter_type()) { }
+ unique_ptr(auto_ptr<_Up>&& __u) noexcept;
#endif
// Destructor.
- ~unique_ptr() noexcept { reset(); }
+ ~unique_ptr() noexcept
+ {
+ auto& __ptr = std::get<0>(_M_t);
+ if (__ptr != nullptr)
+ get_deleter()(__ptr);
+ __ptr = pointer();
+ }
// Assignment.
unique_ptr&
@@ -257,7 +266,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
unique_ptr& operator=(const unique_ptr&) = delete;
};
- /// 20.7.12.3 unique_ptr for array objects with a runtime length
+ /// 20.7.1.3 unique_ptr for array objects with a runtime length
// [unique.ptr.runtime]
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// DR 740 - omit specialization for array objects with a compile time length
@@ -310,7 +319,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{ }
// Destructor.
- ~unique_ptr() { reset(); }
+ ~unique_ptr()
+ {
+ auto& __ptr = std::get<0>(_M_t);
+ if (__ptr != nullptr)
+ get_deleter()(__ptr);
+ __ptr = pointer();
+ }
// Assignment.
unique_ptr&
@@ -403,7 +418,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
unique_ptr& operator=(const unique_ptr&) = delete;
// Disable construction from convertible pointer types.
- // (N2315 - 20.6.5.3.1)
+ // (N2315 - 20.7.1.3.1)
template<typename _Up>
unique_ptr(_Up*, typename
std::conditional<std::is_reference<deleter_type>::value,