summaryrefslogtreecommitdiff
path: root/libcxx/include/memory
diff options
context:
space:
mode:
Diffstat (limited to 'libcxx/include/memory')
-rw-r--r--libcxx/include/memory161
1 files changed, 71 insertions, 90 deletions
diff --git a/libcxx/include/memory b/libcxx/include/memory
index 96bb8fb5ccbba..34c3e0c0d8d1e 100644
--- a/libcxx/include/memory
+++ b/libcxx/include/memory
@@ -1098,40 +1098,51 @@ struct __const_void_pointer<_Ptr, _Alloc, false>
#endif
};
+
+template <bool _UsePointerTraits> struct __to_address_helper;
+
+template <> struct __to_address_helper<true> {
+ template <class _Pointer>
+ using __return_type = decltype(pointer_traits<_Pointer>::to_address(std::declval<const _Pointer&>()));
+
+ template <class _Pointer>
+ _LIBCPP_CONSTEXPR
+ static __return_type<_Pointer>
+ __do_it(const _Pointer &__p) _NOEXCEPT { return pointer_traits<_Pointer>::to_address(__p); }
+};
+
+template <class _Pointer, bool _Dummy = true>
+using __choose_to_address = __to_address_helper<_IsValidExpansion<__to_address_helper<_Dummy>::template __return_type, _Pointer>::value>;
+
+
template <class _Tp>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
_Tp*
-__to_raw_pointer(_Tp* __p) _NOEXCEPT
+__to_address(_Tp* __p) _NOEXCEPT
{
+ static_assert(!is_function<_Tp>::value, "_Tp is a function type");
return __p;
}
-#if _LIBCPP_STD_VER <= 17
template <class _Pointer>
-inline _LIBCPP_INLINE_VISIBILITY
-typename pointer_traits<_Pointer>::element_type*
-__to_raw_pointer(_Pointer __p) _NOEXCEPT
-{
- return _VSTD::__to_raw_pointer(__p.operator->());
-}
-#else
-template <class _Pointer>
-inline _LIBCPP_INLINE_VISIBILITY
-auto
-__to_raw_pointer(const _Pointer& __p) _NOEXCEPT
--> decltype(pointer_traits<_Pointer>::to_address(__p))
-{
- return pointer_traits<_Pointer>::to_address(__p);
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
+typename __choose_to_address<_Pointer>::template __return_type<_Pointer>
+__to_address(const _Pointer& __p) _NOEXCEPT {
+ return __choose_to_address<_Pointer>::__do_it(__p);
}
-template <class _Pointer, class... _None>
-inline _LIBCPP_INLINE_VISIBILITY
-auto
-__to_raw_pointer(const _Pointer& __p, _None...) _NOEXCEPT
-{
- return _VSTD::__to_raw_pointer(__p.operator->());
-}
+template <> struct __to_address_helper<false> {
+ template <class _Pointer>
+ using __return_type = typename pointer_traits<_Pointer>::element_type*;
+
+ template <class _Pointer>
+ _LIBCPP_CONSTEXPR
+ static __return_type<_Pointer>
+ __do_it(const _Pointer &__p) _NOEXCEPT { return std::__to_address(__p.operator->()); }
+};
+
+#if _LIBCPP_STD_VER > 17
template <class _Tp>
inline _LIBCPP_INLINE_VISIBILITY constexpr
_Tp*
@@ -1146,7 +1157,7 @@ inline _LIBCPP_INLINE_VISIBILITY
auto
to_address(const _Pointer& __p) _NOEXCEPT
{
- return _VSTD::__to_raw_pointer(__p);
+ return _VSTD::__to_address(__p);
}
#endif
@@ -1638,7 +1649,7 @@ struct _LIBCPP_TEMPLATE_VIS allocator_traits
static_assert(__is_cpp17_move_insertable<allocator_type>::value,
"The specified type does not meet the requirements of Cpp17MoveInsertible");
for (; __begin1 != __end1; ++__begin1, (void) ++__begin2)
- construct(__a, _VSTD::__to_raw_pointer(__begin2),
+ construct(__a, _VSTD::__to_address(__begin2),
#ifdef _LIBCPP_NO_EXCEPTIONS
_VSTD::move(*__begin1)
#else
@@ -1674,7 +1685,7 @@ struct _LIBCPP_TEMPLATE_VIS allocator_traits
__construct_range_forward(allocator_type& __a, _Iter __begin1, _Iter __end1, _Ptr& __begin2)
{
for (; __begin1 != __end1; ++__begin1, (void) ++__begin2)
- construct(__a, _VSTD::__to_raw_pointer(__begin2), *__begin1);
+ construct(__a, _VSTD::__to_address(__begin2), *__begin1);
}
template <class _SourceTp, class _DestTp,
@@ -1710,7 +1721,7 @@ struct _LIBCPP_TEMPLATE_VIS allocator_traits
"The specified type does not meet the requirements of Cpp17MoveInsertable");
while (__end1 != __begin1)
{
- construct(__a, _VSTD::__to_raw_pointer(__end2 - 1),
+ construct(__a, _VSTD::__to_address(__end2 - 1),
#ifdef _LIBCPP_NO_EXCEPTIONS
_VSTD::move(*--__end1)
#else
@@ -2167,6 +2178,10 @@ public:
};
#endif
+// Tag used to default initialize one or both of the pair's elements.
+struct __default_init_tag {};
+struct __value_init_tag {};
+
template <class _Tp, int _Idx,
bool _CanBeEmptyBase =
is_empty<_Tp>::value && !__libcpp_is_final<_Tp>::value>
@@ -2175,30 +2190,31 @@ struct __compressed_pair_elem {
typedef _Tp& reference;
typedef const _Tp& const_reference;
-#ifndef _LIBCPP_CXX03_LANG
- _LIBCPP_INLINE_VISIBILITY constexpr __compressed_pair_elem() : __value_() {}
+ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
+ __compressed_pair_elem(__default_init_tag) {}
+ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
+ __compressed_pair_elem(__value_init_tag) : __value_() {}
template <class _Up, class = typename enable_if<
!is_same<__compressed_pair_elem, typename decay<_Up>::type>::value
>::type>
_LIBCPP_INLINE_VISIBILITY
- constexpr explicit
+ _LIBCPP_CONSTEXPR explicit
__compressed_pair_elem(_Up&& __u)
: __value_(_VSTD::forward<_Up>(__u))
{
}
+
+#ifndef _LIBCPP_CXX03_LANG
template <class... _Args, size_t... _Indexes>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
__compressed_pair_elem(piecewise_construct_t, tuple<_Args...> __args,
__tuple_indices<_Indexes...>)
: __value_(_VSTD::forward<_Args>(_VSTD::get<_Indexes>(__args))...) {}
-#else
- _LIBCPP_INLINE_VISIBILITY __compressed_pair_elem() : __value_() {}
- _LIBCPP_INLINE_VISIBILITY
- __compressed_pair_elem(_ParamT __p) : __value_(std::forward<_ParamT>(__p)) {}
#endif
+
_LIBCPP_INLINE_VISIBILITY reference __get() _NOEXCEPT { return __value_; }
_LIBCPP_INLINE_VISIBILITY
const_reference __get() const _NOEXCEPT { return __value_; }
@@ -2214,28 +2230,27 @@ struct __compressed_pair_elem<_Tp, _Idx, true> : private _Tp {
typedef const _Tp& const_reference;
typedef _Tp __value_type;
-#ifndef _LIBCPP_CXX03_LANG
- _LIBCPP_INLINE_VISIBILITY constexpr __compressed_pair_elem() = default;
+ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR __compressed_pair_elem() = default;
+ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
+ __compressed_pair_elem(__default_init_tag) {}
+ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
+ __compressed_pair_elem(__value_init_tag) : __value_type() {}
template <class _Up, class = typename enable_if<
!is_same<__compressed_pair_elem, typename decay<_Up>::type>::value
>::type>
_LIBCPP_INLINE_VISIBILITY
- constexpr explicit
+ _LIBCPP_CONSTEXPR explicit
__compressed_pair_elem(_Up&& __u)
: __value_type(_VSTD::forward<_Up>(__u))
{}
+#ifndef _LIBCPP_CXX03_LANG
template <class... _Args, size_t... _Indexes>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
__compressed_pair_elem(piecewise_construct_t, tuple<_Args...> __args,
__tuple_indices<_Indexes...>)
: __value_type(_VSTD::forward<_Args>(_VSTD::get<_Indexes>(__args))...) {}
-#else
- _LIBCPP_INLINE_VISIBILITY __compressed_pair_elem() : __value_type() {}
- _LIBCPP_INLINE_VISIBILITY
- __compressed_pair_elem(_ParamT __p)
- : __value_type(std::forward<_ParamT>(__p)) {}
#endif
_LIBCPP_INLINE_VISIBILITY reference __get() _NOEXCEPT { return *this; }
@@ -2243,9 +2258,6 @@ struct __compressed_pair_elem<_Tp, _Idx, true> : private _Tp {
const_reference __get() const _NOEXCEPT { return *this; }
};
-// Tag used to construct the second element of the compressed pair.
-struct __second_tag {};
-
template <class _T1, class _T2>
class __compressed_pair : private __compressed_pair_elem<_T1, 0>,
private __compressed_pair_elem<_T2, 1> {
@@ -2262,33 +2274,21 @@ class __compressed_pair : private __compressed_pair_elem<_T1, 0>,
"implementation for this configuration");
public:
-#ifndef _LIBCPP_CXX03_LANG
- template <bool _Dummy = true,
+ template <bool _Dummy = true,
class = typename enable_if<
__dependent_type<is_default_constructible<_T1>, _Dummy>::value &&
__dependent_type<is_default_constructible<_T2>, _Dummy>::value
>::type
>
_LIBCPP_INLINE_VISIBILITY
- constexpr __compressed_pair() {}
-
- template <class _Tp, typename enable_if<!is_same<typename decay<_Tp>::type,
- __compressed_pair>::value,
- bool>::type = true>
- _LIBCPP_INLINE_VISIBILITY constexpr explicit
- __compressed_pair(_Tp&& __t)
- : _Base1(std::forward<_Tp>(__t)), _Base2() {}
-
- template <class _Tp>
- _LIBCPP_INLINE_VISIBILITY constexpr
- __compressed_pair(__second_tag, _Tp&& __t)
- : _Base1(), _Base2(std::forward<_Tp>(__t)) {}
+ _LIBCPP_CONSTEXPR __compressed_pair() : _Base1(__value_init_tag()), _Base2(__value_init_tag()) {}
template <class _U1, class _U2>
- _LIBCPP_INLINE_VISIBILITY constexpr
+ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
__compressed_pair(_U1&& __t1, _U2&& __t2)
: _Base1(std::forward<_U1>(__t1)), _Base2(std::forward<_U2>(__t2)) {}
+#ifndef _LIBCPP_CXX03_LANG
template <class... _Args1, class... _Args2>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
__compressed_pair(piecewise_construct_t __pc, tuple<_Args1...> __first_args,
@@ -2297,21 +2297,6 @@ public:
typename __make_tuple_indices<sizeof...(_Args1)>::type()),
_Base2(__pc, _VSTD::move(__second_args),
typename __make_tuple_indices<sizeof...(_Args2)>::type()) {}
-
-#else
- _LIBCPP_INLINE_VISIBILITY
- __compressed_pair() {}
-
- _LIBCPP_INLINE_VISIBILITY explicit
- __compressed_pair(_T1 __t1) : _Base1(_VSTD::forward<_T1>(__t1)) {}
-
- _LIBCPP_INLINE_VISIBILITY
- __compressed_pair(__second_tag, _T2 __t2)
- : _Base1(), _Base2(_VSTD::forward<_T2>(__t2)) {}
-
- _LIBCPP_INLINE_VISIBILITY
- __compressed_pair(_T1 __t1, _T2 __t2)
- : _Base1(_VSTD::forward<_T1>(__t1)), _Base2(_VSTD::forward<_T2>(__t2)) {}
#endif
_LIBCPP_INLINE_VISIBILITY
@@ -2492,17 +2477,17 @@ public:
template <bool _Dummy = true,
class = _EnableIfDeleterDefaultConstructible<_Dummy> >
_LIBCPP_INLINE_VISIBILITY
- _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT : __ptr_(pointer()) {}
+ _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT : __ptr_(pointer(), __default_init_tag()) {}
template <bool _Dummy = true,
class = _EnableIfDeleterDefaultConstructible<_Dummy> >
_LIBCPP_INLINE_VISIBILITY
- _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT : __ptr_(pointer()) {}
+ _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT : __ptr_(pointer(), __default_init_tag()) {}
template <bool _Dummy = true,
class = _EnableIfDeleterDefaultConstructible<_Dummy> >
_LIBCPP_INLINE_VISIBILITY
- explicit unique_ptr(pointer __p) _NOEXCEPT : __ptr_(__p) {}
+ explicit unique_ptr(pointer __p) _NOEXCEPT : __ptr_(__p, __default_init_tag()) {}
template <bool _Dummy = true,
class = _EnableIfDeleterConstructible<_LValRefType<_Dummy> > >
@@ -2544,7 +2529,7 @@ public:
typename enable_if<is_convertible<_Up*, _Tp*>::value &&
is_same<_Dp, default_delete<_Tp> >::value,
__nat>::type = __nat()) _NOEXCEPT
- : __ptr_(__p.release()) {}
+ : __ptr_(__p.release(), __default_init_tag()) {}
#endif
_LIBCPP_INLINE_VISIBILITY
@@ -2715,19 +2700,19 @@ public:
template <bool _Dummy = true,
class = _EnableIfDeleterDefaultConstructible<_Dummy> >
_LIBCPP_INLINE_VISIBILITY
- _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT : __ptr_(pointer()) {}
+ _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT : __ptr_(pointer(), __default_init_tag()) {}
template <bool _Dummy = true,
class = _EnableIfDeleterDefaultConstructible<_Dummy> >
_LIBCPP_INLINE_VISIBILITY
- _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT : __ptr_(pointer()) {}
+ _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT : __ptr_(pointer(), __default_init_tag()) {}
template <class _Pp, bool _Dummy = true,
class = _EnableIfDeleterDefaultConstructible<_Dummy>,
class = _EnableIfPointerConvertible<_Pp> >
_LIBCPP_INLINE_VISIBILITY
explicit unique_ptr(_Pp __p) _NOEXCEPT
- : __ptr_(__p) {}
+ : __ptr_(__p, __default_init_tag()) {}
template <class _Pp, bool _Dummy = true,
class = _EnableIfDeleterConstructible<_LValRefType<_Dummy> >,
@@ -3571,24 +3556,20 @@ class __shared_ptr_emplace
{
__compressed_pair<_Alloc, _Tp> __data_;
public:
-#ifndef _LIBCPP_HAS_NO_VARIADICS
_LIBCPP_INLINE_VISIBILITY
__shared_ptr_emplace(_Alloc __a)
- : __data_(_VSTD::move(__a)) {}
+ : __data_(_VSTD::move(__a), __value_init_tag()) {}
+
+#ifndef _LIBCPP_HAS_NO_VARIADICS
template <class ..._Args>
_LIBCPP_INLINE_VISIBILITY
__shared_ptr_emplace(_Alloc __a, _Args&& ...__args)
: __data_(piecewise_construct, _VSTD::forward_as_tuple(__a),
_VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)) {}
-
#else // _LIBCPP_HAS_NO_VARIADICS
- _LIBCPP_INLINE_VISIBILITY
- __shared_ptr_emplace(_Alloc __a)
- : __data_(__a) {}
-
template <class _A0>
_LIBCPP_INLINE_VISIBILITY
__shared_ptr_emplace(_Alloc __a, _A0& __a0)