// shared_ptr and weak_ptr implementation details -*- C++ -*-
-// Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012
-// Free Software Foundation, Inc.
+// Copyright (C) 2007-2013 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
{
_GLIBCXX_BEGIN_NAMESPACE_VERSION
+#if _GLIBCXX_USE_DEPRECATED
+ template<typename> class auto_ptr;
+#endif
+
/**
* @brief Exception possibly thrown by @c shared_ptr.
* @ingroup exceptions
// Substitute for bad_weak_ptr object in the case of -fno-exceptions.
inline void
__throw_bad_weak_ptr()
- {
-#if __EXCEPTIONS
- throw bad_weak_ptr();
-#else
- __builtin_abort();
-#endif
- }
+ { _GLIBCXX_THROW_OR_ABORT(bad_weak_ptr()); }
using __gnu_cxx::_Lock_policy;
using __gnu_cxx::__default_lock_policy;
// Special case for auto_ptr<_Tp> to provide the strong guarantee.
template<typename _Tp>
explicit
- __shared_count(std::auto_ptr<_Tp>&& __r)
- : _M_pi(new _Sp_counted_ptr<_Tp*, _Lp>(__r.get()))
- { __r.release(); }
+ __shared_count(std::auto_ptr<_Tp>&& __r);
#endif
// Special case for unique_ptr<_Tp,_Del> to provide the strong guarantee.
_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<void>,
+ typedef typename unique_ptr<_Tp, _Del>::pointer _Ptr;
+ return new _Sp_counted_deleter<_Ptr, _Del, std::allocator<void>,
_Lp>(__r.get(), __r.get_deleter());
}
_S_create_from_up(std::unique_ptr<_Tp, _Del>&& __r,
typename std::enable_if<std::is_reference<_Del>::value>::type* = 0)
{
+ typedef typename unique_ptr<_Tp, _Del>::pointer _Ptr;
typedef typename std::remove_reference<_Del>::type _Del1;
typedef std::reference_wrapper<_Del1> _Del2;
- return new _Sp_counted_deleter<_Tp*, _Del2, std::allocator<void>,
+ return new _Sp_counted_deleter<_Ptr, _Del2, std::allocator<void>,
_Lp>(__r.get(), std::ref(__r.get_deleter()));
}
: _M_ptr(__r.get()), _M_refcount()
{
__glibcxx_function_requires(_ConvertibleConcept<_Tp1*, _Tp*>)
- _Tp1* __tmp = __r.get();
+ auto __tmp = std::__addressof(*__r.get());
_M_refcount = __shared_count<_Lp>(std::move(__r));
__enable_shared_from_this_helper(_M_refcount, __tmp, __tmp);
}
#if _GLIBCXX_USE_DEPRECATED
// Postcondition: use_count() == 1 and __r.get() == 0
template<typename _Tp1>
- __shared_ptr(std::auto_ptr<_Tp1>&& __r)
- : _M_ptr(__r.get()), _M_refcount()
- {
- __glibcxx_function_requires(_ConvertibleConcept<_Tp1*, _Tp*>)
- static_assert( sizeof(_Tp1) > 0, "incomplete type" );
- _Tp1* __tmp = __r.get();
- _M_refcount = __shared_count<_Lp>(std::move(__r));
- __enable_shared_from_this_helper(_M_refcount, __tmp, __tmp);
- }
+ __shared_ptr(std::auto_ptr<_Tp1>&& __r);
#endif
/* TODO: use delegating constructor */
};
- // 20.8.13.2.7 shared_ptr comparisons
+ // 20.7.2.2.7 shared_ptr comparisons
template<typename _Tp1, typename _Tp2, _Lock_policy _Lp>
inline bool
operator==(const __shared_ptr<_Tp1, _Lp>& __a,
__weak_count<_Lp> _M_refcount; // Reference counter.
};
- // 20.8.13.3.7 weak_ptr specialized algorithms.
+ // 20.7.2.3.6 weak_ptr specialized algorithms.
template<typename _Tp, _Lock_policy _Lp>
inline void
swap(__weak_ptr<_Tp, _Lp>& __a, __weak_ptr<_Tp, _Lp>& __b) noexcept