Please use GitHub pull requests for new patches. Avoid migrating existing patches. Phabricator shutdown timeline
Changeset View
Standalone View
include/memory
Show First 20 Lines • Show All 620 Lines • ▼ Show 20 Lines | template<class T> | ||||
atomic_compare_exchange_weak_explicit(shared_ptr<T>* p, shared_ptr<T>* v, | atomic_compare_exchange_weak_explicit(shared_ptr<T>* p, shared_ptr<T>* v, | ||||
shared_ptr<T> w, memory_order success, | shared_ptr<T> w, memory_order success, | ||||
memory_order failure); | memory_order failure); | ||||
template<class T> | template<class T> | ||||
bool | bool | ||||
atomic_compare_exchange_strong_explicit(shared_ptr<T>* p, shared_ptr<T>* v, | atomic_compare_exchange_strong_explicit(shared_ptr<T>* p, shared_ptr<T>* v, | ||||
shared_ptr<T> w, memory_order success, | shared_ptr<T> w, memory_order success, | ||||
memory_order failure); | memory_order failure); | ||||
template <class T, class Alloc, class... Args> | |||||
auto uses_allocator_construction_args(const Alloc& alloc, Args&&... args); | |||||
template <class T, class Alloc, class Tuple1, class Tuple2> | |||||
auto uses_allocator_construction_args(const Alloc& alloc, piecewise_construct_t, Tuple1&& x, Tuple2&& y); | |||||
template <class T> | |||||
auto uses_allocator_construction_args(const Alloc& alloc); | |||||
template <class T, class Alloc, class U, class V> | |||||
auto uses_allocator_construction_args(const Alloc& alloc, U&& u, V&& v); | |||||
template <class T, class Alloc, class U, class V> | |||||
auto uses_allocator_construction_args(const Alloc& alloc, const pair<U,V>& pr); | |||||
template <class T, class Alloc, class U, class V> | |||||
auto uses_allocator_construction_args(const Alloc& alloc, pair<U,V>&& pr); | |||||
template <class T, class Alloc, class... Args> | |||||
T make_obj_using_allocator(const Alloc& alloc, Args&&... args); | |||||
template <class T, class Alloc, class... Args> | |||||
T* uninitialized_construct_using_allocator(T* p, const Alloc& alloc, Args&&... args); | |||||
// Hash support | // Hash support | ||||
template <class T> struct hash; | template <class T> struct hash; | ||||
template <class T, class D> struct hash<unique_ptr<T, D> >; | template <class T, class D> struct hash<unique_ptr<T, D> >; | ||||
template <class T> struct hash<shared_ptr<T> >; | template <class T> struct hash<shared_ptr<T> >; | ||||
template <class T, class Alloc> | template <class T, class Alloc> | ||||
inline constexpr bool uses_allocator_v = uses_allocator<T, Alloc>::value; | inline constexpr bool uses_allocator_v = uses_allocator<T, Alloc>::value; | ||||
▲ Show 20 Lines • Show All 5,025 Lines • ▼ Show 20 Lines | |||||
struct __is_allocator : false_type {}; | struct __is_allocator : false_type {}; | ||||
template<typename _Alloc> | template<typename _Alloc> | ||||
struct __is_allocator<_Alloc, | struct __is_allocator<_Alloc, | ||||
typename __void_t<typename _Alloc::value_type>::type, | typename __void_t<typename _Alloc::value_type>::type, | ||||
typename __void_t<decltype(_VSTD::declval<_Alloc&>().allocate(size_t(0)))>::type | typename __void_t<decltype(_VSTD::declval<_Alloc&>().allocate(size_t(0)))>::type | ||||
> | > | ||||
: true_type {}; | : true_type {}; | ||||
#if _LIBCPP_STD_VER > 17 | |||||
template <class _Tp> struct __is_pair : false_type { }; | |||||
template <class _T1, class _T2> | |||||
struct __is_pair<pair<_T1, _T2>> : true_type { }; | |||||
template<class _Tp, class _Un, class _Alloc, class... _Args> | |||||
auto | |||||
__uses_allocator_construction_args_no_pair(false_type, _Un, const _Alloc, _Args&&... __args) { | |||||
return _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...); | |||||
} | |||||
template<class _Tp, class _Alloc, class... _Args> | |||||
auto | |||||
__uses_allocator_construction_args_no_pair(true_type, true_type, const _Alloc __alloc, _Args&&... __args) { | |||||
return _VSTD::forward_as_tuple(allocator_arg, __alloc, _VSTD::forward<_Args>(__args)...); | |||||
} | |||||
template<class _Tp, class _Alloc, class... _Args> | |||||
auto | |||||
__uses_allocator_construction_args_no_pair(false_type, false_type, const _Alloc __alloc, _Args&&... __args) { | |||||
return _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)..., __alloc); | |||||
} | |||||
template<class _Tp, class _Alloc, class... _Args, | |||||
typename = enable_if_t<!__is_pair<_Tp>::value>> | |||||
auto | |||||
uses_allocator_construction_args(const _Alloc& __alloc, _Args&&... __args) { | |||||
return __uses_allocator_construction_args_no_pair<_Tp>( | |||||
_VSTD::uses_allocator<_Tp, _Alloc>(), | |||||
_VSTD::is_constructible<_Tp, allocator_arg_t, _Alloc, _Args...>(), | |||||
__alloc, _VSTD::forward<_Args>(__args)...); | |||||
} | |||||
template<class _Tp, class _Alloc, class _T1, class _T2, | |||||
typename = enable_if_t<__is_pair<_Tp>::value>> | |||||
auto | |||||
uses_allocator_construction_args(const _Alloc& __alloc, | |||||
piecewise_construct_t, | |||||
_T1&& __a, _T2&& __b) { | |||||
return std::make_tuple(piecewise_construct, | |||||
_VSTD::apply( [&__alloc](auto&&... __args) { | |||||
return _VSTD::uses_allocator_construction_args<_T1>(__alloc, _VSTD::forward<decltype(__args)>(__args)...); | |||||
}, _VSTD::forward<_T1>(__a)), | |||||
_VSTD::apply( [&__alloc](auto&&... __args) { | |||||
return _VSTD::uses_allocator_construction_args<_T2>(__alloc, _VSTD::forward<decltype(__args)>(__args)...); | |||||
}, _VSTD::forward<_T2>(__b))); | |||||
} | |||||
template<class _Tp, class _Alloc, | |||||
typename = enable_if_t<__is_pair<_Tp>::value>> | |||||
auto | |||||
uses_allocator_construction_args(const _Alloc& __alloc) { | |||||
return uses_allocator_construction_args<_Tp>(__alloc, piecewise_construct, _VSTD::tuple<>{}, _VSTD::tuple<>{}); | |||||
} | |||||
template<class _Tp, class _Alloc, class _T1, class _T2, | |||||
typename = enable_if_t<__is_pair<_Tp>::value>> | |||||
auto | |||||
uses_allocator_construction_args(const _Alloc& __alloc, _T1&& __a, _T2&& __b) { | |||||
return uses_allocator_construction_args<_Tp>( | |||||
__alloc, piecewise_construct, | |||||
_VSTD::forward_as_tuple(_VSTD::forward<_T1>(__a)), | |||||
_VSTD::forward_as_tuple(_VSTD::forward<_T2>(__b))); | |||||
} | |||||
template<class _Tp, class _Alloc, class _T1, class _T2, | |||||
typename = enable_if_t<__is_pair<_Tp>::value>> | |||||
auto | |||||
uses_allocator_construction_args(const _Alloc& __alloc, const _VSTD::pair<_T1, _T2>& __p) { | |||||
return uses_allocator_construction_args<_Tp>(__alloc, piecewise_construct, | |||||
forward_as_tuple(__p.first), | |||||
forward_as_tuple(__p.second)); | |||||
} | |||||
template<class _Tp, class _Alloc, class _T1, class _T2, | |||||
typename = enable_if_t<__is_pair<_Tp>::value>> | |||||
auto | |||||
uses_allocator_construction_args(const _Alloc& __alloc, _VSTD::pair<_T1, _T2>&& __p) { | |||||
return uses_allocator_construction_args<_Tp>(__alloc, | |||||
piecewise_construct, | |||||
forward_as_tuple(_VSTD::move(__p).first), | |||||
forward_as_tuple(_VSTD::move(__p).first)); | |||||
} | |||||
template<class _Tp, class _Alloc, class... _Args> | |||||
_Tp | |||||
make_obj_using_allocator(const _Alloc& __alloc, _Args&&... __args) { | |||||
return make_from_tuple<_Tp>( | |||||
uses_allocator_construction_args<_Tp>(__alloc, _VSTD::forward<_Args>(__args)...)); | |||||
} | |||||
template<class _Tp, class _Alloc, class... _Args> | |||||
_Tp* | |||||
uninitialized_construct_using_allocator(_Tp* __p, const _Alloc& __alloc, _Args&&... __args) { | |||||
return ::new(static_cast<void*>(__p)) _Tp( | |||||
make_obj_using_allocator<_Tp>(__alloc, _VSTD::forward<_Args>(__args)...) | |||||
); | |||||
} | |||||
#endif // _LIBCPP_STD_VER > 17 | |||||
_LIBCPP_END_NAMESPACE_STD | _LIBCPP_END_NAMESPACE_STD | ||||
_LIBCPP_POP_MACROS | _LIBCPP_POP_MACROS | ||||
#endif // _LIBCPP_MEMORY | #endif // _LIBCPP_MEMORY | ||||
zoecarver: Spacing | |||||
What is -> auto doing here and on line 5755? Quuxplusone: What is `-> auto` doing here and on line 5755? | |||||
Will fix. zoecarver: Will fix. | |||||
So if I pass in a pair<string, int> or pair<string&&, int>, you'll move out of p.first, but if I pass in pair<string&, int>, you'll make a copy of p.first, is that right? I guess that seems reasonable, but it's a surprising/smelly use of std::forward IMVHO. Quuxplusone: So if I pass in a `pair<string, int>` or `pair<string&&, int>`, you'll //move// out of `p. | |||||
You are right; I should probably use std::move here. For reference here is what the standard says. zoecarver: You are right; I should probably use `std::move` here. For reference [[ http://eel. | |||||
Thanks for pointing to the relevant Standard wording! I was too lazy to go look for it myself. :) The wording uses std::move(pr).first, which is equivalent to std::forward<_T1>(pr.first) but doesn't set off my red-flag detectors — I would greatly prefer _VSTD::move(__p).first here. (Notice that _VSTD::move(__p).first is different from _VSTD::move(__p.first) when __p is a pair of lvalue references. Which is good; it's what we want.) Quuxplusone: Thanks for pointing to the relevant Standard wording! I was too lazy to go look for it myself. | |||||
I am not sure that is necessarily true. Sometimes one works, and the other doesn't. I think it should be pointed out that the author of the paper used forward in their implementation (probably for that reason). zoecarver: I am not sure that is necessarily true. Sometimes one works, and the other doesn't. I think it… | |||||
Not Done ReplyInline ActionsNit: I believe this needs a _VSTD:: to prevent ADL in some complicated case involving std::pair<int, std::vector<Incomplete>*> that I don't 100% remember. (Something like it's going to try to look for friends of Incomplete because Incomplete is an associated entity of that pair type.) It would be interesting to write a unit test for this. Quuxplusone: Nit: I believe this needs a `_VSTD::` to prevent ADL in some complicated case involving `std… | |||||
Do you mean __uses_allocator_construction_args_impl or is_pair? zoecarver: Do you mean `__uses_allocator_construction_args_impl` or `is_pair`? | |||||
Not Done ReplyInline ActionsShould make_obj_using_allocator be qualified? MaskRay: Should `make_obj_using_allocator` be qualified?
https://github.com/cplusplus/draft/issues/3111… |
Spacing