summaryrefslogtreecommitdiff
path: root/libstdc++-v3/include/bits
diff options
context:
space:
mode:
Diffstat (limited to 'libstdc++-v3/include/bits')
-rw-r--r--libstdc++-v3/include/bits/atomic_0.h5
-rw-r--r--libstdc++-v3/include/bits/atomic_2.h5
-rw-r--r--libstdc++-v3/include/bits/basic_string.h13
-rw-r--r--libstdc++-v3/include/bits/c++config6
-rw-r--r--libstdc++-v3/include/bits/random.h144
-rw-r--r--libstdc++-v3/include/bits/shared_ptr.h1366
-rw-r--r--libstdc++-v3/include/bits/shared_ptr_base.h1114
-rw-r--r--libstdc++-v3/include/bits/stl_algo.h158
-rw-r--r--libstdc++-v3/include/bits/stl_algobase.h6
-rw-r--r--libstdc++-v3/include/bits/stl_iterator.h63
-rw-r--r--libstdc++-v3/include/bits/stl_iterator_base_funcs.h8
-rw-r--r--libstdc++-v3/include/bits/stl_iterator_base_types.h12
-rw-r--r--libstdc++-v3/include/bits/stl_pair.h28
-rw-r--r--libstdc++-v3/include/bits/stl_tempbuf.h4
-rw-r--r--libstdc++-v3/include/bits/stream_iterator.h7
-rw-r--r--libstdc++-v3/include/bits/streambuf_iterator.h7
-rw-r--r--libstdc++-v3/include/bits/valarray_array.h31
17 files changed, 1570 insertions, 1407 deletions
diff --git a/libstdc++-v3/include/bits/atomic_0.h b/libstdc++-v3/include/bits/atomic_0.h
index a493ea66af9..0caffaf1e9f 100644
--- a/libstdc++-v3/include/bits/atomic_0.h
+++ b/libstdc++-v3/include/bits/atomic_0.h
@@ -82,14 +82,15 @@ namespace __atomic0
__r; })
/// atomic_flag
- struct atomic_flag : private __atomic_flag_base
+ struct atomic_flag : public __atomic_flag_base
{
atomic_flag() = default;
~atomic_flag() = default;
atomic_flag(const atomic_flag&) = delete;
atomic_flag& operator=(const atomic_flag&) = delete;
- atomic_flag(bool __i) { _M_i = __i; } // XXX deleted copy ctor != agg
+ // Conversion to ATOMIC_FLAG_INIT.
+ atomic_flag(bool __i): __atomic_flag_base({ __i }) { }
bool
test_and_set(memory_order __m = memory_order_seq_cst) volatile;
diff --git a/libstdc++-v3/include/bits/atomic_2.h b/libstdc++-v3/include/bits/atomic_2.h
index 8e8e7ff16f8..d39adb920a2 100644
--- a/libstdc++-v3/include/bits/atomic_2.h
+++ b/libstdc++-v3/include/bits/atomic_2.h
@@ -44,14 +44,15 @@
namespace __atomic2
{
/// atomic_flag
- struct atomic_flag : private __atomic_flag_base
+ struct atomic_flag : public __atomic_flag_base
{
atomic_flag() = default;
~atomic_flag() = default;
atomic_flag(const atomic_flag&) = delete;
atomic_flag& operator=(const atomic_flag&) = delete;
- atomic_flag(bool __i) { _M_i = __i; } // XXX deleted copy ctor != agg
+ // Conversion to ATOMIC_FLAG_INIT.
+ atomic_flag(bool __i): __atomic_flag_base({ __i }) { }
bool
test_and_set(memory_order __m = memory_order_seq_cst) volatile
diff --git a/libstdc++-v3/include/bits/basic_string.h b/libstdc++-v3/include/bits/basic_string.h
index bd54537cdc1..9d44dc4fdfc 100644
--- a/libstdc++-v3/include/bits/basic_string.h
+++ b/libstdc++-v3/include/bits/basic_string.h
@@ -540,7 +540,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
basic_string&
operator=(initializer_list<_CharT> __l)
{
- this->assign (__l.begin(), __l.end());
+ this->assign(__l.begin(), __l.size());
return *this;
}
#endif // __GXX_EXPERIMENTAL_CXX0X__
@@ -860,7 +860,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
*/
basic_string&
operator+=(initializer_list<_CharT> __l)
- { return this->append(__l.begin(), __l.end()); }
+ { return this->append(__l.begin(), __l.size()); }
#endif // __GXX_EXPERIMENTAL_CXX0X__
/**
@@ -926,7 +926,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
*/
basic_string&
append(initializer_list<_CharT> __l)
- { return this->append(__l.begin(), __l.end()); }
+ { return this->append(__l.begin(), __l.size()); }
#endif // __GXX_EXPERIMENTAL_CXX0X__
/**
@@ -1045,7 +1045,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
*/
basic_string&
assign(initializer_list<_CharT> __l)
- { return this->assign(__l.begin(), __l.end()); }
+ { return this->assign(__l.begin(), __l.size()); }
#endif // __GXX_EXPERIMENTAL_CXX0X__
/**
@@ -1089,7 +1089,10 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
*/
void
insert(iterator __p, initializer_list<_CharT> __l)
- { this->insert(__p, __l.begin(), __l.end()); }
+ {
+ _GLIBCXX_DEBUG_PEDASSERT(__p >= _M_ibegin() && __p <= _M_iend());
+ this->insert(__p - _M_ibegin(), __l.begin(), __l.size());
+ }
#endif // __GXX_EXPERIMENTAL_CXX0X__
/**
diff --git a/libstdc++-v3/include/bits/c++config b/libstdc++-v3/include/bits/c++config
index 724f373ebae..f4f1f8b901f 100644
--- a/libstdc++-v3/include/bits/c++config
+++ b/libstdc++-v3/include/bits/c++config
@@ -147,7 +147,6 @@
# define _GLIBCXX_STD __cxx1998
# define _GLIBCXX_BEGIN_NAMESPACE(X) namespace X _GLIBCXX_VISIBILITY_ATTR(default) {
# define _GLIBCXX_END_NAMESPACE }
-# define _GLIBCXX_EXTERN_TEMPLATE -1
# endif
// debug + parallel
@@ -172,7 +171,6 @@
# define _GLIBCXX_STD __cxx1998
# define _GLIBCXX_BEGIN_NAMESPACE(X) namespace X _GLIBCXX_VISIBILITY_ATTR(default) {
# define _GLIBCXX_END_NAMESPACE }
-# define _GLIBCXX_EXTERN_TEMPLATE -1
# endif
# if __NO_INLINE__ && !__GXX_WEAK__
@@ -287,6 +285,10 @@ namespace std
// library to avoid multiple weak definitions for required types that
// are already explicitly instantiated in the library binary. This
// substantially reduces the binary size of resulting executables.
+
+// Special case: _GLIBCXX_EXTERN_TEMPLATE == -1 disallows extern
+// templates only in basic_string, thus activating its debug-mode
+// checks even at -O0.
#ifndef _GLIBCXX_EXTERN_TEMPLATE
# define _GLIBCXX_EXTERN_TEMPLATE 1
#endif
diff --git a/libstdc++-v3/include/bits/random.h b/libstdc++-v3/include/bits/random.h
index 06aa6f87b91..ab661e9594c 100644
--- a/libstdc++-v3/include/bits/random.h
+++ b/libstdc++-v3/include/bits/random.h
@@ -32,7 +32,6 @@
namespace std
{
-
// [26.4] Random number generation
/**
@@ -154,10 +153,10 @@ namespace std
template<typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
class linear_congruential_engine
{
- __glibcxx_class_requires(_UIntType, _UnsignedIntegerConcept)
- static_assert(__m == 0 || (__a < __m && __c < __m),
- "template arguments out of bounds"
- " in linear_congruential_engine");
+ static_assert(std::is_unsigned<_UIntType>::value, "template argument "
+ "substituting _UIntType not an unsigned integral type");
+ static_assert(__m == 0u || (__a < __m && __c < __m),
+ "template argument substituting __m out of bounds");
public:
/** The type of the generated random value. */
@@ -341,35 +340,32 @@ namespace std
_UIntType __c, size_t __l, _UIntType __f>
class mersenne_twister_engine
{
- __glibcxx_class_requires(_UIntType, _UnsignedIntegerConcept)
-
- static_assert(__m >= 1U,
- "mersenne_twister_engine template arguments out of bounds");
- static_assert(__n >= __m,
- "mersenne_twister_engine template arguments out of bounds");
- static_assert(__w >= __r,
- "mersenne_twister_engine template arguments out of bounds");
- static_assert(__w >= __u,
- "mersenne_twister_engine template arguments out of bounds");
- static_assert(__w >= __s,
- "mersenne_twister_engine template arguments out of bounds");
- static_assert(__w >= __t,
- "mersenne_twister_engine template arguments out of bounds");
- static_assert(__w >= __l,
- "mersenne_twister_engine template arguments out of bounds");
- static_assert(__w <=
- static_cast<size_t>(std::numeric_limits<_UIntType>::digits),
- "mersenne_twister_engine template arguments out of bounds");
+ static_assert(std::is_unsigned<_UIntType>::value, "template argument "
+ "substituting _UIntType not an unsigned integral type");
+ static_assert(1u <= __m && __m <= __n,
+ "template argument substituting __m out of bounds");
+ static_assert(__r <= __w, "template argument substituting "
+ "__r out of bound");
+ static_assert(__u <= __w, "template argument substituting "
+ "__u out of bound");
+ static_assert(__s <= __w, "template argument substituting "
+ "__s out of bound");
+ static_assert(__t <= __w, "template argument substituting "
+ "__t out of bound");
+ static_assert(__l <= __w, "template argument substituting "
+ "__l out of bound");
+ static_assert(__w <= std::numeric_limits<_UIntType>::digits,
+ "template argument substituting __w out of bound");
static_assert(__a <= (__detail::_Shift<_UIntType, __w>::__value - 1),
- "mersenne_twister_engine template arguments out of bounds");
+ "template argument substituting __a out of bound");
static_assert(__b <= (__detail::_Shift<_UIntType, __w>::__value - 1),
- "mersenne_twister_engine template arguments out of bounds");
+ "template argument substituting __b out of bound");
static_assert(__c <= (__detail::_Shift<_UIntType, __w>::__value - 1),
- "mersenne_twister_engine template arguments out of bounds");
+ "template argument substituting __c out of bound");
static_assert(__d <= (__detail::_Shift<_UIntType, __w>::__value - 1),
- "mersenne_twister_engine template arguments out of bounds");
+ "template argument substituting __d out of bound");
static_assert(__f <= (__detail::_Shift<_UIntType, __w>::__value - 1),
- "mersenne_twister_engine template arguments out of bounds");
+ "template argument substituting __f out of bound");
public:
/** The type of the generated random value. */
@@ -538,13 +534,12 @@ namespace std
template<typename _UIntType, size_t __w, size_t __s, size_t __r>
class subtract_with_carry_engine
{
- __glibcxx_class_requires(_UIntType, _UnsignedIntegerConcept)
- static_assert(__s > 0U && __r > __s
- && __w > 0U
- && __w <= static_cast<size_t>
- (std::numeric_limits<_UIntType>::digits),
- "template arguments out of bounds"
- " in subtract_with_carry_engine");
+ static_assert(std::is_unsigned<_UIntType>::value, "template argument "
+ "substituting _UIntType not an unsigned integral type");
+ static_assert(0u < __s && __s < __r,
+ "template argument substituting __s out of bounds");
+ static_assert(0u < __w && __w <= std::numeric_limits<_UIntType>::digits,
+ "template argument substituting __w out of bounds");
public:
/** The type of the generated random value. */
@@ -702,9 +697,8 @@ namespace std
template<typename _RandomNumberEngine, size_t __p, size_t __r>
class discard_block_engine
{
- static_assert(__r >= 1U && __p >= __r,
- "template arguments out of bounds"
- " in discard_block_engine");
+ static_assert(1 <= __r && __r <= __p,
+ "template argument substituting __r out of bounds");
public:
/** The type of the generated random value. */
@@ -903,12 +897,10 @@ namespace std
template<typename _RandomNumberEngine, size_t __w, typename _UIntType>
class independent_bits_engine
{
- static_assert(__w > 0U
- && __w <=
- static_cast<size_t>
- (std::numeric_limits<_UIntType>::digits),
- "template arguments out of bounds "
- "in independent_bits_engine");
+ static_assert(std::is_unsigned<_UIntType>::value, "template argument "
+ "substituting _UIntType not an unsigned integral type");
+ static_assert(0u < __w && __w <= std::numeric_limits<_UIntType>::digits,
+ "template argument substituting __w out of bounds");
public:
/** The type of the generated random value. */
@@ -1102,9 +1094,8 @@ namespace std
template<typename _RandomNumberEngine, size_t __k>
class shuffle_order_engine
{
- static_assert(__k >= 1U,
- "template arguments out of bounds"
- " in shuffle_order_engine");
+ static_assert(1u <= __k, "template argument substituting "
+ "__k out of bound");
public:
/** The type of the generated random value. */
@@ -1480,7 +1471,8 @@ namespace std
template<typename _IntType = int>
class uniform_int_distribution
{
- __glibcxx_class_requires(_IntType, _IntegerConcept)
+ static_assert(std::is_integral<_IntType>::value,
+ "template argument not an integral type");
public:
/** The type of the range of the distribution. */
@@ -1633,6 +1625,9 @@ namespace std
template<typename _RealType = double>
class uniform_real_distribution
{
+ static_assert(std::is_floating_point<_RealType>::value,
+ "template argument not a floating point type");
+
public:
/** The type of the range of the distribution. */
typedef _RealType result_type;
@@ -1791,6 +1786,9 @@ namespace std
template<typename _RealType = double>
class normal_distribution
{
+ static_assert(std::is_floating_point<_RealType>::value,
+ "template argument not a floating point type");
+
public:
/** The type of the range of the distribution. */
typedef _RealType result_type;
@@ -1943,6 +1941,9 @@ namespace std
template<typename _RealType = double>
class lognormal_distribution
{
+ static_assert(std::is_floating_point<_RealType>::value,
+ "template argument not a floating point type");
+
public:
/** The type of the range of the distribution. */
typedef _RealType result_type;
@@ -2086,6 +2087,9 @@ namespace std
template<typename _RealType = double>
class gamma_distribution
{
+ static_assert(std::is_floating_point<_RealType>::value,
+ "template argument not a floating point type");
+
public:
/** The type of the range of the distribution. */
typedef _RealType result_type;
@@ -2243,6 +2247,9 @@ namespace std
template<typename _RealType = double>
class chi_squared_distribution
{
+ static_assert(std::is_floating_point<_RealType>::value,
+ "template argument not a floating point type");
+
public:
/** The type of the range of the distribution. */
typedef _RealType result_type;
@@ -2378,6 +2385,9 @@ namespace std
template<typename _RealType = double>
class cauchy_distribution
{
+ static_assert(std::is_floating_point<_RealType>::value,
+ "template argument not a floating point type");
+
public:
/** The type of the range of the distribution. */
typedef _RealType result_type;
@@ -2519,6 +2529,9 @@ namespace std
template<typename _RealType = double>
class fisher_f_distribution
{
+ static_assert(std::is_floating_point<_RealType>::value,
+ "template argument not a floating point type");
+
public:
/** The type of the range of the distribution. */
typedef _RealType result_type;
@@ -2670,6 +2683,9 @@ namespace std
template<typename _RealType = double>
class student_t_distribution
{
+ static_assert(std::is_floating_point<_RealType>::value,
+ "template argument not a floating point type");
+
public:
/** The type of the range of the distribution. */
typedef _RealType result_type;
@@ -2972,7 +2988,8 @@ namespace std
template<typename _IntType = int>
class binomial_distribution
{
- __glibcxx_class_requires(_IntType, _IntegerConcept)
+ static_assert(std::is_integral<_IntType>::value,
+ "template argument not an integral type");
public:
/** The type of the range of the distribution. */
@@ -3142,7 +3159,8 @@ namespace std
template<typename _IntType = int>
class geometric_distribution
{
- __glibcxx_class_requires(_IntType, _IntegerConcept)
+ static_assert(std::is_integral<_IntType>::value,
+ "template argument not an integral type");
public:
/** The type of the range of the distribution. */
@@ -3287,7 +3305,8 @@ namespace std
template<typename _IntType = int>
class negative_binomial_distribution
{
- __glibcxx_class_requires(_IntType, _IntegerConcept)
+ static_assert(std::is_integral<_IntType>::value,
+ "template argument not an integral type");
public:
/** The type of the range of the distribution. */
@@ -3439,7 +3458,8 @@ namespace std
template<typename _IntType = int>
class poisson_distribution
{
- __glibcxx_class_requires(_IntType, _IntegerConcept)
+ static_assert(std::is_integral<_IntType>::value,
+ "template argument not an integral type");
public:
/** The type of the range of the distribution. */
@@ -3594,6 +3614,9 @@ namespace std
template<typename _RealType = double>
class exponential_distribution
{
+ static_assert(std::is_floating_point<_RealType>::value,
+ "template argument not a floating point type");
+
public:
/** The type of the range of the distribution. */
typedef _RealType result_type;
@@ -3736,6 +3759,9 @@ namespace std
template<typename _RealType = double>
class weibull_distribution
{
+ static_assert(std::is_floating_point<_RealType>::value,
+ "template argument not a floating point type");
+
public:
/** The type of the range of the distribution. */
typedef _RealType result_type;
@@ -3879,6 +3905,9 @@ namespace std
template<typename _RealType = double>
class extreme_value_distribution
{
+ static_assert(std::is_floating_point<_RealType>::value,
+ "template argument not a floating point type");
+
public:
/** The type of the range of the distribution. */
typedef _RealType result_type;
@@ -4021,7 +4050,8 @@ namespace std
template<typename _IntType = int>
class discrete_distribution
{
- __glibcxx_class_requires(_IntType, _IntegerConcept)
+ static_assert(std::is_integral<_IntType>::value,
+ "template argument not an integral type");
public:
/** The type of the range of the distribution. */
@@ -4185,6 +4215,9 @@ namespace std
template<typename _RealType = double>
class piecewise_constant_distribution
{
+ static_assert(std::is_floating_point<_RealType>::value,
+ "template argument not a floating point type");
+
public:
/** The type of the range of the distribution. */
typedef _RealType result_type;
@@ -4363,6 +4396,9 @@ namespace std
template<typename _RealType = double>
class piecewise_linear_distribution
{
+ static_assert(std::is_floating_point<_RealType>::value,
+ "template argument not a floating point type");
+
public:
/** The type of the range of the distribution. */
typedef _RealType result_type;
diff --git a/libstdc++-v3/include/bits/shared_ptr.h b/libstdc++-v3/include/bits/shared_ptr.h
index 81bef585940..796df14c2c4 100644
--- a/libstdc++-v3/include/bits/shared_ptr.h
+++ b/libstdc++-v3/include/bits/shared_ptr.h
@@ -22,6 +22,8 @@
// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
// <http://www.gnu.org/licenses/>.
+// GCC Note: Based on files from version 1.32.0 of the Boost library.
+
// shared_count.hpp
// Copyright (c) 2001, 2002, 2003 Peter Dimov and Multi Media Ltd.
@@ -39,8 +41,6 @@
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
-// GCC Note: based on version 1.32.0 of the Boost library.
-
/** @file bits/shared_ptr.h
* This is an internal header file, included by other library headers.
* You should not attempt to use it directly.
@@ -53,9 +53,7 @@
# include <c++0x_warning.h>
#endif
-#if defined(_GLIBCXX_INCLUDE_AS_TR1)
-# error C++0x header cannot be included from TR1 header
-#endif
+#include <bits/shared_ptr_base.h>
_GLIBCXX_BEGIN_NAMESPACE(std)
@@ -64,563 +62,89 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
* @{
*/
- // counted ptr with no deleter or allocator support
- template<typename _Ptr, _Lock_policy _Lp>
- class _Sp_counted_ptr
- : public _Sp_counted_base<_Lp>
- {
- public:
- _Sp_counted_ptr(_Ptr __p)
- : _M_ptr(__p) { }
-
- virtual void
- _M_dispose() // nothrow
- { delete _M_ptr; }
-
- virtual void
- _M_destroy() // nothrow
- { delete this; }
-
- virtual void*
- _M_get_deleter(const std::type_info& __ti)
- { return 0; }
-
- _Sp_counted_ptr(const _Sp_counted_ptr&) = delete;
- _Sp_counted_ptr& operator=(const _Sp_counted_ptr&) = delete;
-
- protected:
- _Ptr _M_ptr; // copy constructor must not throw
- };
-
- // support for custom deleter and/or allocator
- template<typename _Ptr, typename _Deleter, typename _Alloc, _Lock_policy _Lp>
- class _Sp_counted_deleter
- : public _Sp_counted_ptr<_Ptr, _Lp>
- {
- typedef typename _Alloc::template
- rebind<_Sp_counted_deleter>::other _My_alloc_type;
-
- // Helper class that stores the Deleter and also acts as an allocator.
- // Used to dispose of the owned pointer and the internal refcount
- // Requires that copies of _Alloc can free each other's memory.
- struct _My_Deleter
- : public _My_alloc_type // copy constructor must not throw
- {
- _Deleter _M_del; // copy constructor must not throw
- _My_Deleter(_Deleter __d, const _Alloc& __a)
- : _My_alloc_type(__a), _M_del(__d) { }
- };
-
- protected:
- typedef _Sp_counted_ptr<_Ptr, _Lp> _Base_type;
-
- public:
- /**
- * @brief
- * @pre __d(__p) must not throw.
- */
- _Sp_counted_deleter(_Ptr __p, _Deleter __d)
- : _Base_type(__p), _M_del(__d, _Alloc()) { }
-
- /**
- * @brief
- * @pre __d(__p) must not throw.
- */
- _Sp_counted_deleter(_Ptr __p, _Deleter __d, const _Alloc& __a)
- : _Base_type(__p), _M_del(__d, __a) { }
-
- virtual void
- _M_dispose() // nothrow
- { _M_del._M_del(_Base_type::_M_ptr); }
-
- virtual void
- _M_destroy() // nothrow
- {
- _My_alloc_type __a(_M_del);
- this->~_Sp_counted_deleter();
- __a.deallocate(this, 1);
- }
-
- virtual void*
- _M_get_deleter(const std::type_info& __ti)
- { return __ti == typeid(_Deleter) ? &_M_del._M_del : 0; }
-
- protected:
- _My_Deleter _M_del; // copy constructor must not throw
- };
-
- // helpers for make_shared / allocate_shared
-
- template<typename _Tp>
- struct _Sp_destroy_inplace
- {
- void operator()(_Tp* __p) const { if (__p) __p->~_Tp(); }
- };
-
- struct _Sp_make_shared_tag { };
-
- template<typename _Tp, typename _Alloc, _Lock_policy _Lp>
- class _Sp_counted_ptr_inplace
- : public _Sp_counted_deleter<_Tp*, _Sp_destroy_inplace<_Tp>, _Alloc, _Lp>
- {
- typedef _Sp_counted_deleter<_Tp*, _Sp_destroy_inplace<_Tp>, _Alloc, _Lp>
- _Base_type;
-
- public:
- _Sp_counted_ptr_inplace(_Alloc __a)
- : _Base_type(static_cast<_Tp*>(0), _Sp_destroy_inplace<_Tp>(), __a)
- , _M_storage()
- {
- void* __p = &_M_storage;
- ::new (__p) _Tp(); // might throw
- _Base_type::_Base_type::_M_ptr = static_cast<_Tp*>(__p);
- }
-
- template<typename... _Args>
- _Sp_counted_ptr_inplace(_Alloc __a, _Args&&... __args)
- : _Base_type(static_cast<_Tp*>(0), _Sp_destroy_inplace<_Tp>(), __a)
- , _M_storage()
- {
- void* __p = &_M_storage;
- ::new (__p) _Tp(std::forward<_Args>(__args)...); // might throw
- _Base_type::_Base_type::_M_ptr = static_cast<_Tp*>(__p);
- }
-
- // override because the allocator needs to know the dynamic type
- virtual void
- _M_destroy() // nothrow
- {
- typedef typename _Alloc::template
- rebind<_Sp_counted_ptr_inplace>::other _My_alloc_type;
- _My_alloc_type __a(_Base_type::_M_del);
- this->~_Sp_counted_ptr_inplace();
- __a.deallocate(this, 1);
- }
-
- // sneaky trick so __shared_ptr can get the managed pointer
- virtual void*
- _M_get_deleter(const std::type_info& __ti)
- {
- return __ti == typeid(_Sp_make_shared_tag)
- ? static_cast<void*>(&_M_storage)
- : _Base_type::_M_get_deleter(__ti);
- }
-
- private:
- typename aligned_storage<sizeof(_Tp), alignment_of<_Tp>::value>::type
- _M_storage;
- };
-
- template<_Lock_policy _Lp = __default_lock_policy>
- class __weak_count;
-
- template<_Lock_policy _Lp = __default_lock_policy>
- class __shared_count
- {
- public:
- __shared_count()
- : _M_pi(0) // nothrow
- { }
-
- template<typename _Ptr>
- __shared_count(_Ptr __p) : _M_pi(0)
- {
- __try
- {
- _M_pi = new _Sp_counted_ptr<_Ptr, _Lp>(__p);
- }
- __catch(...)
- {
- delete __p;
- __throw_exception_again;
- }
- }
-
- template<typename _Ptr, typename _Deleter>
- __shared_count(_Ptr __p, _Deleter __d) : _M_pi(0)
- {
- // allocator's value_type doesn't matter, will rebind it anyway
- typedef std::allocator<int> _Alloc;
- typedef _Sp_counted_deleter<_Ptr, _Deleter, _Alloc, _Lp> _Sp_cd_type;
- typedef std::allocator<_Sp_cd_type> _Alloc2;
- _Alloc2 __a2;
- __try
- {
- _M_pi = __a2.allocate(1);
- ::new(static_cast<void*>(_M_pi)) _Sp_cd_type(__p, __d);
- }
- __catch(...)
- {
- __d(__p); // Call _Deleter on __p.
- if (_M_pi)
- __a2.deallocate(static_cast<_Sp_cd_type*>(_M_pi), 1);
- __throw_exception_again;
- }
- }
-
- template<typename _Ptr, typename _Deleter, typename _Alloc>
- __shared_count(_Ptr __p, _Deleter __d, _Alloc __a) : _M_pi(0)
- {
- typedef _Sp_counted_deleter<_Ptr, _Deleter, _Alloc, _Lp> _Sp_cd_type;
- typedef typename _Alloc::template rebind<_Sp_cd_type>::other _Alloc2;
- _Alloc2 __a2(__a);
- __try
- {
- _M_pi = __a2.allocate(1);
- ::new(static_cast<void*>(_M_pi)) _Sp_cd_type(__p, __d, __a);
- }
- __catch(...)
- {
- __d(__p); // Call _Deleter on __p.
- if (_M_pi)
- __a2.deallocate(static_cast<_Sp_cd_type*>(_M_pi), 1);
- __throw_exception_again;
- }
- }
-
- template<typename _Tp, typename _Alloc, typename... _Args>
- __shared_count(_Sp_make_shared_tag, _Tp*, _Alloc __a, _Args&&... __args)
- : _M_pi(0)
- {
- typedef _Sp_counted_ptr_inplace<_Tp, _Alloc, _Lp> _Sp_cp_type;
- typedef typename _Alloc::template rebind<_Sp_cp_type>::other _Alloc2;
- _Alloc2 __a2(__a);
- __try
- {
- _M_pi = __a2.allocate(1);
- ::new(static_cast<void*>(_M_pi)) _Sp_cp_type(__a,
- std::forward<_Args>(__args)...);
- }
- __catch(...)
- {
- if (_M_pi)
- __a2.deallocate(static_cast<_Sp_cp_type*>(_M_pi), 1);
- __throw_exception_again;
- }
- }
-
-#if _GLIBCXX_DEPRECATED
- // 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(); }
-#endif
-
- // Special case for unique_ptr<_Tp,_Del> to provide the strong guarantee.
- template<typename _Tp, typename _Del>
- explicit
- __shared_count(std::unique_ptr<_Tp, _Del>&& __r)
- : _M_pi(_S_create_from_up(std::move(__r)))
- { __r.release(); }
-
- // Throw bad_weak_ptr when __r._M_get_use_count() == 0.
- explicit
- __shared_count(const __weak_count<_Lp>& __r);
-
- ~__shared_count() // nothrow
- {
- if (_M_pi != 0)
- _M_pi->_M_release();
- }
-
- __shared_count(const __shared_count& __r)
- : _M_pi(__r._M_pi) // nothrow
- {
- if (_M_pi != 0)
- _M_pi->_M_add_ref_copy();
- }
-
- __shared_count&
- operator=(const __shared_count& __r) // nothrow
- {
- _Sp_counted_base<_Lp>* __tmp = __r._M_pi;
- if (__tmp != _M_pi)
- {
- if (__tmp != 0)
- __tmp->_M_add_ref_copy();
- if (_M_pi != 0)
- _M_pi->_M_release();
- _M_pi = __tmp;
- }
- return *this;
- }
-
- void
- _M_swap(__shared_count& __r) // nothrow
- {
- _Sp_counted_base<_Lp>* __tmp = __r._M_pi;
- __r._M_pi = _M_pi;
- _M_pi = __tmp;
- }
-
- long
- _M_get_use_count() const // nothrow
- { return _M_pi != 0 ? _M_pi->_M_get_use_count() : 0; }
-
- bool
- _M_unique() const // nothrow
- { return this->_M_get_use_count() == 1; }
-
- void*
- _M_get_deleter(const std::type_info& __ti) const
- { return _M_pi ? _M_pi->_M_get_deleter(__ti) : 0; }
-
- bool
- _M_less(const __shared_count& __rhs) const
- { return std::less<_Sp_counted_base<_Lp>*>()(this->_M_pi, __rhs._M_pi); }
-
- bool
- _M_less(const __weak_count<_Lp>& __rhs) const
- { return std::less<_Sp_counted_base<_Lp>*>()(this->_M_pi, __rhs._M_pi); }
-
- // friend function injected into enclosing namespace and found by ADL
- friend inline bool
- operator==(const __shared_count& __a, const __shared_count& __b)
- { return __a._M_pi == __b._M_pi; }
-
- private:
- friend class __weak_count<_Lp>;
-
- template<typename _Tp, typename _Del>
- static _Sp_counted_base<_Lp>*
- _S_create_from_up(std::unique_ptr<_Tp, _Del>&& __r,
- typename std::enable_if<!std::is_reference<_Del>::value>::type* = 0)
- {
- return new _Sp_counted_deleter<_Tp*, _Del, std::allocator<_Tp>,
- _Lp>(__r.get(), __r.get_deleter());
- }
-
- template<typename _Tp, typename _Del>
- static _Sp_counted_base<_Lp>*
- _S_create_from_up(std::unique_ptr<_Tp, _Del>&& __r,
- typename std::enable_if<std::is_reference<_Del>::value>::type* = 0)
- {
- typedef typename std::remove_reference<_Del>::type _Del1;
- typedef std::reference_wrapper<_Del1> _Del2;
- return new _Sp_counted_deleter<_Tp*, _Del2, std::allocator<_Tp>,
- _Lp>(__r.get(), std::ref(__r.get_deleter()));
- }
-
- _Sp_counted_base<_Lp>* _M_pi;
- };
-
-
- template<_Lock_policy _Lp>
- class __weak_count
- {
- public:
- __weak_count()
- : _M_pi(0) // nothrow
- { }
-
- __weak_count(const __shared_count<_Lp>& __r)
- : _M_pi(__r._M_pi) // nothrow
- {
- if (_M_pi != 0)
- _M_pi->_M_weak_add_ref();
- }
-
- __weak_count(const __weak_count<_Lp>& __r)
- : _M_pi(__r._M_pi) // nothrow
- {
- if (_M_pi != 0)
- _M_pi->_M_weak_add_ref();
- }
-
- ~__weak_count() // nothrow
- {
- if (_M_pi != 0)
- _M_pi->_M_weak_release();
- }
-
- __weak_count<_Lp>&
- operator=(const __shared_count<_Lp>& __r) // nothrow
- {
- _Sp_counted_base<_Lp>* __tmp = __r._M_pi;
- if (__tmp != 0)
- __tmp->_M_weak_add_ref();
- if (_M_pi != 0)
- _M_pi->_M_weak_release();
- _M_pi = __tmp;
- return *this;
- }
-
- __weak_count<_Lp>&
- operator=(const __weak_count<_Lp>& __r) // nothrow
- {
- _Sp_counted_base<_Lp>* __tmp = __r._M_pi;
- if (__tmp != 0)
- __tmp->_M_weak_add_ref();
- if (_M_pi != 0)
- _M_pi->_M_weak_release();
- _M_pi = __tmp;
- return *this;
- }
-
- void
- _M_swap(__weak_count<_Lp>& __r) // nothrow
- {
- _Sp_counted_base<_Lp>* __tmp = __r._M_pi;
- __r._M_pi = _M_pi;
- _M_pi = __tmp;
- }
-
- long
- _M_get_use_count() const // nothrow
- { return _M_pi != 0 ? _M_pi->_M_get_use_count() : 0; }
-
- bool
- _M_less(const __weak_count& __rhs) const
- { return std::less<_Sp_counted_base<_Lp>*>()(this->_M_pi, __rhs._M_pi); }
-
- bool
- _M_less(const __shared_count<_Lp>& __rhs) const
- { return std::less<_Sp_counted_base<_Lp>*>()(this->_M_pi, __rhs._M_pi); }
-
- // friend function injected into enclosing namespace and found by ADL
- friend inline bool
- operator==(const __weak_count& __a, const __weak_count& __b)
- { return __a._M_pi == __b._M_pi; }
-
- private:
- friend class __shared_count<_Lp>;
-
- _Sp_counted_base<_Lp>* _M_pi;
- };
-
- // now that __weak_count is defined we can define this constructor:
- template<_Lock_policy _Lp>
- inline
- __shared_count<_Lp>::
- __shared_count(const __weak_count<_Lp>& __r)
- : _M_pi(__r._M_pi)
+ /// 2.2.3.7 shared_ptr I/O
+ template<typename _Ch, typename _Tr, typename _Tp, _Lock_policy _Lp>
+ std::basic_ostream<_Ch, _Tr>&
+ operator<<(std::basic_ostream<_Ch, _Tr>& __os,
+ const __shared_ptr<_Tp, _Lp>& __p)
{
- if (_M_pi != 0)
- _M_pi->_M_add_ref_lock();
- else
- __throw_bad_weak_ptr();
+ __os << __p.get();
+ return __os;
}
- // Forward declarations.
- template<typename _Tp, _Lock_policy _Lp = __default_lock_policy>
- class __shared_ptr;
-
- template<typename _Tp, _Lock_policy _Lp = __default_lock_policy>
- class __weak_ptr;
-
- template<typename _Tp, _Lock_policy _Lp = __default_lock_policy>
- class __enable_shared_from_this;
+ /// 2.2.3.10 shared_ptr get_deleter (experimental)
+ template<typename _Del, typename _Tp, _Lock_policy _Lp>
+ inline _Del*
+ get_deleter(const __shared_ptr<_Tp, _Lp>& __p)
+ { return static_cast<_Del*>(__p._M_get_deleter(typeid(_Del))); }
- template<typename _Tp>
- class shared_ptr;
-
- template<typename _Tp>
- class weak_ptr;
+ /**
+ * @brief A smart pointer with reference-counted copy semantics.
+ *
+ * The object pointed to is deleted when the last shared_ptr pointing to
+ * it is destroyed or reset.
+ */
template<typename _Tp>
- class enable_shared_from_this;
-
- // Support for enable_shared_from_this.
-
- // Friend of __enable_shared_from_this.
- template<_Lock_policy _Lp, typename _Tp1, typename _Tp2>
- void
- __enable_shared_from_this_helper(const __shared_count<_Lp>&,
- const __enable_shared_from_this<_Tp1,
- _Lp>*, const _Tp2*);
-
- // Friend of enable_shared_from_this.
- template<typename _Tp1, typename _Tp2>
- void
- __enable_shared_from_this_helper(const __shared_count<>&,
- const enable_shared_from_this<_Tp1>*,
- const _Tp2*);
-
- template<_Lock_policy _Lp>
- inline void
- __enable_shared_from_this_helper(const __shared_count<_Lp>&, ...)
- { }
-
-
- template<typename _Tp, _Lock_policy _Lp>
- class __shared_ptr
+ class shared_ptr : public __shared_ptr<_Tp>
{
public:
- typedef _Tp element_type;
-
- /** @brief Construct an empty %__shared_ptr.
+ /**
+ * @brief Construct an empty %shared_ptr.
* @post use_count()==0 && get()==0
*/
- __shared_ptr()
- : _M_ptr(0), _M_refcount() // never throws
- { }
+ shared_ptr() : __shared_ptr<_Tp>() { }
- /** @brief Construct a %__shared_ptr that owns the pointer @a __p.
+ /**
+ * @brief Construct a %shared_ptr that owns the pointer @a __p.
* @param __p A pointer that is convertible to element_type*.
* @post use_count() == 1 && get() == __p
* @throw std::bad_alloc, in which case @c delete @a __p is called.
*/
template<typename _Tp1>
- explicit
- __shared_ptr(_Tp1* __p)
- : _M_ptr(__p), _M_refcount(__p)
- {
- __glibcxx_function_requires(_ConvertibleConcept<_Tp1*, _Tp*>)
- // __glibcxx_function_requires(_CompleteConcept<_Tp1*>)
- __enable_shared_from_this_helper(_M_refcount, __p, __p);
- }
+ explicit shared_ptr(_Tp1* __p) : __shared_ptr<_Tp>(__p) { }
- //
- // Requirements: _Deleter's copy constructor and destructor must
- // not throw
- //
- // __shared_ptr will release __p by calling __d(__p)
- //
- /** @brief Construct a %__shared_ptr that owns the pointer @a __p
+ /**
+ * @brief Construct a %shared_ptr that owns the pointer @a __p
* and the deleter @a __d.
* @param __p A pointer.
* @param __d A deleter.
* @post use_count() == 1 && get() == __p
* @throw std::bad_alloc, in which case @a __d(__p) is called.
+ *
+ * Requirements: _Deleter's copy constructor and destructor must
+ * not throw
+ *
+ * __shared_ptr will release __p by calling __d(__p)
*/
- template<typename _Tp1, typename _Deleter>
- __shared_ptr(_Tp1* __p, _Deleter __d)
- : _M_ptr(__p), _M_refcount(__p, __d)
- {
- __glibcxx_function_requires(_ConvertibleConcept<_Tp1*, _Tp*>)
- // TODO requires _Deleter CopyConstructible and __d(__p) well-formed
- __enable_shared_from_this_helper(_M_refcount, __p, __p);
- }
-
- //
- // Requirements: _Deleter's copy constructor and destructor must
- // not throw _Alloc's copy constructor and destructor must not
- // throw.
- //
- // __shared_ptr will release __p by calling __d(__p)
- //
- /** @brief Construct a %__shared_ptr that owns the pointer @a __p
+ template<typename _Tp1, typename _Deleter>
+ shared_ptr(_Tp1* __p, _Deleter __d) : __shared_ptr<_Tp>(__p, __d) { }
+
+ /**
+ * @brief Construct a %shared_ptr that owns the pointer @a __p
* and the deleter @a __d.
* @param __p A pointer.
* @param __d A deleter.
* @param __a An allocator.
* @post use_count() == 1 && get() == __p
* @throw std::bad_alloc, in which case @a __d(__p) is called.
+ *
+ * Requirements: _Deleter's copy constructor and destructor must
+ * not throw _Alloc's copy constructor and destructor must not
+ * throw.
+ *
+ * __shared_ptr will release __p by calling __d(__p)
*/
template<typename _Tp1, typename _Deleter, typename _Alloc>
- __shared_ptr(_Tp1* __p, _Deleter __d, const _Alloc& __a)
- : _M_ptr(__p), _M_refcount(__p, __d, __a)
- {
- __glibcxx_function_requires(_ConvertibleConcept<_Tp1*, _Tp*>)
- // TODO requires _Deleter CopyConstructible and __d(__p) well-formed
- __enable_shared_from_this_helper(_M_refcount, __p, __p);
- }
+ shared_ptr(_Tp1* __p, _Deleter __d, const _Alloc& __a)
+ : __shared_ptr<_Tp>(__p, __d, __a) { }
+
+ // Aliasing constructor
- /** @brief Constructs a %__shared_ptr instance that stores @a __p
+ /**
+ * @brief Constructs a %shared_ptr instance that stores @a __p
* and shares ownership with @a __r.
- * @param __r A %__shared_ptr.
+ * @param __r A %shared_ptr.
* @param __p A pointer that will remain valid while @a *__r is valid.
* @post get() == __p && use_count() == __r.use_count()
*
@@ -634,48 +158,38 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
* @endcode
*/
template<typename _Tp1>
- __shared_ptr(const __shared_ptr<_Tp1, _Lp>& __r, _Tp* __p)
- : _M_ptr(__p), _M_refcount(__r._M_refcount) // never throws
- { }
-
- // generated copy constructor, assignment, destructor are fine.
-
- /** @brief If @a __r is empty, constructs an empty %__shared_ptr;
- * otherwise construct a %__shared_ptr that shares ownership
+ shared_ptr(const shared_ptr<_Tp1>& __r, _Tp* __p)
+ : __shared_ptr<_Tp>(__r, __p) { }
+
+ /**
+ * @brief If @a __r is empty, constructs an empty %shared_ptr;
+ * otherwise construct a %shared_ptr that shares ownership
* with @a __r.
- * @param __r A %__shared_ptr.
+ * @param __r A %shared_ptr.
* @post get() == __r.get() && use_count() == __r.use_count()
*/
template<typename _Tp1>
- __shared_ptr(const __shared_ptr<_Tp1, _Lp>& __r)
- : _M_ptr(__r._M_ptr), _M_refcount(__r._M_refcount) // never throws
- { __glibcxx_function_requires(_ConvertibleConcept<_Tp1*, _Tp*>) }
+ shared_ptr(const shared_ptr<_Tp1>& __r) : __shared_ptr<_Tp>(__r) { }
- /** @brief Move-constructs a %__shared_ptr instance from @a __r.
- * @param __r A %__shared_ptr rvalue.
+ /**
+ * @brief Move-constructs a %shared_ptr instance from @a __r.
+ * @param __r A %shared_ptr rvalue.
* @post *this contains the old value of @a __r, @a __r is empty.
*/
- __shared_ptr(__shared_ptr&& __r)
- : _M_ptr(__r._M_ptr), _M_refcount() // never throws
- {
- _M_refcount._M_swap(__r._M_refcount);
- __r._M_ptr = 0;
- }
+ shared_ptr(shared_ptr&& __r)
+ : __shared_ptr<_Tp>(std::move(__r)) { }
- /** @brief Move-constructs a %__shared_ptr instance from @a __r.
- * @param __r A %__shared_ptr rvalue.
+ /**
+ * @brief Move-constructs a %shared_ptr instance from @a __r.
+ * @param __r A %shared_ptr rvalue.
* @post *this contains the old value of @a __r, @a __r is empty.
*/
template<typename _Tp1>
- __shared_ptr(__shared_ptr<_Tp1, _Lp>&& __r)
- : _M_ptr(__r._M_ptr), _M_refcount() // never throws
- {
- __glibcxx_function_requires(_ConvertibleConcept<_Tp1*, _Tp*>)
- _M_refcount._M_swap(__r._M_refcount);
- __r._M_ptr = 0;
- }
-
- /** @brief Constructs a %__shared_ptr that shares ownership with @a __r
+ shared_ptr(shared_ptr<_Tp1>&& __r)
+ : __shared_ptr<_Tp>(std::move(__r)) { }
+
+ /**
+ * @brief Constructs a %shared_ptr that shares ownership with @a __r
* and stores a copy of the pointer stored in @a __r.
* @param __r A weak_ptr.
* @post use_count() == __r.use_count()
@@ -683,609 +197,36 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
* in which case the constructor has no effect.
*/
template<typename _Tp1>
- explicit
- __shared_ptr(const __weak_ptr<_Tp1, _Lp>& __r)
- : _M_refcount(__r._M_refcount) // may throw
- {
- __glibcxx_function_requires(_ConvertibleConcept<_Tp1*, _Tp*>)
- // It is now safe to copy __r._M_ptr, as _M_refcount(__r._M_refcount)
- // did not throw.
- _M_ptr = __r._M_ptr;
- }
-
- template<typename _Tp1, typename _Del>
- explicit
- __shared_ptr(const std::unique_ptr<_Tp1, _Del>&) = delete;
-
- /**
- * If an exception is thrown this constructor has no effect.
- */
- template<typename _Tp1, typename _Del>
- explicit
- __shared_ptr(std::unique_ptr<_Tp1, _Del>&& __r)
- : _M_ptr(__r.get()), _M_refcount()
- {
- __glibcxx_function_requires(_ConvertibleConcept<_Tp1*, _Tp*>)
- _Tp1* __tmp = __r.get();
- _M_refcount = __shared_count<_Lp>(std::move(__r));
- __enable_shared_from_this_helper(_M_refcount, __tmp, __tmp);
- }
-
-#if _GLIBCXX_DEPRECATED
- /**
- * @post use_count() == 1 and __r.get() == 0
- */
- template<typename _Tp1>
- explicit
- __shared_ptr(std::auto_ptr<_Tp1>&& __r)
- : _M_ptr(__r.get()), _M_refcount()
- {
- __glibcxx_function_requires(_ConvertibleConcept<_Tp1*, _Tp*>)
- // TODO requires _Tp1 is complete, delete __r.release() well-formed
- _Tp1* __tmp = __r.get();
- _M_refcount = __shared_count<_Lp>(std::move(__r));
- __enable_shared_from_this_helper(_M_refcount, __tmp, __tmp);
- }
-#endif
-
- template<typename _Tp1>
- __shared_ptr&
- operator=(const __shared_ptr<_Tp1, _Lp>& __r) // never throws
- {
- _M_ptr = __r._M_ptr;
- _M_refcount = __r._M_refcount; // __shared_count::op= doesn't throw
- return *this;
- }
-
-#if _GLIBCXX_DEPRECATED
- template<typename _Tp1>
- __shared_ptr&
- operator=(std::auto_ptr<_Tp1>&& __r)
- {
- __shared_ptr(std::move(__r)).swap(*this);
- return *this;
- }
-#endif
-
- __shared_ptr&
- operator=(__shared_ptr&& __r)
- {
- __shared_ptr(std::move(__r)).swap(*this);
- return *this;
- }
-
- template<class _Tp1>
- __shared_ptr&
- operator=(__shared_ptr<_Tp1, _Lp>&& __r)
- {
- __shared_ptr(std::move(__r)).swap(*this);
- return *this;
- }
-
- template<typename _Tp1, typename _Del>
- __shared_ptr&
- operator=(const std::unique_ptr<_Tp1, _Del>& __r) = delete;
-
- template<typename _Tp1, typename _Del>
- __shared_ptr&
- operator=(std::unique_ptr<_Tp1, _Del>&& __r)
- {
- __shared_ptr(std::move(__r)).swap(*this);
- return *this;
- }
-
- void
- reset() // never throws
- { __shared_ptr().swap(*this); }
-
- template<typename _Tp1>
- void
- reset(_Tp1* __p) // _Tp1 must be complete.
- {
- // Catch self-reset errors.
- _GLIBCXX_DEBUG_ASSERT(__p == 0 || __p != _M_ptr);
- __shared_ptr(__p).swap(*this);
- }
-
- template<typename _Tp1, typename _Deleter>
- void
- reset(_Tp1* __p, _Deleter __d)
- { __shared_ptr(__p, __d).swap(*this); }
-
- template<typename _Tp1, typename _Deleter, typename _Alloc>
- void
- reset(_Tp1* __p, _Deleter __d, const _Alloc& __a)
- { __shared_ptr(__p, __d, __a).swap(*this); }
-
- // Allow class instantiation when _Tp is [cv-qual] void.
- typename std::add_lvalue_reference<_Tp>::type
- operator*() const // never throws
- {
- _GLIBCXX_DEBUG_ASSERT(_M_ptr != 0);
- return *_M_ptr;
- }
-
- _Tp*
- operator->() const // never throws
- {
- _GLIBCXX_DEBUG_ASSERT(_M_ptr != 0);
- return _M_ptr;
- }
-
- _Tp*
- get() const // never throws
- { return _M_ptr; }
-
- explicit operator bool() const // never throws
- { return _M_ptr == 0 ? false : true; }
-
- bool
- unique() const // never throws
- { return _M_refcount._M_unique(); }
-
- long
- use_count() const // never throws
- { return _M_refcount._M_get_use_count(); }
-
- void
- swap(__shared_ptr<_Tp, _Lp>& __other) // never throws
- {
- std::swap(_M_ptr, __other._M_ptr);
- _M_refcount._M_swap(__other._M_refcount);
- }
-
- template<typename _Tp1>
- bool
- owner_before(__shared_ptr<_Tp1, _Lp> const& __rhs) const
- { return _M_refcount._M_less(__rhs._M_refcount); }
-
- template<typename _Tp1>
- bool
- owner_before(__weak_ptr<_Tp1, _Lp> const& __rhs) const
- { return _M_refcount._M_less(__rhs._M_refcount); }
-
- protected:
- // This constructor is non-standard, it is used by allocate_shared.
- template<typename _Alloc, typename... _Args>
- __shared_ptr(_Sp_make_shared_tag __tag, _Alloc __a, _Args&&... __args)
- : _M_ptr(), _M_refcount(__tag, (_Tp*)0, __a,
- std::forward<_Args>(__args)...)
- {
- // _M_ptr needs to point to the newly constructed object.
- // This relies on _Sp_counted_ptr_inplace::_M_get_deleter.
- void* __p = _M_refcount._M_get_deleter(typeid(__tag));
- _M_ptr = static_cast<_Tp*>(__p);
- __enable_shared_from_this_helper(_M_refcount, _M_ptr, _M_ptr);
- }
-
- template<typename _Tp1, _Lock_policy _Lp1, typename _Alloc,
- typename... _Args>
- friend __shared_ptr<_Tp1, _Lp1>
- __allocate_shared(_Alloc __a, _Args&&... __args);
-
- private:
- void*
- _M_get_deleter(const std::type_info& __ti) const
- { return _M_refcount._M_get_deleter(__ti); }
-
- template<typename _Tp1, _Lock_policy _Lp1> friend class __shared_ptr;
- template<typename _Tp1, _Lock_policy _Lp1> friend class __weak_ptr;
-
- template<typename _Del, typename _Tp1, _Lock_policy _Lp1>
- friend _Del* get_deleter(const __shared_ptr<_Tp1, _Lp1>&);
-
- _Tp* _M_ptr; // Contained pointer.
- __shared_count<_Lp> _M_refcount; // Reference counter.
- };
-
- // 20.8.13.2.7 shared_ptr comparisons
- template<typename _Tp1, typename _Tp2, _Lock_policy _Lp>
- inline bool
- operator==(const __shared_ptr<_Tp1, _Lp>& __a,
- const __shared_ptr<_Tp2, _Lp>& __b)
- { return __a.get() == __b.get(); }
-
- template<typename _Tp1, typename _Tp2, _Lock_policy _Lp>
- inline bool
- operator!=(const __shared_ptr<_Tp1, _Lp>& __a,
- const __shared_ptr<_Tp2, _Lp>& __b)
- { return __a.get() != __b.get(); }
-
- template<typename _Tp1, typename _Tp2, _Lock_policy _Lp>
- inline bool
- operator<(const __shared_ptr<_Tp1, _Lp>& __a,
- const __shared_ptr<_Tp2, _Lp>& __b)
- { return __a.get() < __b.get(); }
-
- template<typename _Sp>
- struct _Sp_less : public binary_function<_Sp, _Sp, bool>
- {
- bool
- operator()(const _Sp& __lhs, const _Sp& __rhs) const
- {
- return std::less<typename _Sp::element_type*>()(__lhs.get(),
- __rhs.get());
- }
- };
-
- template<typename _Tp, _Lock_policy _Lp>
- struct less<__shared_ptr<_Tp, _Lp>>
- : public _Sp_less<__shared_ptr<_Tp, _Lp>>
- { };
-
- // XXX LessThanComparable<_Tp> concept should provide >, >= and <=
- template<typename _Tp, _Lock_policy _Lp>
- inline bool
- operator>(const __shared_ptr<_Tp, _Lp>& __a,
- const __shared_ptr<_Tp, _Lp>& __b)
- { return __a.get() > __b.get(); }
-
- template<typename _Tp, _Lock_policy _Lp>
- inline bool
- operator>=(const __shared_ptr<_Tp, _Lp>& __a,
- const __shared_ptr<_Tp, _Lp>& __b)
- { return __a.get() >= __b.get(); }
-
- template<typename _Tp, _Lock_policy _Lp>
- inline bool
- operator<=(const __shared_ptr<_Tp, _Lp>& __a,
- const __shared_ptr<_Tp, _Lp>& __b)
- { return __a.get() <= __b.get(); }
-
- // 2.2.3.8 shared_ptr specialized algorithms.
- template<typename _Tp, _Lock_policy _Lp>
- inline void
- swap(__shared_ptr<_Tp, _Lp>& __a, __shared_ptr<_Tp, _Lp>& __b)
- { __a.swap(__b); }
-
- // 2.2.3.9 shared_ptr casts
- /** @warning The seemingly equivalent
- * <code>shared_ptr<_Tp, _Lp>(static_cast<_Tp*>(__r.get()))</code>
- * will eventually result in undefined behaviour,
- * attempting to delete the same object twice.
- */
- template<typename _Tp, typename _Tp1, _Lock_policy _Lp>
- inline __shared_ptr<_Tp, _Lp>
- static_pointer_cast(const __shared_ptr<_Tp1, _Lp>& __r)
- { return __shared_ptr<_Tp, _Lp>(__r, static_cast<_Tp*>(__r.get())); }
-
- /** @warning The seemingly equivalent
- * <code>shared_ptr<_Tp, _Lp>(const_cast<_Tp*>(__r.get()))</code>
- * will eventually result in undefined behaviour,
- * attempting to delete the same object twice.
- */
- template<typename _Tp, typename _Tp1, _Lock_policy _Lp>
- inline __shared_ptr<_Tp, _Lp>
- const_pointer_cast(const __shared_ptr<_Tp1, _Lp>& __r)
- { return __shared_ptr<_Tp, _Lp>(__r, const_cast<_Tp*>(__r.get())); }
-
- /** @warning The seemingly equivalent
- * <code>shared_ptr<_Tp, _Lp>(dynamic_cast<_Tp*>(__r.get()))</code>
- * will eventually result in undefined behaviour,
- * attempting to delete the same object twice.
- */
- template<typename _Tp, typename _Tp1, _Lock_policy _Lp>
- inline __shared_ptr<_Tp, _Lp>
- dynamic_pointer_cast(const __shared_ptr<_Tp1, _Lp>& __r)
- {
- if (_Tp* __p = dynamic_cast<_Tp*>(__r.get()))
- return __shared_ptr<_Tp, _Lp>(__r, __p);
- return __shared_ptr<_Tp, _Lp>();
- }
-
- // 2.2.3.7 shared_ptr I/O
- template<typename _Ch, typename _Tr, typename _Tp, _Lock_policy _Lp>
- std::basic_ostream<_Ch, _Tr>&
- operator<<(std::basic_ostream<_Ch, _Tr>& __os,
- const __shared_ptr<_Tp, _Lp>& __p)
- {
- __os << __p.get();
- return __os;
- }
-
- // 2.2.3.10 shared_ptr get_deleter (experimental)
- template<typename _Del, typename _Tp, _Lock_policy _Lp>
- inline _Del*
- get_deleter(const __shared_ptr<_Tp, _Lp>& __p)
- { return static_cast<_Del*>(__p._M_get_deleter(typeid(_Del))); }
-
-
- template<typename _Tp, _Lock_policy _Lp>
- class __weak_ptr
- {
- public:
- typedef _Tp element_type;
-
- __weak_ptr()
- : _M_ptr(0), _M_refcount() // never throws
- { }
-
- // Generated copy constructor, assignment, destructor are fine.
-
- // The "obvious" converting constructor implementation:
- //
- // template<typename _Tp1>
- // __weak_ptr(const __weak_ptr<_Tp1, _Lp>& __r)
- // : _M_ptr(__r._M_ptr), _M_refcount(__r._M_refcount) // never throws
- // { }
- //
- // has a serious problem.
- //
- // __r._M_ptr may already have been invalidated. The _M_ptr(__r._M_ptr)
- // conversion may require access to *__r._M_ptr (virtual inheritance).
- //
- // It is not possible to avoid spurious access violations since
- // in multithreaded programs __r._M_ptr may be invalidated at any point.
- template<typename _Tp1>
- __weak_ptr(const __weak_ptr<_Tp1, _Lp>& __r)
- : _M_refcount(__r._M_refcount) // never throws
- {
- __glibcxx_function_requires(_ConvertibleConcept<_Tp1*, _Tp*>)
- _M_ptr = __r.lock().get();
- }
-
- template<typename _Tp1>
- __weak_ptr(const __shared_ptr<_Tp1, _Lp>& __r)
- : _M_ptr(__r._M_ptr), _M_refcount(__r._M_refcount) // never throws
- { __glibcxx_function_requires(_ConvertibleConcept<_Tp1*, _Tp*>) }
-
- template<typename _Tp1>
- __weak_ptr&
- operator=(const __weak_ptr<_Tp1, _Lp>& __r) // never throws
- {
- _M_ptr = __r.lock().get();
- _M_refcount = __r._M_refcount;
- return *this;
- }
-
- template<typename _Tp1>
- __weak_ptr&
- operator=(const __shared_ptr<_Tp1, _Lp>& __r) // never throws
- {
- _M_ptr = __r._M_ptr;
- _M_refcount = __r._M_refcount;
- return *this;
- }
-
- __shared_ptr<_Tp, _Lp>
- lock() const // never throws
- {
-#ifdef __GTHREADS
- // Optimization: avoid throw overhead.
- if (expired())
- return __shared_ptr<element_type, _Lp>();
-
- __try
- {
- return __shared_ptr<element_type, _Lp>(*this);
- }
- __catch(const bad_weak_ptr&)
- {
- // Q: How can we get here?
- // A: Another thread may have invalidated r after the
- // use_count test above.
- return __shared_ptr<element_type, _Lp>();
- }
-
-#else
- // Optimization: avoid try/catch overhead when single threaded.
- return expired() ? __shared_ptr<element_type, _Lp>()
- : __shared_ptr<element_type, _Lp>(*this);
-
-#endif
- } // XXX MT
-
- long
- use_count() const // never throws
- { return _M_refcount._M_get_use_count(); }
-
- bool
- expired() const // never throws
- { return _M_refcount._M_get_use_count() == 0; }
-
- template<typename _Tp1>
- bool
- owner_before(const __shared_ptr<_Tp1, _Lp>& __rhs) const
- { return _M_refcount._M_less(__rhs._M_refcount); }
-
- template<typename _Tp1>
- bool
- owner_before(const __weak_ptr<_Tp1, _Lp>& __rhs) const
- { return _M_refcount._M_less(__rhs._M_refcount); }
-
- void
- reset() // never throws
- { __weak_ptr().swap(*this); }
-
- void
- swap(__weak_ptr& __s) // never throws
- {
- std::swap(_M_ptr, __s._M_ptr);
- _M_refcount._M_swap(__s._M_refcount);
- }
-
- // comparisons
- template<typename _Tp1>
- bool operator<(const __weak_ptr<_Tp1, _Lp>&) const = delete;
- template<typename _Tp1>
- bool operator<=(const __weak_ptr<_Tp1, _Lp>&) const = delete;
- template<typename _Tp1>
- bool operator>(const __weak_ptr<_Tp1, _Lp>&) const = delete;
- template<typename _Tp1>
- bool operator>=(const __weak_ptr<_Tp1, _Lp>&) const = delete;
-
- private:
- // Used by __enable_shared_from_this.
- void
- _M_assign(_Tp* __ptr, const __shared_count<_Lp>& __refcount)
- {
- _M_ptr = __ptr;
- _M_refcount = __refcount;
- }
-
- template<typename _Tp1, _Lock_policy _Lp1> friend class __shared_ptr;
- template<typename _Tp1, _Lock_policy _Lp1> friend class __weak_ptr;
- friend class __enable_shared_from_this<_Tp, _Lp>;
- friend class enable_shared_from_this<_Tp>;
-
- _Tp* _M_ptr; // Contained pointer.
- __weak_count<_Lp> _M_refcount; // Reference counter.
- };
-
- // 20.8.13.3.7 weak_ptr specialized algorithms.
- template<typename _Tp, _Lock_policy _Lp>
- inline void
- swap(__weak_ptr<_Tp, _Lp>& __a, __weak_ptr<_Tp, _Lp>& __b)
- { __a.swap(__b); }
-
- /// owner_less
- template<typename _Tp> struct owner_less;
-
- template<typename _Tp, typename _Tp1>
- struct _Sp_owner_less : public binary_function<_Tp, _Tp, bool>
- {
- bool
- operator()(const _Tp& __lhs, const _Tp& __rhs) const
- { return __lhs.owner_before(__rhs); }
- bool
- operator()(const _Tp& __lhs, const _Tp1& __rhs) const
- { return __lhs.owner_before(__rhs); }
- bool
- operator()(const _Tp1& __lhs, const _Tp& __rhs) const
- { return __lhs.owner_before(__rhs); }
- };
-
- template<typename _Tp, _Lock_policy _Lp>
- struct owner_less<__shared_ptr<_Tp, _Lp>>
- : public _Sp_owner_less<__shared_ptr<_Tp, _Lp>, __weak_ptr<_Tp, _Lp>>
- { };
-
- template<typename _Tp, _Lock_policy _Lp>
- struct owner_less<__weak_ptr<_Tp, _Lp>>
- : public _Sp_owner_less<__weak_ptr<_Tp, _Lp>, __shared_ptr<_Tp, _Lp>>
- {
- };
-
-
- template<typename _Tp, _Lock_policy _Lp>
- class __enable_shared_from_this
- {
- protected:
- __enable_shared_from_this() { }
-
- __enable_shared_from_this(const __enable_shared_from_this&) { }
-
- __enable_shared_from_this&
- operator=(const __enable_shared_from_this&)
- { return *this; }
-
- ~__enable_shared_from_this() { }
-
- public:
- __shared_ptr<_Tp, _Lp>
- shared_from_this()
- { return __shared_ptr<_Tp, _Lp>(this->_M_weak_this); }
-
- __shared_ptr<const _Tp, _Lp>
- shared_from_this() const
- { return __shared_ptr<const _Tp, _Lp>(this->_M_weak_this); }
-
- private:
- template<typename _Tp1>
- void
- _M_weak_assign(_Tp1* __p, const __shared_count<_Lp>& __n) const
- { _M_weak_this._M_assign(__p, __n); }
-
- template<typename _Tp1>
- friend void
- __enable_shared_from_this_helper(const __shared_count<_Lp>& __pn,
- const __enable_shared_from_this* __pe,
- const _Tp1* __px)
- {
- if (__pe != 0)
- __pe->_M_weak_assign(const_cast<_Tp1*>(__px), __pn);
- }
-
- mutable __weak_ptr<_Tp, _Lp> _M_weak_this;
- };
-
- /**
- * @brief A smart pointer with reference-counted copy semantics.
- *
- * The object pointed to is deleted when the last shared_ptr pointing to
- * it is destroyed or reset.
- */
- template<typename _Tp>
- class shared_ptr
- : public __shared_ptr<_Tp>
- {
- public:
- shared_ptr()
- : __shared_ptr<_Tp>() { }
-
- template<typename _Tp1>
- explicit
- shared_ptr(_Tp1* __p)
- : __shared_ptr<_Tp>(__p) { }
-
- template<typename _Tp1, typename _Deleter>
- shared_ptr(_Tp1* __p, _Deleter __d)
- : __shared_ptr<_Tp>(__p, __d) { }
-
- template<typename _Tp1, typename _Deleter, typename _Alloc>
- shared_ptr(_Tp1* __p, _Deleter __d, const _Alloc& __a)
- : __shared_ptr<_Tp>(__p, __d, __a) { }
-
- // Aliasing constructor
- template<typename _Tp1>
- shared_ptr(const shared_ptr<_Tp1>& __r, _Tp* __p)
- : __shared_ptr<_Tp>(__r, __p) { }
-
- template<typename _Tp1>
- shared_ptr(const shared_ptr<_Tp1>& __r)
- : __shared_ptr<_Tp>(__r) { }
-
- shared_ptr(shared_ptr&& __r)
- : __shared_ptr<_Tp>(std::move(__r)) { }
-
- template<typename _Tp1>
- shared_ptr(shared_ptr<_Tp1>&& __r)
- : __shared_ptr<_Tp>(std::move(__r)) { }
-
- template<typename _Tp1>
- explicit
- shared_ptr(const weak_ptr<_Tp1>& __r)
+ explicit shared_ptr(const weak_ptr<_Tp1>& __r)
: __shared_ptr<_Tp>(__r) { }
#if _GLIBCXX_DEPRECATED
template<typename _Tp1>
- explicit
- shared_ptr(std::auto_ptr<_Tp1>&& __r)
+ explicit
+ shared_ptr(std::auto_ptr<_Tp1>&& __r)
: __shared_ptr<_Tp>(std::move(__r)) { }
#endif
template<typename _Tp1, typename _Del>
- explicit
- shared_ptr(const std::unique_ptr<_Tp1, _Del>&) = delete;
+ explicit shared_ptr(const std::unique_ptr<_Tp1, _Del>&) = delete;
template<typename _Tp1, typename _Del>
- explicit
- shared_ptr(std::unique_ptr<_Tp1, _Del>&& __r)
+ explicit shared_ptr(std::unique_ptr<_Tp1, _Del>&& __r)
: __shared_ptr<_Tp>(std::move(__r)) { }
template<typename _Tp1>
- shared_ptr&
- operator=(const shared_ptr<_Tp1>& __r) // never throws
- {
+ shared_ptr&
+ operator=(const shared_ptr<_Tp1>& __r) // never throws
+ {
this->__shared_ptr<_Tp>::operator=(__r);
return *this;
}
#if _GLIBCXX_DEPRECATED
template<typename _Tp1>
- shared_ptr&
- operator=(std::auto_ptr<_Tp1>&& __r)
- {
+ shared_ptr&
+ operator=(std::auto_ptr<_Tp1>&& __r)
+ {
this->__shared_ptr<_Tp>::operator=(std::move(__r));
return *this;
}
@@ -1294,26 +235,26 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
shared_ptr&
operator=(shared_ptr&& __r)
{
- this->__shared_ptr<_Tp>::operator=(std::move(__r));
- return *this;
+ this->__shared_ptr<_Tp>::operator=(std::move(__r));
+ return *this;
}
-
+
template<class _Tp1>
- shared_ptr&
- operator=(shared_ptr<_Tp1>&& __r)
- {
- this->__shared_ptr<_Tp>::operator=(std::move(__r));
- return *this;
- }
+ shared_ptr&
+ operator=(shared_ptr<_Tp1>&& __r)
+ {
+ this->__shared_ptr<_Tp>::operator=(std::move(__r));
+ return *this;
+ }
template<typename _Tp1, typename _Del>
- shared_ptr&
- operator=(const std::unique_ptr<_Tp1, _Del>& __r) = delete;
+ shared_ptr&
+ operator=(const std::unique_ptr<_Tp1, _Del>& __r) = delete;
template<typename _Tp1, typename _Del>
- shared_ptr&
- operator=(std::unique_ptr<_Tp1, _Del>&& __r)
- {
+ shared_ptr&
+ operator=(std::unique_ptr<_Tp1, _Del>&& __r)
+ {
this->__shared_ptr<_Tp>::operator=(std::move(__r));
return *this;
}
@@ -1321,13 +262,13 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
private:
// This constructor is non-standard, it is used by allocate_shared.
template<typename _Alloc, typename... _Args>
- shared_ptr(_Sp_make_shared_tag __tag, _Alloc __a, _Args&&... __args)
- : __shared_ptr<_Tp>(__tag, __a, std::forward<_Args>(__args)...)
- { }
+ shared_ptr(_Sp_make_shared_tag __tag, _Alloc __a, _Args&&... __args)
+ : __shared_ptr<_Tp>(__tag, __a, std::forward<_Args>(__args)...)
+ { }
template<typename _Tp1, typename _Alloc, typename... _Args>
- friend shared_ptr<_Tp1>
- allocate_shared(_Alloc __a, _Args&&... __args);
+ friend shared_ptr<_Tp1>
+ allocate_shared(_Alloc __a, _Args&&... __args);
};
// 20.8.13.2.7 shared_ptr comparisons
@@ -1347,8 +288,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
{ return __a.get() < __b.get(); }
template<typename _Tp>
- struct less<shared_ptr<_Tp>>
- : public _Sp_less<shared_ptr<_Tp>>
+ struct less<shared_ptr<_Tp>> : public _Sp_less<shared_ptr<_Tp>>
{ };
// 20.8.13.2.9 shared_ptr specialized algorithms.
@@ -1373,44 +313,42 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
dynamic_pointer_cast(const shared_ptr<_Tp1>& __r)
{
if (_Tp* __p = dynamic_cast<_Tp*>(__r.get()))
- return shared_ptr<_Tp>(__r, __p);
+ return shared_ptr<_Tp>(__r, __p);
return shared_ptr<_Tp>();
}
- /**
- * @brief A smart pointer with weak semantics.
- *
+ /**
+ * @brief A smart pointer with weak semantics.
+ *
* With forwarding constructors and assignment operators.
*/
template<typename _Tp>
- class weak_ptr
- : public __weak_ptr<_Tp>
+ class weak_ptr : public __weak_ptr<_Tp>
{
public:
- weak_ptr()
- : __weak_ptr<_Tp>() { }
-
+ weak_ptr() : __weak_ptr<_Tp>() { }
+
template<typename _Tp1>
- weak_ptr(const weak_ptr<_Tp1>& __r)
+ weak_ptr(const weak_ptr<_Tp1>& __r)
: __weak_ptr<_Tp>(__r) { }
template<typename _Tp1>
- weak_ptr(const shared_ptr<_Tp1>& __r)
+ weak_ptr(const shared_ptr<_Tp1>& __r)
: __weak_ptr<_Tp>(__r) { }
template<typename _Tp1>
- weak_ptr&
- operator=(const weak_ptr<_Tp1>& __r) // never throws
- {
+ weak_ptr&
+ operator=(const weak_ptr<_Tp1>& __r) // never throws
+ {
this->__weak_ptr<_Tp>::operator=(__r);
return *this;
}
template<typename _Tp1>
- weak_ptr&
- operator=(const shared_ptr<_Tp1>& __r) // never throws
- {
+ weak_ptr&
+ operator=(const shared_ptr<_Tp1>& __r) // never throws
+ {
this->__weak_ptr<_Tp>::operator=(__r);
return *this;
}
@@ -1431,20 +369,19 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
return shared_ptr<_Tp>();
}
#else
- return this->expired() ? shared_ptr<_Tp>()
- : shared_ptr<_Tp>(*this);
+ return this->expired() ? shared_ptr<_Tp>() : shared_ptr<_Tp>(*this);
#endif
}
- // comparisons
+ // Comparisons
template<typename _Tp1>
- bool operator<(const weak_ptr<_Tp1>&) const = delete;
+ bool operator<(const weak_ptr<_Tp1>&) const = delete;
template<typename _Tp1>
- bool operator<=(const weak_ptr<_Tp1>&) const = delete;
+ bool operator<=(const weak_ptr<_Tp1>&) const = delete;
template<typename _Tp1>
- bool operator>(const weak_ptr<_Tp1>&) const = delete;
+ bool operator>(const weak_ptr<_Tp1>&) const = delete;
template<typename _Tp1>
- bool operator>=(const weak_ptr<_Tp1>&) const = delete;
+ bool operator>=(const weak_ptr<_Tp1>&) const = delete;
};
// 20.8.13.3.7 weak_ptr specialized algorithms.
@@ -1453,18 +390,24 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
swap(weak_ptr<_Tp>& __a, weak_ptr<_Tp>& __b)
{ __a.swap(__b); }
- /// owner_less
+
+ /// Primary template owner_less
+ template<typename _Tp>
+ struct owner_less;
+
+ /// Partial specialization of owner_less for shared_ptr.
template<typename _Tp>
struct owner_less<shared_ptr<_Tp>>
: public _Sp_owner_less<shared_ptr<_Tp>, weak_ptr<_Tp>>
{ };
+ /// Partial specialization of owner_less for weak_ptr.
template<typename _Tp>
struct owner_less<weak_ptr<_Tp>>
: public _Sp_owner_less<weak_ptr<_Tp>, shared_ptr<_Tp>>
{ };
- /**
+ /**
* @brief Base class allowing use of member function shared_from_this.
*/
template<typename _Tp>
@@ -1472,7 +415,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
{
protected:
enable_shared_from_this() { }
-
+
enable_shared_from_this(const enable_shared_from_this&) { }
enable_shared_from_this&
@@ -1492,16 +435,16 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
private:
template<typename _Tp1>
- void
- _M_weak_assign(_Tp1* __p, const __shared_count<>& __n) const
- { _M_weak_this._M_assign(__p, __n); }
+ void
+ _M_weak_assign(_Tp1* __p, const __shared_count<>& __n) const
+ { _M_weak_this._M_assign(__p, __n); }
template<typename _Tp1>
- friend void
- __enable_shared_from_this_helper(const __shared_count<>& __pn,
+ friend void
+ __enable_shared_from_this_helper(const __shared_count<>& __pn,
const enable_shared_from_this* __pe,
const _Tp1* __px)
- {
+ {
if (__pe != 0)
__pe->_M_weak_assign(const_cast<_Tp1*>(__px), __pn);
}
@@ -1509,24 +452,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
mutable weak_ptr<_Tp> _M_weak_this;
};
- template<typename _Tp, _Lock_policy _Lp, typename _Alloc, typename... _Args>
- inline __shared_ptr<_Tp, _Lp>
- __allocate_shared(_Alloc __a, _Args&&... __args)
- {
- return __shared_ptr<_Tp, _Lp>(_Sp_make_shared_tag(),
- std::forward<_Alloc>(__a), std::forward<_Args>(__args)...);
- }
-
- template<typename _Tp, _Lock_policy _Lp, typename... _Args>
- inline __shared_ptr<_Tp, _Lp>
- __make_shared(_Args&&... __args)
- {
- typedef typename std::remove_const<_Tp>::type _Tp_nc;
- return __allocate_shared<_Tp, _Lp>(std::allocator<_Tp_nc>(),
- std::forward<_Args>(__args)...);
- }
-
- /** @brief Create an object that is owned by a shared_ptr.
+ /**
+ * @brief Create an object that is owned by a shared_ptr.
* @param __a An allocator.
* @param __args Arguments for the @a _Tp object's constructor.
* @return A shared_ptr that owns the newly created object.
@@ -1541,10 +468,11 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
allocate_shared(_Alloc __a, _Args&&... __args)
{
return shared_ptr<_Tp>(_Sp_make_shared_tag(), std::forward<_Alloc>(__a),
- std::forward<_Args>(__args)...);
+ std::forward<_Args>(__args)...);
}
- /** @brief Create an object that is owned by a shared_ptr.
+ /**
+ * @brief Create an object that is owned by a shared_ptr.
* @param __args Arguments for the @a _Tp object's constructor.
* @return A shared_ptr that owns the newly created object.
* @throw std::bad_alloc, or an exception thrown from the
@@ -1556,7 +484,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
{
typedef typename std::remove_const<_Tp>::type _Tp_nc;
return allocate_shared<_Tp>(std::allocator<_Tp_nc>(),
- std::forward<_Args>(__args)...);
+ std::forward<_Args>(__args)...);
}
// @} group pointer_abstractions
diff --git a/libstdc++-v3/include/bits/shared_ptr_base.h b/libstdc++-v3/include/bits/shared_ptr_base.h
new file mode 100644
index 00000000000..b8083e405c8
--- /dev/null
+++ b/libstdc++-v3/include/bits/shared_ptr_base.h
@@ -0,0 +1,1114 @@
+// shared_ptr and weak_ptr implementation details -*- C++ -*-
+
+// Copyright (C) 2007, 2008, 2009 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
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// Under Section 7 of GPL version 3, you are granted additional
+// permissions described in the GCC Runtime Library Exception, version
+// 3.1, as published by the Free Software Foundation.
+
+// You should have received a copy of the GNU General Public License and
+// a copy of the GCC Runtime Library Exception along with this program;
+// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
+// <http://www.gnu.org/licenses/>.
+
+// GCC Note: Based on files from version 1.32.0 of the Boost library.
+
+// shared_count.hpp
+// Copyright (c) 2001, 2002, 2003 Peter Dimov and Multi Media Ltd.
+
+// shared_ptr.hpp
+// Copyright (C) 1998, 1999 Greg Colvin and Beman Dawes.
+// Copyright (C) 2001, 2002, 2003 Peter Dimov
+
+// weak_ptr.hpp
+// Copyright (C) 2001, 2002, 2003 Peter Dimov
+
+// enable_shared_from_this.hpp
+// Copyright (C) 2002 Peter Dimov
+
+// Distributed under the Boost Software License, Version 1.0. (See
+// accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+/** @file bits/shared_ptr_base.h
+ * This is an internal header file, included by other library headers.
+ * You should not attempt to use it directly.
+ */
+
+#ifndef _SHARED_PTR_BASE_H
+#define _SHARED_PTR_BASE_H 1
+
+_GLIBCXX_BEGIN_NAMESPACE(std)
+
+ // Forward declarations.
+ template<typename _Tp, _Lock_policy _Lp = __default_lock_policy>
+ class __shared_ptr;
+
+ template<typename _Tp, _Lock_policy _Lp = __default_lock_policy>
+ class __weak_ptr;
+
+ template<typename _Tp, _Lock_policy _Lp = __default_lock_policy>
+ class __enable_shared_from_this;
+
+ template<typename _Tp>
+ class shared_ptr;
+
+ template<typename _Tp>
+ class weak_ptr;
+
+ template<typename _Tp>
+ struct owner_less;
+
+ template<typename _Tp>
+ class enable_shared_from_this;
+
+ template<_Lock_policy _Lp = __default_lock_policy>
+ class __weak_count;
+
+ template<_Lock_policy _Lp = __default_lock_policy>
+ class __shared_count;
+
+
+ // Counted ptr with no deleter or allocator support
+ template<typename _Ptr, _Lock_policy _Lp>
+ class _Sp_counted_ptr : public _Sp_counted_base<_Lp>
+ {
+ public:
+ _Sp_counted_ptr(_Ptr __p)
+ : _M_ptr(__p) { }
+
+ virtual void
+ _M_dispose() // nothrow
+ { delete _M_ptr; }
+
+ virtual void
+ _M_destroy() // nothrow
+ { delete this; }
+
+ virtual void*
+ _M_get_deleter(const std::type_info& __ti)
+ { return 0; }
+
+ _Sp_counted_ptr(const _Sp_counted_ptr&) = delete;
+ _Sp_counted_ptr& operator=(const _Sp_counted_ptr&) = delete;
+
+ protected:
+ _Ptr _M_ptr; // copy constructor must not throw
+ };
+
+ // Support for custom deleter and/or allocator
+ template<typename _Ptr, typename _Deleter, typename _Alloc, _Lock_policy _Lp>
+ class _Sp_counted_deleter : public _Sp_counted_ptr<_Ptr, _Lp>
+ {
+ typedef typename _Alloc::template
+ rebind<_Sp_counted_deleter>::other _My_alloc_type;
+
+ // Helper class that stores the Deleter and also acts as an allocator.
+ // Used to dispose of the owned pointer and the internal refcount
+ // Requires that copies of _Alloc can free each other's memory.
+ struct _My_Deleter
+ : public _My_alloc_type // copy constructor must not throw
+ {
+ _Deleter _M_del; // copy constructor must not throw
+ _My_Deleter(_Deleter __d, const _Alloc& __a)
+ : _My_alloc_type(__a), _M_del(__d) { }
+ };
+
+ protected:
+ typedef _Sp_counted_ptr<_Ptr, _Lp> _Base_type;
+
+ public:
+ // __d(__p) must not throw.
+ _Sp_counted_deleter(_Ptr __p, _Deleter __d)
+ : _Base_type(__p), _M_del(__d, _Alloc()) { }
+
+ // __d(__p) must not throw.
+ _Sp_counted_deleter(_Ptr __p, _Deleter __d, const _Alloc& __a)
+ : _Base_type(__p), _M_del(__d, __a) { }
+
+ virtual void
+ _M_dispose() // nothrow
+ { _M_del._M_del(_Base_type::_M_ptr); }
+
+ virtual void
+ _M_destroy() // nothrow
+ {
+ _My_alloc_type __a(_M_del);
+ this->~_Sp_counted_deleter();
+ __a.deallocate(this, 1);
+ }
+
+ virtual void*
+ _M_get_deleter(const std::type_info& __ti)
+ { return __ti == typeid(_Deleter) ? &_M_del._M_del : 0; }
+
+ protected:
+ _My_Deleter _M_del; // copy constructor must not throw
+ };
+
+ // helpers for make_shared / allocate_shared
+
+ template<typename _Tp>
+ struct _Sp_destroy_inplace
+ {
+ void operator()(_Tp* __p) const { if (__p) __p->~_Tp(); }
+ };
+
+ struct _Sp_make_shared_tag { };
+
+ template<typename _Tp, typename _Alloc, _Lock_policy _Lp>
+ class _Sp_counted_ptr_inplace
+ : public _Sp_counted_deleter<_Tp*, _Sp_destroy_inplace<_Tp>, _Alloc, _Lp>
+ {
+ typedef _Sp_counted_deleter<_Tp*, _Sp_destroy_inplace<_Tp>, _Alloc, _Lp>
+ _Base_type;
+
+ public:
+ _Sp_counted_ptr_inplace(_Alloc __a)
+ : _Base_type(static_cast<_Tp*>(0), _Sp_destroy_inplace<_Tp>(), __a)
+ , _M_storage()
+ {
+ void* __p = &_M_storage;
+ ::new (__p) _Tp(); // might throw
+ _Base_type::_Base_type::_M_ptr = static_cast<_Tp*>(__p);
+ }
+
+ template<typename... _Args>
+ _Sp_counted_ptr_inplace(_Alloc __a, _Args&&... __args)
+ : _Base_type(static_cast<_Tp*>(0), _Sp_destroy_inplace<_Tp>(), __a)
+ , _M_storage()
+ {
+ void* __p = &_M_storage;
+ ::new (__p) _Tp(std::forward<_Args>(__args)...); // might throw
+ _Base_type::_Base_type::_M_ptr = static_cast<_Tp*>(__p);
+ }
+
+ // Override because the allocator needs to know the dynamic type
+ virtual void
+ _M_destroy() // nothrow
+ {
+ typedef typename _Alloc::template
+ rebind<_Sp_counted_ptr_inplace>::other _My_alloc_type;
+ _My_alloc_type __a(_Base_type::_M_del);
+ this->~_Sp_counted_ptr_inplace();
+ __a.deallocate(this, 1);
+ }
+
+ // Sneaky trick so __shared_ptr can get the managed pointer
+ virtual void*
+ _M_get_deleter(const std::type_info& __ti)
+ {
+ return __ti == typeid(_Sp_make_shared_tag)
+ ? static_cast<void*>(&_M_storage)
+ : _Base_type::_M_get_deleter(__ti);
+ }
+
+ private:
+ typename aligned_storage<sizeof(_Tp), alignment_of<_Tp>::value>::type
+ _M_storage;
+ };
+
+ template<_Lock_policy _Lp>
+ class __shared_count
+ {
+ public:
+ __shared_count() : _M_pi(0) // nothrow
+ { }
+
+ template<typename _Ptr>
+ __shared_count(_Ptr __p) : _M_pi(0)
+ {
+ __try
+ {
+ _M_pi = new _Sp_counted_ptr<_Ptr, _Lp>(__p);
+ }
+ __catch(...)
+ {
+ delete __p;
+ __throw_exception_again;
+ }
+ }
+
+ template<typename _Ptr, typename _Deleter>
+ __shared_count(_Ptr __p, _Deleter __d) : _M_pi(0)
+ {
+ // The allocator's value_type doesn't matter, will rebind it anyway.
+ typedef std::allocator<int> _Alloc;
+ typedef _Sp_counted_deleter<_Ptr, _Deleter, _Alloc, _Lp> _Sp_cd_type;
+ typedef std::allocator<_Sp_cd_type> _Alloc2;
+ _Alloc2 __a2;
+ __try
+ {
+ _M_pi = __a2.allocate(1);
+ ::new(static_cast<void*>(_M_pi)) _Sp_cd_type(__p, __d);
+ }
+ __catch(...)
+ {
+ __d(__p); // Call _Deleter on __p.
+ if (_M_pi)
+ __a2.deallocate(static_cast<_Sp_cd_type*>(_M_pi), 1);
+ __throw_exception_again;
+ }
+ }
+
+ template<typename _Ptr, typename _Deleter, typename _Alloc>
+ __shared_count(_Ptr __p, _Deleter __d, _Alloc __a) : _M_pi(0)
+ {
+ typedef _Sp_counted_deleter<_Ptr, _Deleter, _Alloc, _Lp> _Sp_cd_type;
+ typedef typename _Alloc::template rebind<_Sp_cd_type>::other _Alloc2;
+ _Alloc2 __a2(__a);
+ __try
+ {
+ _M_pi = __a2.allocate(1);
+ ::new(static_cast<void*>(_M_pi)) _Sp_cd_type(__p, __d, __a);
+ }
+ __catch(...)
+ {
+ __d(__p); // Call _Deleter on __p.
+ if (_M_pi)
+ __a2.deallocate(static_cast<_Sp_cd_type*>(_M_pi), 1);
+ __throw_exception_again;
+ }
+ }
+
+ template<typename _Tp, typename _Alloc, typename... _Args>
+ __shared_count(_Sp_make_shared_tag, _Tp*, _Alloc __a, _Args&&... __args)
+ : _M_pi(0)
+ {
+ typedef _Sp_counted_ptr_inplace<_Tp, _Alloc, _Lp> _Sp_cp_type;
+ typedef typename _Alloc::template rebind<_Sp_cp_type>::other _Alloc2;
+ _Alloc2 __a2(__a);
+ __try
+ {
+ _M_pi = __a2.allocate(1);
+ ::new(static_cast<void*>(_M_pi)) _Sp_cp_type(__a,
+ std::forward<_Args>(__args)...);
+ }
+ __catch(...)
+ {
+ if (_M_pi)
+ __a2.deallocate(static_cast<_Sp_cp_type*>(_M_pi), 1);
+ __throw_exception_again;
+ }
+ }
+
+#if _GLIBCXX_DEPRECATED
+ // 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(); }
+#endif
+
+ // Special case for unique_ptr<_Tp,_Del> to provide the strong guarantee.
+ template<typename _Tp, typename _Del>
+ explicit __shared_count(std::unique_ptr<_Tp, _Del>&& __r)
+ : _M_pi(_S_create_from_up(std::move(__r)))
+ { __r.release(); }
+
+ // Throw bad_weak_ptr when __r._M_get_use_count() == 0.
+ explicit __shared_count(const __weak_count<_Lp>& __r);
+
+ ~__shared_count() // nothrow
+ {
+ if (_M_pi != 0)
+ _M_pi->_M_release();
+ }
+
+ __shared_count(const __shared_count& __r)
+ : _M_pi(__r._M_pi) // nothrow
+ {
+ if (_M_pi != 0)
+ _M_pi->_M_add_ref_copy();
+ }
+
+ __shared_count&
+ operator=(const __shared_count& __r) // nothrow
+ {
+ _Sp_counted_base<_Lp>* __tmp = __r._M_pi;
+ if (__tmp != _M_pi)
+ {
+ if (__tmp != 0)
+ __tmp->_M_add_ref_copy();
+ if (_M_pi != 0)
+ _M_pi->_M_release();
+ _M_pi = __tmp;
+ }
+ return *this;
+ }
+
+ void
+ _M_swap(__shared_count& __r) // nothrow
+ {
+ _Sp_counted_base<_Lp>* __tmp = __r._M_pi;
+ __r._M_pi = _M_pi;
+ _M_pi = __tmp;
+ }
+
+ long
+ _M_get_use_count() const // nothrow
+ { return _M_pi != 0 ? _M_pi->_M_get_use_count() : 0; }
+
+ bool
+ _M_unique() const // nothrow
+ { return this->_M_get_use_count() == 1; }
+
+ void*
+ _M_get_deleter(const std::type_info& __ti) const
+ { return _M_pi ? _M_pi->_M_get_deleter(__ti) : 0; }
+
+ bool
+ _M_less(const __shared_count& __rhs) const
+ { return std::less<_Sp_counted_base<_Lp>*>()(this->_M_pi, __rhs._M_pi); }
+
+ bool
+ _M_less(const __weak_count<_Lp>& __rhs) const
+ { return std::less<_Sp_counted_base<_Lp>*>()(this->_M_pi, __rhs._M_pi); }
+
+ // Friend function injected into enclosing namespace and found by ADL
+ friend inline bool
+ operator==(const __shared_count& __a, const __shared_count& __b)
+ { return __a._M_pi == __b._M_pi; }
+
+ private:
+ friend class __weak_count<_Lp>;
+
+ template<typename _Tp, typename _Del>
+ static _Sp_counted_base<_Lp>*
+ _S_create_from_up(std::unique_ptr<_Tp, _Del>&& __r,
+ typename std::enable_if<!std::is_reference<_Del>::value>::type* = 0)
+ {
+ return new _Sp_counted_deleter<_Tp*, _Del, std::allocator<_Tp>,
+ _Lp>(__r.get(), __r.get_deleter());
+ }
+
+ template<typename _Tp, typename _Del>
+ static _Sp_counted_base<_Lp>*
+ _S_create_from_up(std::unique_ptr<_Tp, _Del>&& __r,
+ typename std::enable_if<std::is_reference<_Del>::value>::type* = 0)
+ {
+ typedef typename std::remove_reference<_Del>::type _Del1;
+ typedef std::reference_wrapper<_Del1> _Del2;
+ return new _Sp_counted_deleter<_Tp*, _Del2, std::allocator<_Tp>,
+ _Lp>(__r.get(), std::ref(__r.get_deleter()));
+ }
+
+ _Sp_counted_base<_Lp>* _M_pi;
+ };
+
+
+ template<_Lock_policy _Lp>
+ class __weak_count
+ {
+ public:
+ __weak_count() : _M_pi(0) // nothrow
+ { }
+
+ __weak_count(const __shared_count<_Lp>& __r) : _M_pi(__r._M_pi) // nothrow
+ {
+ if (_M_pi != 0)
+ _M_pi->_M_weak_add_ref();
+ }
+
+ __weak_count(const __weak_count<_Lp>& __r) : _M_pi(__r._M_pi) // nothrow
+ {
+ if (_M_pi != 0)
+ _M_pi->_M_weak_add_ref();
+ }
+
+ ~__weak_count() // nothrow
+ {
+ if (_M_pi != 0)
+ _M_pi->_M_weak_release();
+ }
+
+ __weak_count<_Lp>&
+ operator=(const __shared_count<_Lp>& __r) // nothrow
+ {
+ _Sp_counted_base<_Lp>* __tmp = __r._M_pi;
+ if (__tmp != 0)
+ __tmp->_M_weak_add_ref();
+ if (_M_pi != 0)
+ _M_pi->_M_weak_release();
+ _M_pi = __tmp;
+ return *this;
+ }
+
+ __weak_count<_Lp>&
+ operator=(const __weak_count<_Lp>& __r) // nothrow
+ {
+ _Sp_counted_base<_Lp>* __tmp = __r._M_pi;
+ if (__tmp != 0)
+ __tmp->_M_weak_add_ref();
+ if (_M_pi != 0)
+ _M_pi->_M_weak_release();
+ _M_pi = __tmp;
+ return *this;
+ }
+
+ void
+ _M_swap(__weak_count<_Lp>& __r) // nothrow
+ {
+ _Sp_counted_base<_Lp>* __tmp = __r._M_pi;
+ __r._M_pi = _M_pi;
+ _M_pi = __tmp;
+ }
+
+ long
+ _M_get_use_count() const // nothrow
+ { return _M_pi != 0 ? _M_pi->_M_get_use_count() : 0; }
+
+ bool
+ _M_less(const __weak_count& __rhs) const
+ { return std::less<_Sp_counted_base<_Lp>*>()(this->_M_pi, __rhs._M_pi); }
+
+ bool
+ _M_less(const __shared_count<_Lp>& __rhs) const
+ { return std::less<_Sp_counted_base<_Lp>*>()(this->_M_pi, __rhs._M_pi); }
+
+ // Friend function injected into enclosing namespace and found by ADL
+ friend inline bool
+ operator==(const __weak_count& __a, const __weak_count& __b)
+ { return __a._M_pi == __b._M_pi; }
+
+ private:
+ friend class __shared_count<_Lp>;
+
+ _Sp_counted_base<_Lp>* _M_pi;
+ };
+
+ // Now that __weak_count is defined we can define this constructor:
+ template<_Lock_policy _Lp>
+ inline __shared_count<_Lp>:: __shared_count(const __weak_count<_Lp>& __r)
+ : _M_pi(__r._M_pi)
+ {
+ if (_M_pi != 0)
+ _M_pi->_M_add_ref_lock();
+ else
+ __throw_bad_weak_ptr();
+ }
+
+
+ // Support for enable_shared_from_this.
+
+ // Friend of __enable_shared_from_this.
+ template<_Lock_policy _Lp, typename _Tp1, typename _Tp2>
+ void
+ __enable_shared_from_this_helper(const __shared_count<_Lp>&,
+ const __enable_shared_from_this<_Tp1,
+ _Lp>*, const _Tp2*);
+
+ // Friend of enable_shared_from_this.
+ template<typename _Tp1, typename _Tp2>
+ void
+ __enable_shared_from_this_helper(const __shared_count<>&,
+ const enable_shared_from_this<_Tp1>*,
+ const _Tp2*);
+
+ template<_Lock_policy _Lp>
+ inline void
+ __enable_shared_from_this_helper(const __shared_count<_Lp>&, ...)
+ { }
+
+
+ template<typename _Tp, _Lock_policy _Lp>
+ class __shared_ptr
+ {
+ public:
+ typedef _Tp element_type;
+
+ __shared_ptr() : _M_ptr(0), _M_refcount() // never throws
+ { }
+
+ template<typename _Tp1>
+ explicit __shared_ptr(_Tp1* __p) : _M_ptr(__p), _M_refcount(__p)
+ {
+ __glibcxx_function_requires(_ConvertibleConcept<_Tp1*, _Tp*>)
+ // __glibcxx_function_requires(_CompleteConcept<_Tp1*>)
+ __enable_shared_from_this_helper(_M_refcount, __p, __p);
+ }
+
+ template<typename _Tp1, typename _Deleter>
+ __shared_ptr(_Tp1* __p, _Deleter __d)
+ : _M_ptr(__p), _M_refcount(__p, __d)
+ {
+ __glibcxx_function_requires(_ConvertibleConcept<_Tp1*, _Tp*>)
+ // TODO requires _Deleter CopyConstructible and __d(__p) well-formed
+ __enable_shared_from_this_helper(_M_refcount, __p, __p);
+ }
+
+ template<typename _Tp1, typename _Deleter, typename _Alloc>
+ __shared_ptr(_Tp1* __p, _Deleter __d, const _Alloc& __a)
+ : _M_ptr(__p), _M_refcount(__p, __d, __a)
+ {
+ __glibcxx_function_requires(_ConvertibleConcept<_Tp1*, _Tp*>)
+ // TODO requires _Deleter CopyConstructible and __d(__p) well-formed
+ __enable_shared_from_this_helper(_M_refcount, __p, __p);
+ }
+
+ template<typename _Tp1>
+ __shared_ptr(const __shared_ptr<_Tp1, _Lp>& __r, _Tp* __p)
+ : _M_ptr(__p), _M_refcount(__r._M_refcount) // never throws
+ { }
+
+ // generated copy constructor, assignment, destructor are fine.
+
+ template<typename _Tp1>
+ __shared_ptr(const __shared_ptr<_Tp1, _Lp>& __r)
+ : _M_ptr(__r._M_ptr), _M_refcount(__r._M_refcount) // never throws
+ { __glibcxx_function_requires(_ConvertibleConcept<_Tp1*, _Tp*>) }
+
+ __shared_ptr(__shared_ptr&& __r)
+ : _M_ptr(__r._M_ptr), _M_refcount() // never throws
+ {
+ _M_refcount._M_swap(__r._M_refcount);
+ __r._M_ptr = 0;
+ }
+
+ template<typename _Tp1>
+ __shared_ptr(__shared_ptr<_Tp1, _Lp>&& __r)
+ : _M_ptr(__r._M_ptr), _M_refcount() // never throws
+ {
+ __glibcxx_function_requires(_ConvertibleConcept<_Tp1*, _Tp*>)
+ _M_refcount._M_swap(__r._M_refcount);
+ __r._M_ptr = 0;
+ }
+
+ template<typename _Tp1>
+ explicit __shared_ptr(const __weak_ptr<_Tp1, _Lp>& __r)
+ : _M_refcount(__r._M_refcount) // may throw
+ {
+ __glibcxx_function_requires(_ConvertibleConcept<_Tp1*, _Tp*>)
+
+ // It is now safe to copy __r._M_ptr, as
+ // _M_refcount(__r._M_refcount) did not throw.
+ _M_ptr = __r._M_ptr;
+ }
+
+ template<typename _Tp1, typename _Del>
+ explicit __shared_ptr(const std::unique_ptr<_Tp1, _Del>&) = delete;
+
+ // If an exception is thrown this constructor has no effect.
+ template<typename _Tp1, typename _Del>
+ explicit __shared_ptr(std::unique_ptr<_Tp1, _Del>&& __r)
+ : _M_ptr(__r.get()), _M_refcount()
+ {
+ __glibcxx_function_requires(_ConvertibleConcept<_Tp1*, _Tp*>)
+ _Tp1* __tmp = __r.get();
+ _M_refcount = __shared_count<_Lp>(std::move(__r));
+ __enable_shared_from_this_helper(_M_refcount, __tmp, __tmp);
+ }
+
+#if _GLIBCXX_DEPRECATED
+ // Postcondition: use_count() == 1 and __r.get() == 0
+ template<typename _Tp1>
+ explicit __shared_ptr(std::auto_ptr<_Tp1>&& __r)
+ : _M_ptr(__r.get()), _M_refcount()
+ {
+ __glibcxx_function_requires(_ConvertibleConcept<_Tp1*, _Tp*>)
+ // TODO requires _Tp1 is complete, delete __r.release() well-formed
+ _Tp1* __tmp = __r.get();
+ _M_refcount = __shared_count<_Lp>(std::move(__r));
+ __enable_shared_from_this_helper(_M_refcount, __tmp, __tmp);
+ }
+#endif
+
+ template<typename _Tp1>
+ __shared_ptr&
+ operator=(const __shared_ptr<_Tp1, _Lp>& __r) // never throws
+ {
+ _M_ptr = __r._M_ptr;
+ _M_refcount = __r._M_refcount; // __shared_count::op= doesn't throw
+ return *this;
+ }
+
+#if _GLIBCXX_DEPRECATED
+ template<typename _Tp1>
+ __shared_ptr&
+ operator=(std::auto_ptr<_Tp1>&& __r)
+ {
+ __shared_ptr(std::move(__r)).swap(*this);
+ return *this;
+ }
+#endif
+
+ __shared_ptr&
+ operator=(__shared_ptr&& __r)
+ {
+ __shared_ptr(std::move(__r)).swap(*this);
+ return *this;
+ }
+
+ template<class _Tp1>
+ __shared_ptr&
+ operator=(__shared_ptr<_Tp1, _Lp>&& __r)
+ {
+ __shared_ptr(std::move(__r)).swap(*this);
+ return *this;
+ }
+
+ template<typename _Tp1, typename _Del>
+ __shared_ptr&
+ operator=(const std::unique_ptr<_Tp1, _Del>& __r) = delete;
+
+ template<typename _Tp1, typename _Del>
+ __shared_ptr&
+ operator=(std::unique_ptr<_Tp1, _Del>&& __r)
+ {
+ __shared_ptr(std::move(__r)).swap(*this);
+ return *this;
+ }
+
+ void
+ reset() // never throws
+ { __shared_ptr().swap(*this); }
+
+ template<typename _Tp1>
+ void
+ reset(_Tp1* __p) // _Tp1 must be complete.
+ {
+ // Catch self-reset errors.
+ _GLIBCXX_DEBUG_ASSERT(__p == 0 || __p != _M_ptr);
+ __shared_ptr(__p).swap(*this);
+ }
+
+ template<typename _Tp1, typename _Deleter>
+ void
+ reset(_Tp1* __p, _Deleter __d)
+ { __shared_ptr(__p, __d).swap(*this); }
+
+ template<typename _Tp1, typename _Deleter, typename _Alloc>
+ void
+ reset(_Tp1* __p, _Deleter __d, const _Alloc& __a)
+ { __shared_ptr(__p, __d, __a).swap(*this); }
+
+ // Allow class instantiation when _Tp is [cv-qual] void.
+ typename std::add_lvalue_reference<_Tp>::type
+ operator*() const // never throws
+ {
+ _GLIBCXX_DEBUG_ASSERT(_M_ptr != 0);
+ return *_M_ptr;
+ }
+
+ _Tp*
+ operator->() const // never throws
+ {
+ _GLIBCXX_DEBUG_ASSERT(_M_ptr != 0);
+ return _M_ptr;
+ }
+
+ _Tp*
+ get() const // never throws
+ { return _M_ptr; }
+
+ explicit operator bool() const // never throws
+ { return _M_ptr == 0 ? false : true; }
+
+ bool
+ unique() const // never throws
+ { return _M_refcount._M_unique(); }
+
+ long
+ use_count() const // never throws
+ { return _M_refcount._M_get_use_count(); }
+
+ void
+ swap(__shared_ptr<_Tp, _Lp>& __other) // never throws
+ {
+ std::swap(_M_ptr, __other._M_ptr);
+ _M_refcount._M_swap(__other._M_refcount);
+ }
+
+ template<typename _Tp1>
+ bool
+ owner_before(__shared_ptr<_Tp1, _Lp> const& __rhs) const
+ { return _M_refcount._M_less(__rhs._M_refcount); }
+
+ template<typename _Tp1>
+ bool
+ owner_before(__weak_ptr<_Tp1, _Lp> const& __rhs) const
+ { return _M_refcount._M_less(__rhs._M_refcount); }
+
+ protected:
+ // This constructor is non-standard, it is used by allocate_shared.
+ template<typename _Alloc, typename... _Args>
+ __shared_ptr(_Sp_make_shared_tag __tag, _Alloc __a, _Args&&... __args)
+ : _M_ptr(), _M_refcount(__tag, (_Tp*)0, __a,
+ std::forward<_Args>(__args)...)
+ {
+ // _M_ptr needs to point to the newly constructed object.
+ // This relies on _Sp_counted_ptr_inplace::_M_get_deleter.
+ void* __p = _M_refcount._M_get_deleter(typeid(__tag));
+ _M_ptr = static_cast<_Tp*>(__p);
+ __enable_shared_from_this_helper(_M_refcount, _M_ptr, _M_ptr);
+ }
+
+ template<typename _Tp1, _Lock_policy _Lp1, typename _Alloc,
+ typename... _Args>
+ friend __shared_ptr<_Tp1, _Lp1>
+ __allocate_shared(_Alloc __a, _Args&&... __args);
+
+ private:
+ void*
+ _M_get_deleter(const std::type_info& __ti) const
+ { return _M_refcount._M_get_deleter(__ti); }
+
+ template<typename _Tp1, _Lock_policy _Lp1> friend class __shared_ptr;
+ template<typename _Tp1, _Lock_policy _Lp1> friend class __weak_ptr;
+
+ template<typename _Del, typename _Tp1, _Lock_policy _Lp1>
+ friend _Del* get_deleter(const __shared_ptr<_Tp1, _Lp1>&);
+
+ _Tp* _M_ptr; // Contained pointer.
+ __shared_count<_Lp> _M_refcount; // Reference counter.
+ };
+
+
+ // 20.8.13.2.7 shared_ptr comparisons
+ template<typename _Tp1, typename _Tp2, _Lock_policy _Lp>
+ inline bool
+ operator==(const __shared_ptr<_Tp1, _Lp>& __a,
+ const __shared_ptr<_Tp2, _Lp>& __b)
+ { return __a.get() == __b.get(); }
+
+ template<typename _Tp1, typename _Tp2, _Lock_policy _Lp>
+ inline bool
+ operator!=(const __shared_ptr<_Tp1, _Lp>& __a,
+ const __shared_ptr<_Tp2, _Lp>& __b)
+ { return __a.get() != __b.get(); }
+
+ template<typename _Tp1, typename _Tp2, _Lock_policy _Lp>
+ inline bool
+ operator<(const __shared_ptr<_Tp1, _Lp>& __a,
+ const __shared_ptr<_Tp2, _Lp>& __b)
+ { return __a.get() < __b.get(); }
+
+ template<typename _Sp>
+ struct _Sp_less : public binary_function<_Sp, _Sp, bool>
+ {
+ bool
+ operator()(const _Sp& __lhs, const _Sp& __rhs) const
+ {
+ typedef typename _Sp::element_type element_type;
+ return std::less<element_type*>()(__lhs.get(), __rhs.get());
+ }
+ };
+
+ template<typename _Tp, _Lock_policy _Lp>
+ struct less<__shared_ptr<_Tp, _Lp>>
+ : public _Sp_less<__shared_ptr<_Tp, _Lp>>
+ { };
+
+ // XXX LessThanComparable<_Tp> concept should provide >, >= and <=
+ template<typename _Tp, _Lock_policy _Lp>
+ inline bool
+ operator>(const __shared_ptr<_Tp, _Lp>& __a,
+ const __shared_ptr<_Tp, _Lp>& __b)
+ { return __a.get() > __b.get(); }
+
+ template<typename _Tp, _Lock_policy _Lp>
+ inline bool
+ operator>=(const __shared_ptr<_Tp, _Lp>& __a,
+ const __shared_ptr<_Tp, _Lp>& __b)
+ { return __a.get() >= __b.get(); }
+
+ template<typename _Tp, _Lock_policy _Lp>
+ inline bool
+ operator<=(const __shared_ptr<_Tp, _Lp>& __a,
+ const __shared_ptr<_Tp, _Lp>& __b)
+ { return __a.get() <= __b.get(); }
+
+ // 2.2.3.8 shared_ptr specialized algorithms.
+ template<typename _Tp, _Lock_policy _Lp>
+ inline void
+ swap(__shared_ptr<_Tp, _Lp>& __a, __shared_ptr<_Tp, _Lp>& __b)
+ { __a.swap(__b); }
+
+ // 2.2.3.9 shared_ptr casts
+
+ // The seemingly equivalent code:
+ // shared_ptr<_Tp, _Lp>(static_cast<_Tp*>(__r.get()))
+ // will eventually result in undefined behaviour, attempting to
+ // delete the same object twice.
+ /// static_pointer_cast
+ template<typename _Tp, typename _Tp1, _Lock_policy _Lp>
+ inline __shared_ptr<_Tp, _Lp>
+ static_pointer_cast(const __shared_ptr<_Tp1, _Lp>& __r)
+ { return __shared_ptr<_Tp, _Lp>(__r, static_cast<_Tp*>(__r.get())); }
+
+ // The seemingly equivalent code:
+ // shared_ptr<_Tp, _Lp>(const_cast<_Tp*>(__r.get()))
+ // will eventually result in undefined behaviour, attempting to
+ // delete the same object twice.
+ /// const_pointer_cast
+ template<typename _Tp, typename _Tp1, _Lock_policy _Lp>
+ inline __shared_ptr<_Tp, _Lp>
+ const_pointer_cast(const __shared_ptr<_Tp1, _Lp>& __r)
+ { return __shared_ptr<_Tp, _Lp>(__r, const_cast<_Tp*>(__r.get())); }
+
+ // The seemingly equivalent code:
+ // shared_ptr<_Tp, _Lp>(dynamic_cast<_Tp*>(__r.get()))
+ // will eventually result in undefined behaviour, attempting to
+ // delete the same object twice.
+ /// dynamic_pointer_cast
+ template<typename _Tp, typename _Tp1, _Lock_policy _Lp>
+ inline __shared_ptr<_Tp, _Lp>
+ dynamic_pointer_cast(const __shared_ptr<_Tp1, _Lp>& __r)
+ {
+ if (_Tp* __p = dynamic_cast<_Tp*>(__r.get()))
+ return __shared_ptr<_Tp, _Lp>(__r, __p);
+ return __shared_ptr<_Tp, _Lp>();
+ }
+
+
+ template<typename _Tp, _Lock_policy _Lp>
+ class __weak_ptr
+ {
+ public:
+ typedef _Tp element_type;
+
+ __weak_ptr() : _M_ptr(0), _M_refcount() // never throws
+ { }
+
+ // Generated copy constructor, assignment, destructor are fine.
+
+ // The "obvious" converting constructor implementation:
+ //
+ // template<typename _Tp1>
+ // __weak_ptr(const __weak_ptr<_Tp1, _Lp>& __r)
+ // : _M_ptr(__r._M_ptr), _M_refcount(__r._M_refcount) // never throws
+ // { }
+ //
+ // has a serious problem.
+ //
+ // __r._M_ptr may already have been invalidated. The _M_ptr(__r._M_ptr)
+ // conversion may require access to *__r._M_ptr (virtual inheritance).
+ //
+ // It is not possible to avoid spurious access violations since
+ // in multithreaded programs __r._M_ptr may be invalidated at any point.
+ template<typename _Tp1>
+ __weak_ptr(const __weak_ptr<_Tp1, _Lp>& __r)
+ : _M_refcount(__r._M_refcount) // never throws
+ {
+ __glibcxx_function_requires(_ConvertibleConcept<_Tp1*, _Tp*>)
+ _M_ptr = __r.lock().get();
+ }
+
+ template<typename _Tp1>
+ __weak_ptr(const __shared_ptr<_Tp1, _Lp>& __r)
+ : _M_ptr(__r._M_ptr), _M_refcount(__r._M_refcount) // never throws
+ { __glibcxx_function_requires(_ConvertibleConcept<_Tp1*, _Tp*>) }
+
+ template<typename _Tp1>
+ __weak_ptr&
+ operator=(const __weak_ptr<_Tp1, _Lp>& __r) // never throws
+ {
+ _M_ptr = __r.lock().get();
+ _M_refcount = __r._M_refcount;
+ return *this;
+ }
+
+ template<typename _Tp1>
+ __weak_ptr&
+ operator=(const __shared_ptr<_Tp1, _Lp>& __r) // never throws
+ {
+ _M_ptr = __r._M_ptr;
+ _M_refcount = __r._M_refcount;
+ return *this;
+ }
+
+ __shared_ptr<_Tp, _Lp>
+ lock() const // never throws
+ {
+#ifdef __GTHREADS
+ // Optimization: avoid throw overhead.
+ if (expired())
+ return __shared_ptr<element_type, _Lp>();
+
+ __try
+ {
+ return __shared_ptr<element_type, _Lp>(*this);
+ }
+ __catch(const bad_weak_ptr&)
+ {
+ // Q: How can we get here?
+ // A: Another thread may have invalidated r after the
+ // use_count test above.
+ return __shared_ptr<element_type, _Lp>();
+ }
+
+#else
+ // Optimization: avoid try/catch overhead when single threaded.
+ return expired() ? __shared_ptr<element_type, _Lp>()
+ : __shared_ptr<element_type, _Lp>(*this);
+
+#endif
+ } // XXX MT
+
+ long
+ use_count() const // never throws
+ { return _M_refcount._M_get_use_count(); }
+
+ bool
+ expired() const // never throws
+ { return _M_refcount._M_get_use_count() == 0; }
+
+ template<typename _Tp1>
+ bool
+ owner_before(const __shared_ptr<_Tp1, _Lp>& __rhs) const
+ { return _M_refcount._M_less(__rhs._M_refcount); }
+
+ template<typename _Tp1>
+ bool
+ owner_before(const __weak_ptr<_Tp1, _Lp>& __rhs) const
+ { return _M_refcount._M_less(__rhs._M_refcount); }
+
+ void
+ reset() // never throws
+ { __weak_ptr().swap(*this); }
+
+ void
+ swap(__weak_ptr& __s) // never throws
+ {
+ std::swap(_M_ptr, __s._M_ptr);
+ _M_refcount._M_swap(__s._M_refcount);
+ }
+
+ // Comparisons
+ template<typename _Tp1>
+ bool operator<(const __weak_ptr<_Tp1, _Lp>&) const = delete;
+
+ template<typename _Tp1>
+ bool operator<=(const __weak_ptr<_Tp1, _Lp>&) const = delete;
+
+ template<typename _Tp1>
+ bool operator>(const __weak_ptr<_Tp1, _Lp>&) const = delete;
+
+ template<typename _Tp1>
+ bool operator>=(const __weak_ptr<_Tp1, _Lp>&) const = delete;
+
+ private:
+ // Used by __enable_shared_from_this.
+ void
+ _M_assign(_Tp* __ptr, const __shared_count<_Lp>& __refcount)
+ {
+ _M_ptr = __ptr;
+ _M_refcount = __refcount;
+ }
+
+ template<typename _Tp1, _Lock_policy _Lp1> friend class __shared_ptr;
+ template<typename _Tp1, _Lock_policy _Lp1> friend class __weak_ptr;
+ friend class __enable_shared_from_this<_Tp, _Lp>;
+ friend class enable_shared_from_this<_Tp>;
+
+ _Tp* _M_ptr; // Contained pointer.
+ __weak_count<_Lp> _M_refcount; // Reference counter.
+ };
+
+ // 20.8.13.3.7 weak_ptr specialized algorithms.
+ template<typename _Tp, _Lock_policy _Lp>
+ inline void
+ swap(__weak_ptr<_Tp, _Lp>& __a, __weak_ptr<_Tp, _Lp>& __b)
+ { __a.swap(__b); }
+
+ template<typename _Tp, typename _Tp1>
+ struct _Sp_owner_less : public binary_function<_Tp, _Tp, bool>
+ {
+ bool
+ operator()(const _Tp& __lhs, const _Tp& __rhs) const
+ { return __lhs.owner_before(__rhs); }
+
+ bool
+ operator()(const _Tp& __lhs, const _Tp1& __rhs) const
+ { return __lhs.owner_before(__rhs); }
+
+ bool
+ operator()(const _Tp1& __lhs, const _Tp& __rhs) const
+ { return __lhs.owner_before(__rhs); }
+ };
+
+ template<typename _Tp, _Lock_policy _Lp>
+ struct owner_less<__shared_ptr<_Tp, _Lp>>
+ : public _Sp_owner_less<__shared_ptr<_Tp, _Lp>, __weak_ptr<_Tp, _Lp>>
+ { };
+
+ template<typename _Tp, _Lock_policy _Lp>
+ struct owner_less<__weak_ptr<_Tp, _Lp>>
+ : public _Sp_owner_less<__weak_ptr<_Tp, _Lp>, __shared_ptr<_Tp, _Lp>>
+ { };
+
+
+ template<typename _Tp, _Lock_policy _Lp>
+ class __enable_shared_from_this
+ {
+ protected:
+ __enable_shared_from_this() { }
+
+ __enable_shared_from_this(const __enable_shared_from_this&) { }
+
+ __enable_shared_from_this&
+ operator=(const __enable_shared_from_this&)
+ { return *this; }
+
+ ~__enable_shared_from_this() { }
+
+ public:
+ __shared_ptr<_Tp, _Lp>
+ shared_from_this()
+ { return __shared_ptr<_Tp, _Lp>(this->_M_weak_this); }
+
+ __shared_ptr<const _Tp, _Lp>
+ shared_from_this() const
+ { return __shared_ptr<const _Tp, _Lp>(this->_M_weak_this); }
+
+ private:
+ template<typename _Tp1>
+ void
+ _M_weak_assign(_Tp1* __p, const __shared_count<_Lp>& __n) const
+ { _M_weak_this._M_assign(__p, __n); }
+
+ template<typename _Tp1>
+ friend void
+ __enable_shared_from_this_helper(const __shared_count<_Lp>& __pn,
+ const __enable_shared_from_this* __pe,
+ const _Tp1* __px)
+ {
+ if (__pe != 0)
+ __pe->_M_weak_assign(const_cast<_Tp1*>(__px), __pn);
+ }
+
+ mutable __weak_ptr<_Tp, _Lp> _M_weak_this;
+ };
+
+
+ template<typename _Tp, _Lock_policy _Lp, typename _Alloc, typename... _Args>
+ inline __shared_ptr<_Tp, _Lp>
+ __allocate_shared(_Alloc __a, _Args&&... __args)
+ {
+ return __shared_ptr<_Tp, _Lp>(_Sp_make_shared_tag(),
+ std::forward<_Alloc>(__a), std::forward<_Args>(__args)...);
+ }
+
+ template<typename _Tp, _Lock_policy _Lp, typename... _Args>
+ inline __shared_ptr<_Tp, _Lp>
+ __make_shared(_Args&&... __args)
+ {
+ typedef typename std::remove_const<_Tp>::type _Tp_nc;
+ return __allocate_shared<_Tp, _Lp>(std::allocator<_Tp_nc>(),
+ std::forward<_Args>(__args)...);
+ }
+
+_GLIBCXX_END_NAMESPACE
+
+#endif // _SHARED_PTR_BASE_H
diff --git a/libstdc++-v3/include/bits/stl_algo.h b/libstdc++-v3/include/bits/stl_algo.h
index a745295e9b0..9b6f2afb9ec 100644
--- a/libstdc++-v3/include/bits/stl_algo.h
+++ b/libstdc++-v3/include/bits/stl_algo.h
@@ -1647,53 +1647,64 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
typedef typename iterator_traits<_RandomAccessIterator>::value_type
_ValueType;
- const _Distance __n = __last - __first;
- const _Distance __k = __middle - __first;
- const _Distance __l = __n - __k;
+ _Distance __n = __last - __first;
+ _Distance __k = __middle - __first;
- if (__k == __l)
+ if (__k == __n - __k)
{
std::swap_ranges(__first, __middle, __middle);
return;
}
- const _Distance __d = std::__gcd(__n, __k);
+ _RandomAccessIterator __p = __first;
- for (_Distance __i = 0; __i < __d; __i++)
+ for (;;)
{
- _ValueType __tmp = _GLIBCXX_MOVE(*__first);
- _RandomAccessIterator __p = __first;
-
- if (__k < __l)
+ if (__k < __n - __k)
{
- for (_Distance __j = 0; __j < __l / __d; __j++)
+ if (__is_pod(_ValueType) && __k == 1)
+ {
+ _ValueType __t = _GLIBCXX_MOVE(*__p);
+ _GLIBCXX_MOVE3(__p + 1, __p + __n, __p);
+ *(__p + __n - 1) = _GLIBCXX_MOVE(__t);
+ return;
+ }
+ _RandomAccessIterator __q = __p + __k;
+ for (_Distance __i = 0; __i < __n - __k; ++ __i)
{
- if (__p > __first + __l)
- {
- *__p = _GLIBCXX_MOVE(*(__p - __l));
- __p -= __l;
- }
-
- *__p = _GLIBCXX_MOVE(*(__p + __k));
- __p += __k;
+ std::iter_swap(__p, __q);
+ ++__p;
+ ++__q;
}
+ __n %= __k;
+ if (__n == 0)
+ return;
+ std::swap(__n, __k);
+ __k = __n - __k;
}
else
{
- for (_Distance __j = 0; __j < __k / __d - 1; __j ++)
+ __k = __n - __k;
+ if (__is_pod(_ValueType) && __k == 1)
{
- if (__p < __last - __k)
- {
- *__p = _GLIBCXX_MOVE(*(__p + __k));
- __p += __k;
- }
- *__p = _GLIBCXX_MOVE(*(__p - __l));
- __p -= __l;
+ _ValueType __t = _GLIBCXX_MOVE(*(__p + __n - 1));
+ _GLIBCXX_MOVE_BACKWARD3(__p, __p + __n - 1, __p + __n);
+ *__p = _GLIBCXX_MOVE(__t);
+ return;
}
+ _RandomAccessIterator __q = __p + __n;
+ __p = __q - __k;
+ for (_Distance __i = 0; __i < __n - __k; ++ __i)
+ {
+ --__p;
+ --__q;
+ std::iter_swap(__p, __q);
+ }
+ __n %= __k;
+ if (__n == 0)
+ return;
+ std::swap(__n, __k);
}
-
- *__p = _GLIBCXX_MOVE(__tmp);
- ++__first;
}
}
@@ -1862,15 +1873,15 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
for (; __first != __last; ++__first)
if (__pred(*__first))
{
- *__result1 = *__first;
+ *__result1 = _GLIBCXX_MOVE(*__first);
++__result1;
}
else
{
- *__result2 = *__first;
+ *__result2 = _GLIBCXX_MOVE(*__first);
++__result2;
}
- std::copy(__buffer, __result2, __result1);
+ _GLIBCXX_MOVE3(__buffer, __result2, __result1);
return __result1;
}
else
@@ -2926,15 +2937,15 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
_BidirectionalIterator2 __buffer_end;
if (__len1 > __len2 && __len2 <= __buffer_size)
{
- __buffer_end = std::copy(__middle, __last, __buffer);
- std::copy_backward(__first, __middle, __last);
- return std::copy(__buffer, __buffer_end, __first);
+ __buffer_end = _GLIBCXX_MOVE3(__middle, __last, __buffer);
+ _GLIBCXX_MOVE_BACKWARD3(__first, __middle, __last);
+ return _GLIBCXX_MOVE3(__buffer, __buffer_end, __first);
}
else if (__len1 <= __buffer_size)
{
- __buffer_end = std::copy(__first, __middle, __buffer);
- std::copy(__middle, __last, __first);
- return std::copy_backward(__buffer, __buffer_end, __last);
+ __buffer_end = _GLIBCXX_MOVE3(__first, __middle, __buffer);
+ _GLIBCXX_MOVE3(__middle, __last, __first);
+ return _GLIBCXX_MOVE_BACKWARD3(__buffer, __buffer_end, __last);
}
else
{
@@ -2956,15 +2967,21 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
{
if (__len1 <= __len2 && __len1 <= __buffer_size)
{
- _Pointer __buffer_end = std::copy(__first, __middle, __buffer);
- _GLIBCXX_STD_P::merge(__buffer, __buffer_end, __middle, __last,
+ _Pointer __buffer_end = _GLIBCXX_MOVE3(__first, __middle, __buffer);
+ _GLIBCXX_STD_P::merge(_GLIBCXX_MAKE_MOVE_ITERATOR(__buffer),
+ _GLIBCXX_MAKE_MOVE_ITERATOR(__buffer_end),
+ _GLIBCXX_MAKE_MOVE_ITERATOR(__middle),
+ _GLIBCXX_MAKE_MOVE_ITERATOR(__last),
__first);
}
else if (__len2 <= __buffer_size)
{
- _Pointer __buffer_end = std::copy(__middle, __last, __buffer);
- std::__merge_backward(__first, __middle, __buffer,
- __buffer_end, __last);
+ _Pointer __buffer_end = _GLIBCXX_MOVE3(__middle, __last, __buffer);
+ std::__merge_backward(_GLIBCXX_MAKE_MOVE_ITERATOR(__first),
+ _GLIBCXX_MAKE_MOVE_ITERATOR(__middle),
+ _GLIBCXX_MAKE_MOVE_ITERATOR(__buffer),
+ _GLIBCXX_MAKE_MOVE_ITERATOR(__buffer_end),
+ __last);
}
else
{
@@ -3013,15 +3030,21 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
{
if (__len1 <= __len2 && __len1 <= __buffer_size)
{
- _Pointer __buffer_end = std::copy(__first, __middle, __buffer);
- _GLIBCXX_STD_P::merge(__buffer, __buffer_end, __middle, __last,
+ _Pointer __buffer_end = _GLIBCXX_MOVE3(__first, __middle, __buffer);
+ _GLIBCXX_STD_P::merge(_GLIBCXX_MAKE_MOVE_ITERATOR(__buffer),
+ _GLIBCXX_MAKE_MOVE_ITERATOR(__buffer_end),
+ _GLIBCXX_MAKE_MOVE_ITERATOR(__middle),
+ _GLIBCXX_MAKE_MOVE_ITERATOR(__last),
__first, __comp);
}
else if (__len2 <= __buffer_size)
{
- _Pointer __buffer_end = std::copy(__middle, __last, __buffer);
- std::__merge_backward(__first, __middle, __buffer, __buffer_end,
- __last, __comp);
+ _Pointer __buffer_end = _GLIBCXX_MOVE3(__middle, __last, __buffer);
+ std::__merge_backward(_GLIBCXX_MAKE_MOVE_ITERATOR(__first),
+ _GLIBCXX_MAKE_MOVE_ITERATOR(__middle),
+ _GLIBCXX_MAKE_MOVE_ITERATOR(__buffer),
+ _GLIBCXX_MAKE_MOVE_ITERATOR(__buffer_end),
+ __last,__comp);
}
else
{
@@ -3270,16 +3293,22 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
while (__last - __first >= __two_step)
{
- __result = _GLIBCXX_STD_P::merge(__first, __first + __step_size,
- __first + __step_size,
- __first + __two_step,
- __result);
+ __result = _GLIBCXX_STD_P::merge(
+ _GLIBCXX_MAKE_MOVE_ITERATOR(__first),
+ _GLIBCXX_MAKE_MOVE_ITERATOR(__first + __step_size),
+ _GLIBCXX_MAKE_MOVE_ITERATOR(__first + __step_size),
+ _GLIBCXX_MAKE_MOVE_ITERATOR(__first + __two_step),
+ __result);
__first += __two_step;
}
__step_size = std::min(_Distance(__last - __first), __step_size);
- _GLIBCXX_STD_P::merge(__first, __first + __step_size,
- __first + __step_size, __last,
+ _GLIBCXX_STD_P::merge(_GLIBCXX_MAKE_MOVE_ITERATOR(__first),
+ _GLIBCXX_MAKE_MOVE_ITERATOR(__first +
+ __step_size),
+ _GLIBCXX_MAKE_MOVE_ITERATOR(__first +
+ __step_size),
+ _GLIBCXX_MAKE_MOVE_ITERATOR(__last),
__result);
}
@@ -3295,16 +3324,23 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
while (__last - __first >= __two_step)
{
- __result = _GLIBCXX_STD_P::merge(__first, __first + __step_size,
- __first + __step_size, __first + __two_step,
- __result,
- __comp);
+ __result = _GLIBCXX_STD_P::merge(
+ _GLIBCXX_MAKE_MOVE_ITERATOR(__first),
+ _GLIBCXX_MAKE_MOVE_ITERATOR(__first + __step_size),
+ _GLIBCXX_MAKE_MOVE_ITERATOR(__first + __step_size),
+ _GLIBCXX_MAKE_MOVE_ITERATOR(__first + __two_step),
+ __result, __comp);
__first += __two_step;
}
__step_size = std::min(_Distance(__last - __first), __step_size);
- _GLIBCXX_STD_P::merge(__first, __first + __step_size,
- __first + __step_size, __last, __result, __comp);
+ _GLIBCXX_STD_P::merge(_GLIBCXX_MAKE_MOVE_ITERATOR(__first),
+ _GLIBCXX_MAKE_MOVE_ITERATOR(__first +
+ __step_size),
+ _GLIBCXX_MAKE_MOVE_ITERATOR(__first +
+ __step_size),
+ _GLIBCXX_MAKE_MOVE_ITERATOR(__last),
+ __result, __comp);
}
template<typename _RandomAccessIterator, typename _Distance>
diff --git a/libstdc++-v3/include/bits/stl_algobase.h b/libstdc++-v3/include/bits/stl_algobase.h
index c638c547887..f9c3ab2b428 100644
--- a/libstdc++-v3/include/bits/stl_algobase.h
+++ b/libstdc++-v3/include/bits/stl_algobase.h
@@ -998,7 +998,7 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_P)
}
/**
- * @brief Performs "dictionary" comparison on ranges.
+ * @brief Performs 'dictionary' comparison on ranges.
* @ingroup sorting_algorithms
* @param first1 An input iterator.
* @param last1 An input iterator.
@@ -1006,9 +1006,9 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_P)
* @param last2 An input iterator.
* @return A boolean true or false.
*
- * "Returns true if the sequence of elements defined by the range
+ * 'Returns true if the sequence of elements defined by the range
* [first1,last1) is lexicographically less than the sequence of elements
- * defined by the range [first2,last2). Returns false otherwise."
+ * defined by the range [first2,last2). Returns false otherwise.'
* (Quoted from [25.3.8]/1.) If the iterators are all character pointers,
* then this is an inline call to @c memcmp.
*/
diff --git a/libstdc++-v3/include/bits/stl_iterator.h b/libstdc++-v3/include/bits/stl_iterator.h
index eb7290053ed..a60fea60a6b 100644
--- a/libstdc++-v3/include/bits/stl_iterator.h
+++ b/libstdc++-v3/include/bits/stl_iterator.h
@@ -67,9 +67,14 @@
_GLIBCXX_BEGIN_NAMESPACE(std)
+ /**
+ * @addtogroup iterators
+ * @{
+ */
+
// 24.4.1 Reverse iterators
/**
- * "Bidirectional and random access iterators have corresponding reverse
+ * 'Bidirectional and random access iterators have corresponding reverse
* %iterator adaptors that iterate through the data structure in the
* opposite direction. They have the same signatures as the corresponding
* iterators. The fundamental relation between a reverse %iterator and its
@@ -80,7 +85,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
*
* This mapping is dictated by the fact that while there is always a
* pointer past the end of an array, there might not be a valid pointer
- * before the beginning of an array." [24.4.1]/1,2
+ * before the beginning of an array.' [24.4.1]/1,2
*
* Reverse iterators can be tricky and surprising at first. Their
* semantics make sense, however, and the trickiness is a side effect of
@@ -97,14 +102,14 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
protected:
_Iterator current;
- public:
- typedef _Iterator iterator_type;
- typedef typename iterator_traits<_Iterator>::difference_type
- difference_type;
- typedef typename iterator_traits<_Iterator>::reference reference;
- typedef typename iterator_traits<_Iterator>::pointer pointer;
+ typedef iterator_traits<_Iterator> __traits_type;
public:
+ typedef _Iterator iterator_type;
+ typedef typename __traits_type::difference_type difference_type;
+ typedef typename __traits_type::pointer pointer;
+ typedef typename __traits_type::reference reference;
+
/**
* The default constructor default-initializes member @p current.
* If it is a pointer, that means it is zero-initialized.
@@ -651,6 +656,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
typename _Container::iterator(__i));
}
+ // @} group iterators
+
_GLIBCXX_END_NAMESPACE
_GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
@@ -670,15 +677,15 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
protected:
_Iterator _M_current;
+ typedef iterator_traits<_Iterator> __traits_type;
+
public:
- typedef _Iterator iterator_type;
- typedef typename iterator_traits<_Iterator>::iterator_category
- iterator_category;
- typedef typename iterator_traits<_Iterator>::value_type value_type;
- typedef typename iterator_traits<_Iterator>::difference_type
- difference_type;
- typedef typename iterator_traits<_Iterator>::reference reference;
- typedef typename iterator_traits<_Iterator>::pointer pointer;
+ typedef _Iterator iterator_type;
+ typedef typename __traits_type::iterator_category iterator_category;
+ typedef typename __traits_type::value_type value_type;
+ typedef typename __traits_type::difference_type difference_type;
+ typedef typename __traits_type::reference reference;
+ typedef typename __traits_type::pointer pointer;
__normal_iterator() : _M_current(_Iterator()) { }
@@ -869,6 +876,11 @@ _GLIBCXX_END_NAMESPACE
_GLIBCXX_BEGIN_NAMESPACE(std)
+ /**
+ * @addtogroup iterators
+ * @{
+ */
+
// 24.4.3 Move iterators
/**
* Class template move_iterator is an iterator adapter with the same
@@ -884,18 +896,17 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
protected:
_Iterator _M_current;
+ typedef iterator_traits<_Iterator> __traits_type;
+
public:
- typedef _Iterator iterator_type;
- typedef typename iterator_traits<_Iterator>::difference_type
- difference_type;
+ typedef _Iterator iterator_type;
+ typedef typename __traits_type::iterator_category iterator_category;
+ typedef typename __traits_type::value_type value_type;
+ typedef typename __traits_type::difference_type difference_type;
// NB: DR 680.
- typedef _Iterator pointer;
- typedef typename iterator_traits<_Iterator>::value_type value_type;
- typedef typename iterator_traits<_Iterator>::iterator_category
- iterator_category;
- typedef value_type&& reference;
+ typedef _Iterator pointer;
+ typedef value_type&& reference;
- public:
move_iterator()
: _M_current() { }
@@ -1031,6 +1042,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
make_move_iterator(const _Iterator& __i)
{ return move_iterator<_Iterator>(__i); }
+ // @} group iterators
+
_GLIBCXX_END_NAMESPACE
#define _GLIBCXX_MAKE_MOVE_ITERATOR(_Iter) std::make_move_iterator(_Iter)
diff --git a/libstdc++-v3/include/bits/stl_iterator_base_funcs.h b/libstdc++-v3/include/bits/stl_iterator_base_funcs.h
index 0a854faa14c..b629ca20231 100644
--- a/libstdc++-v3/include/bits/stl_iterator_base_funcs.h
+++ b/libstdc++-v3/include/bits/stl_iterator_base_funcs.h
@@ -173,10 +173,10 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
}
#ifdef __GXX_EXPERIMENTAL_CXX0X__
- template<typename _InputIterator>
- inline _InputIterator
- next(_InputIterator __x, typename
- iterator_traits<_InputIterator>::difference_type __n = 1)
+ template<typename _ForwardIterator>
+ inline _ForwardIterator
+ next(_ForwardIterator __x, typename
+ iterator_traits<_ForwardIterator>::difference_type __n = 1)
{
std::advance(__x, __n);
return __x;
diff --git a/libstdc++-v3/include/bits/stl_iterator_base_types.h b/libstdc++-v3/include/bits/stl_iterator_base_types.h
index 6dc0d7838d3..d2bf647f058 100644
--- a/libstdc++-v3/include/bits/stl_iterator_base_types.h
+++ b/libstdc++-v3/include/bits/stl_iterator_base_types.h
@@ -77,15 +77,19 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
//@{
/// Marking input iterators.
struct input_iterator_tag { };
+
/// Marking output iterators.
struct output_iterator_tag { };
+
/// Forward iterators support a superset of input iterator operations.
struct forward_iterator_tag : public input_iterator_tag { };
+
/// Bidirectional iterators support a superset of forward iterator
/// operations.
struct bidirectional_iterator_tag : public forward_iterator_tag { };
- /// Random-access iterators support a superset of bidirectional iterator
- /// operations.
+
+ /// Random-access iterators support a superset of bidirectional
+ /// iterator operations.
struct random_access_iterator_tag : public bidirectional_iterator_tag { };
@@ -116,6 +120,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
};
/**
+ * @brief Traits class for iterators.
+ *
* This class does nothing but define nested typedefs. The general
* version simply "forwards" the nested typedefs from the Iterator
* argument. Specialized versions for pointers and pointers-to-const
@@ -131,6 +137,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
typedef typename _Iterator::reference reference;
};
+ /// Partial specialization for pointer types.
template<typename _Tp>
struct iterator_traits<_Tp*>
{
@@ -141,6 +148,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
typedef _Tp& reference;
};
+ /// Partial specialization for const pointer types.
template<typename _Tp>
struct iterator_traits<const _Tp*>
{
diff --git a/libstdc++-v3/include/bits/stl_pair.h b/libstdc++-v3/include/bits/stl_pair.h
index d6c590186d6..4a9fb6be485 100644
--- a/libstdc++-v3/include/bits/stl_pair.h
+++ b/libstdc++-v3/include/bits/stl_pair.h
@@ -60,6 +60,10 @@
#include <bits/move.h> // for std::move / std::forward, std::decay, and
// std::swap
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+#include <type_traits>
+#endif
+
_GLIBCXX_BEGIN_NAMESPACE(std)
/// pair holds two objects of arbitrary type.
@@ -84,7 +88,22 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
: first(__a), second(__b) { }
#ifdef __GXX_EXPERIMENTAL_CXX0X__
- template<class _U1, class _U2>
+ // DR 811.
+ template<class _U1, class = typename
+ std::enable_if<std::is_convertible<_U1, _T1>::value>::type>
+ pair(_U1&& __x, const _T2& __y)
+ : first(std::forward<_U1>(__x)),
+ second(__y) { }
+
+ template<class _U2, class = typename
+ std::enable_if<std::is_convertible<_U2, _T2>::value>::type>
+ pair(const _T1& __x, _U2&& __y)
+ : first(__x),
+ second(std::forward<_U2>(__y)) { }
+
+ template<class _U1, class _U2, class = typename
+ std::enable_if<std::is_convertible<_U1, _T1>::value
+ && std::is_convertible<_U2, _T2>::value>::type>
pair(_U1&& __x, _U2&& __y)
: first(std::forward<_U1>(__x)),
second(std::forward<_U2>(__y)) { }
@@ -106,13 +125,6 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
: first(std::move(__p.first)),
second(std::move(__p.second)) { }
- // http://gcc.gnu.org/ml/libstdc++/2007-08/msg00052.html
- template<class _U1, class _Arg0, class... _Args>
- pair(_U1&& __x, _Arg0&& __arg0, _Args&&... __args)
- : first(std::forward<_U1>(__x)),
- second(std::forward<_Arg0>(__arg0),
- std::forward<_Args>(__args)...) { }
-
pair&
operator=(pair&& __p)
{
diff --git a/libstdc++-v3/include/bits/stl_tempbuf.h b/libstdc++-v3/include/bits/stl_tempbuf.h
index 2b887912a10..27b58bf5f81 100644
--- a/libstdc++-v3/include/bits/stl_tempbuf.h
+++ b/libstdc++-v3/include/bits/stl_tempbuf.h
@@ -72,9 +72,9 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
*
* This function tries to obtain storage for @c len adjacent Tp
* objects. The objects themselves are not constructed, of course.
- * A pair<> is returned containing "the buffer s address and
+ * A pair<> is returned containing 'the buffer s address and
* capacity (in the units of sizeof(Tp)), or a pair of 0 values if
- * no storage can be obtained." Note that the capacity obtained
+ * no storage can be obtained.' Note that the capacity obtained
* may be less than that requested if the memory is unavailable;
* you should compare len with the .second return value.
*
diff --git a/libstdc++-v3/include/bits/stream_iterator.h b/libstdc++-v3/include/bits/stream_iterator.h
index fce6c26d1a5..90f1b552b60 100644
--- a/libstdc++-v3/include/bits/stream_iterator.h
+++ b/libstdc++-v3/include/bits/stream_iterator.h
@@ -36,6 +36,11 @@
_GLIBCXX_BEGIN_NAMESPACE(std)
+ /**
+ * @addtogroup iterators
+ * @{
+ */
+
/// Provides input iterator semantics for streams.
template<typename _Tp, typename _CharT = char,
typename _Traits = char_traits<_CharT>, typename _Dist = ptrdiff_t>
@@ -206,6 +211,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
{ return *this; }
};
+ // @} group iterators
+
_GLIBCXX_END_NAMESPACE
#endif
diff --git a/libstdc++-v3/include/bits/streambuf_iterator.h b/libstdc++-v3/include/bits/streambuf_iterator.h
index d02b555343a..71c323035a2 100644
--- a/libstdc++-v3/include/bits/streambuf_iterator.h
+++ b/libstdc++-v3/include/bits/streambuf_iterator.h
@@ -39,6 +39,11 @@
_GLIBCXX_BEGIN_NAMESPACE(std)
+ /**
+ * @addtogroup iterators
+ * @{
+ */
+
// 24.5.3 Template class istreambuf_iterator
/// Provides input iterator semantics for streambufs.
template<typename _CharT, typename _Traits>
@@ -387,6 +392,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
return __first;
}
+// @} group iterators
+
_GLIBCXX_END_NAMESPACE
#endif
diff --git a/libstdc++-v3/include/bits/valarray_array.h b/libstdc++-v3/include/bits/valarray_array.h
index 492891bc9d8..a12b3347b9d 100644
--- a/libstdc++-v3/include/bits/valarray_array.h
+++ b/libstdc++-v3/include/bits/valarray_array.h
@@ -1,7 +1,7 @@
// The template and inlines for the -*- C++ -*- internal _Array helper class.
// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
-// 2006, 2007, 2009
+// 2006, 2007, 2008, 2009
// Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
@@ -73,7 +73,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
// Please note that this isn't exception safe. But
// valarrays aren't required to be exception safe.
inline static void
- _S_do_it(_Tp* __restrict__ __b, _Tp* __restrict__ __e)
+ _S_do_it(_Tp* __b, _Tp* __e)
{
while (__b != __e)
new(__b++) _Tp();
@@ -85,13 +85,13 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
{
// For fundamental types, it suffices to say 'memset()'
inline static void
- _S_do_it(_Tp* __restrict__ __b, _Tp* __restrict__ __e)
+ _S_do_it(_Tp* __b, _Tp* __e)
{ __builtin_memset(__b, 0, (__e - __b) * sizeof(_Tp)); }
};
template<typename _Tp>
inline void
- __valarray_default_construct(_Tp* __restrict__ __b, _Tp* __restrict__ __e)
+ __valarray_default_construct(_Tp* __b, _Tp* __e)
{
_Array_default_ctor<_Tp, __is_scalar<_Tp>::__value>::_S_do_it(__b, __e);
}
@@ -105,7 +105,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
// Please note that this isn't exception safe. But
// valarrays aren't required to be exception safe.
inline static void
- _S_do_it(_Tp* __restrict__ __b, _Tp* __restrict__ __e, const _Tp __t)
+ _S_do_it(_Tp* __b, _Tp* __e, const _Tp __t)
{
while (__b != __e)
new(__b++) _Tp(__t);
@@ -116,7 +116,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
struct _Array_init_ctor<_Tp, true>
{
inline static void
- _S_do_it(_Tp* __restrict__ __b, _Tp* __restrict__ __e, const _Tp __t)
+ _S_do_it(_Tp* __b, _Tp* __e, const _Tp __t)
{
while (__b != __e)
*__b++ = __t;
@@ -125,8 +125,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
template<typename _Tp>
inline void
- __valarray_fill_construct(_Tp* __restrict__ __b, _Tp* __restrict__ __e,
- const _Tp __t)
+ __valarray_fill_construct(_Tp* __b, _Tp* __e, const _Tp __t)
{
_Array_init_ctor<_Tp, __is_pod(_Tp)>::_S_do_it(__b, __e, __t);
}
@@ -141,8 +140,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
// Please note that this isn't exception safe. But
// valarrays aren't required to be exception safe.
inline static void
- _S_do_it(const _Tp* __restrict__ __b, const _Tp* __restrict__ __e,
- _Tp* __restrict__ __o)
+ _S_do_it(const _Tp* __b, const _Tp* __e, _Tp* __restrict__ __o)
{
while (__b != __e)
new(__o++) _Tp(*__b++);
@@ -153,15 +151,13 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
struct _Array_copy_ctor<_Tp, true>
{
inline static void
- _S_do_it(const _Tp* __restrict__ __b, const _Tp* __restrict__ __e,
- _Tp* __restrict__ __o)
+ _S_do_it(const _Tp* __b, const _Tp* __e, _Tp* __restrict__ __o)
{ __builtin_memcpy(__o, __b, (__e - __b) * sizeof(_Tp)); }
};
template<typename _Tp>
inline void
- __valarray_copy_construct(const _Tp* __restrict__ __b,
- const _Tp* __restrict__ __e,
+ __valarray_copy_construct(const _Tp* __b, const _Tp* __e,
_Tp* __restrict__ __o)
{
_Array_copy_ctor<_Tp, __is_pod(_Tp)>::_S_do_it(__b, __e, __o);
@@ -205,7 +201,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
// Do the necessary cleanup when we're done with arrays.
template<typename _Tp>
inline void
- __valarray_destroy_elements(_Tp* __restrict__ __b, _Tp* __restrict__ __e)
+ __valarray_destroy_elements(_Tp* __b, _Tp* __e)
{
if (!__is_pod(_Tp))
while (__b != __e)
@@ -347,7 +343,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
//
template<typename _Tp>
inline _Tp
- __valarray_sum(const _Tp* __restrict__ __f, const _Tp* __restrict__ __l)
+ __valarray_sum(const _Tp* __f, const _Tp* __l)
{
_Tp __r = _Tp();
while (__f != __l)
@@ -358,8 +354,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
// Compute the product of all elements in range [__f, __l)
template<typename _Tp>
inline _Tp
- __valarray_product(const _Tp* __restrict__ __f,
- const _Tp* __restrict__ __l)
+ __valarray_product(const _Tp* __f, const _Tp* __l)
{
_Tp __r = _Tp(1);
while (__f != __l)