Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions stl/inc/scoped_allocator
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ decltype(auto) _Scoped_outermost(_Alloc& _Al) { // gets the outermost allocator
}

template <class _Alloc>
using _Scoped_outermost_t = remove_reference_t<decltype(_Scoped_outermost(_STD declval<_Alloc&>()))>;
using _Scoped_outermost_t = remove_reference_t<decltype(_STD _Scoped_outermost(_STD declval<_Alloc&>()))>;

template <class _Alloc>
using _Scoped_outermost_traits = allocator_traits<_Scoped_outermost_t<_Alloc>>;
Expand Down Expand Up @@ -230,17 +230,23 @@ public:
_STD apply(
[_Ptr, this](auto&&... _New_args) {
_Scoped_outermost_traits<scoped_allocator_adaptor>::construct(
_Scoped_outermost(*this), _Ptr, _STD forward<decltype(_New_args)>(_New_args)...);
_STD _Scoped_outermost(*this), _Ptr, _STD forward<decltype(_New_args)>(_New_args)...);
},
_STD uses_allocator_construction_args<_Ty>(inner_allocator(), _STD forward<_Types>(_Args)...));
#else // ^^^ _HAS_CXX20 / !_HAS_CXX20 vvv
_Uses_allocator_construct(_Ptr, _Scoped_outermost(*this), inner_allocator(), _STD forward<_Types>(_Args)...);
if constexpr (_Is_cv_pair<_Ty>) {
_STD _Uses_alloc_construct_pair(
_Ptr, _STD _Scoped_outermost(*this), inner_allocator(), _STD forward<_Types>(_Args)...);
} else {
_STD _Uses_alloc_construct_non_pair(
_Ptr, _STD _Scoped_outermost(*this), inner_allocator(), _STD forward<_Types>(_Args)...);
}
#endif // ^^^ !_HAS_CXX20 ^^^
}

template <class _Ty>
void destroy(_Ty* _Ptr) { // destroy object at _Ptr
_Scoped_outermost_traits<scoped_allocator_adaptor>::destroy(_Scoped_outermost(*this), _Ptr);
_Scoped_outermost_traits<scoped_allocator_adaptor>::destroy(_STD _Scoped_outermost(*this), _Ptr);
}

// select_on_container_copy_construction comes from _Scoped_base
Expand Down
56 changes: 24 additions & 32 deletions stl/inc/xmemory
Original file line number Diff line number Diff line change
Expand Up @@ -2241,7 +2241,10 @@ template <class _Ty, class = void>
_INLINE_VAR constexpr bool _Is_deducible_as_pair = false;

template <class _Ty>
_INLINE_VAR constexpr bool _Is_deducible_as_pair<_Ty, decltype(_Deduce_as_pair(_STD declval<_Ty>()))> = true;
_INLINE_VAR constexpr bool _Is_deducible_as_pair<_Ty, decltype(_STD _Deduce_as_pair(_STD declval<_Ty>()))> = true;

template <class _Ty>
_INLINE_VAR constexpr bool _Is_cv_pair = _Is_specialization_v<remove_cv_t<_Ty>, pair>;

template <class _Ty>
const _Ty& _Normally_bind(_Identity_t<const _Ty&>); // not defined
Expand All @@ -2250,7 +2253,7 @@ template <class _Ty>
_Ty&& _Normally_bind(_Identity_t<_Ty&&>); // not defined

template <class _Ty, class _Uty>
using _Normally_bound_ref = decltype(_Normally_bind<_Ty>(_STD declval<_Uty>()));
using _Normally_bound_ref = decltype(_STD _Normally_bind<_Ty>(_STD declval<_Uty>()));

template <class _Ty, class _Uty, class = void>
_INLINE_VAR constexpr bool _Is_normally_bindable = false;
Expand All @@ -2259,11 +2262,11 @@ template <class _Ty, class _Uty>
_INLINE_VAR constexpr bool _Is_normally_bindable<_Ty, _Uty, void_t<_Normally_bound_ref<_Ty, _Uty>>> = true;

#if _HAS_CXX20
_EXPORT_STD template <class _Ty, class _Alloc, class... _Types, enable_if_t<!_Is_specialization_v<_Ty, pair>, int> = 0>
_EXPORT_STD template <class _Ty, class _Alloc, class... _Types, enable_if_t<!_Is_cv_pair<_Ty>, int> = 0>
_NODISCARD constexpr auto uses_allocator_construction_args(const _Alloc& _Al, _Types&&... _Args) noexcept {
if constexpr (!uses_allocator_v<_Ty, _Alloc>) {
if constexpr (!uses_allocator_v<remove_cv_t<_Ty>, _Alloc>) {
static_assert(is_constructible_v<_Ty, _Types...>,
"If uses_allocator_v<T, Alloc> does not hold, T must be constructible from Types...");
"If uses_allocator_v<remove_cv_t<T>, Alloc> does not hold, T must be constructible from Types...");
(void) _Al;
return _STD forward_as_tuple(_STD forward<_Types>(_Args)...);
} else if constexpr (is_constructible_v<_Ty, allocator_arg_t, const _Alloc&, _Types...>) {
Expand All @@ -2274,44 +2277,38 @@ _NODISCARD constexpr auto uses_allocator_construction_args(const _Alloc& _Al, _T
} else {
static_assert(_Always_false<_Ty>,
"T must be constructible from either (allocator_arg_t, const Alloc&, Types...) "
"or (Types..., const Alloc&) if uses_allocator_v<T, Alloc> is true");
"or (Types..., const Alloc&) if uses_allocator_v<remove_cv_t<T>, Alloc> is true");
}
}

_EXPORT_STD template <class _Ty, class _Alloc, enable_if_t<_Is_specialization_v<_Ty, pair>, int> = 0>
_EXPORT_STD template <class _Ty, class _Alloc, enable_if_t<_Is_cv_pair<_Ty>, int> = 0>
_NODISCARD constexpr auto uses_allocator_construction_args(const _Alloc& _Al) noexcept;

_EXPORT_STD template <class _Ty, class _Alloc, class _Uty1, class _Uty2,
enable_if_t<_Is_specialization_v<_Ty, pair>, int> = 0>
_EXPORT_STD template <class _Ty, class _Alloc, class _Uty1, class _Uty2, enable_if_t<_Is_cv_pair<_Ty>, int> = 0>
_NODISCARD constexpr auto uses_allocator_construction_args(const _Alloc& _Al, _Uty1&& _Val1, _Uty2&& _Val2) noexcept;

#if _HAS_CXX23
_EXPORT_STD template <class _Ty, class _Alloc, class _Uty1, class _Uty2,
enable_if_t<_Is_specialization_v<_Ty, pair>, int> = 0>
_EXPORT_STD template <class _Ty, class _Alloc, class _Uty1, class _Uty2, enable_if_t<_Is_cv_pair<_Ty>, int> = 0>
_NODISCARD constexpr auto uses_allocator_construction_args(const _Alloc& _Al, pair<_Uty1, _Uty2>& _Pair) noexcept;
#endif // _HAS_CXX23

_EXPORT_STD template <class _Ty, class _Alloc, class _Uty1, class _Uty2,
enable_if_t<_Is_specialization_v<_Ty, pair>, int> = 0>
_EXPORT_STD template <class _Ty, class _Alloc, class _Uty1, class _Uty2, enable_if_t<_Is_cv_pair<_Ty>, int> = 0>
_NODISCARD constexpr auto uses_allocator_construction_args(const _Alloc& _Al, const pair<_Uty1, _Uty2>& _Pair) noexcept;

_EXPORT_STD template <class _Ty, class _Alloc, class _Uty1, class _Uty2,
enable_if_t<_Is_specialization_v<_Ty, pair>, int> = 0>
_EXPORT_STD template <class _Ty, class _Alloc, class _Uty1, class _Uty2, enable_if_t<_Is_cv_pair<_Ty>, int> = 0>
_NODISCARD constexpr auto uses_allocator_construction_args(const _Alloc& _Al, pair<_Uty1, _Uty2>&& _Pair) noexcept;

#if _HAS_CXX23
_EXPORT_STD template <class _Ty, class _Alloc, class _Uty1, class _Uty2,
enable_if_t<_Is_specialization_v<_Ty, pair>, int> = 0>
_EXPORT_STD template <class _Ty, class _Alloc, class _Uty1, class _Uty2, enable_if_t<_Is_cv_pair<_Ty>, int> = 0>
_NODISCARD constexpr auto uses_allocator_construction_args(
const _Alloc& _Al, const pair<_Uty1, _Uty2>&& _Pair) noexcept;
#endif // _HAS_CXX23

_EXPORT_STD template <class _Ty, class _Alloc, class _Uty,
enable_if_t<_Is_specialization_v<_Ty, pair> && !_Is_deducible_as_pair<_Uty&>, int> = 0>
enable_if_t<_Is_cv_pair<_Ty> && !_Is_deducible_as_pair<_Uty&>, int> = 0>
_NODISCARD constexpr auto uses_allocator_construction_args(const _Alloc& _Al, _Uty&& _Ux) noexcept;

_EXPORT_STD template <class _Ty, class _Alloc, class _Tuple1, class _Tuple2,
enable_if_t<_Is_specialization_v<_Ty, pair>, int> = 0>
_EXPORT_STD template <class _Ty, class _Alloc, class _Tuple1, class _Tuple2, enable_if_t<_Is_cv_pair<_Ty>, int> = 0>
_NODISCARD constexpr auto uses_allocator_construction_args(
const _Alloc& _Al, piecewise_construct_t, _Tuple1&& _Tup1, _Tuple2&& _Tup2) noexcept {
return _STD make_tuple(piecewise_construct,
Expand All @@ -2329,16 +2326,15 @@ _NODISCARD constexpr auto uses_allocator_construction_args(
_STD forward<_Tuple2>(_Tup2)));
}

_EXPORT_STD template <class _Ty, class _Alloc, enable_if_t<_Is_specialization_v<_Ty, pair>, int>>
_EXPORT_STD template <class _Ty, class _Alloc, enable_if_t<_Is_cv_pair<_Ty>, int>>
_NODISCARD constexpr auto uses_allocator_construction_args(const _Alloc& _Al) noexcept {
// equivalent to
// return _STD uses_allocator_construction_args<_Ty>(_Al, piecewise_construct, tuple<>{}, tuple<>{});
return _STD make_tuple(piecewise_construct, _STD uses_allocator_construction_args<typename _Ty::first_type>(_Al),
_STD uses_allocator_construction_args<typename _Ty::second_type>(_Al));
}

_EXPORT_STD template <class _Ty, class _Alloc, class _Uty1, class _Uty2,
enable_if_t<_Is_specialization_v<_Ty, pair>, int>>
_EXPORT_STD template <class _Ty, class _Alloc, class _Uty1, class _Uty2, enable_if_t<_Is_cv_pair<_Ty>, int>>
_NODISCARD constexpr auto uses_allocator_construction_args(const _Alloc& _Al, _Uty1&& _Val1, _Uty2&& _Val2) noexcept {
// equivalent to
// return _STD uses_allocator_construction_args<_Ty>(_Al, piecewise_construct,
Expand All @@ -2349,8 +2345,7 @@ _NODISCARD constexpr auto uses_allocator_construction_args(const _Alloc& _Al, _U
}

#if _HAS_CXX23
_EXPORT_STD template <class _Ty, class _Alloc, class _Uty1, class _Uty2,
enable_if_t<_Is_specialization_v<_Ty, pair>, int>>
_EXPORT_STD template <class _Ty, class _Alloc, class _Uty1, class _Uty2, enable_if_t<_Is_cv_pair<_Ty>, int>>
_NODISCARD constexpr auto uses_allocator_construction_args(const _Alloc& _Al, pair<_Uty1, _Uty2>& _Pair) noexcept {
// equivalent to
// return _STD uses_allocator_construction_args<_Ty>(_Al, piecewise_construct,
Expand All @@ -2361,8 +2356,7 @@ _NODISCARD constexpr auto uses_allocator_construction_args(const _Alloc& _Al, pa
}
#endif // _HAS_CXX23

_EXPORT_STD template <class _Ty, class _Alloc, class _Uty1, class _Uty2,
enable_if_t<_Is_specialization_v<_Ty, pair>, int>>
_EXPORT_STD template <class _Ty, class _Alloc, class _Uty1, class _Uty2, enable_if_t<_Is_cv_pair<_Ty>, int>>
_NODISCARD constexpr auto uses_allocator_construction_args(
const _Alloc& _Al, const pair<_Uty1, _Uty2>& _Pair) noexcept {
// equivalent to
Expand All @@ -2373,8 +2367,7 @@ _NODISCARD constexpr auto uses_allocator_construction_args(
_STD uses_allocator_construction_args<typename _Ty::second_type>(_Al, _Pair.second));
}

_EXPORT_STD template <class _Ty, class _Alloc, class _Uty1, class _Uty2,
enable_if_t<_Is_specialization_v<_Ty, pair>, int>>
_EXPORT_STD template <class _Ty, class _Alloc, class _Uty1, class _Uty2, enable_if_t<_Is_cv_pair<_Ty>, int>>
_NODISCARD constexpr auto uses_allocator_construction_args(const _Alloc& _Al, pair<_Uty1, _Uty2>&& _Pair) noexcept {
// equivalent to
// return _STD uses_allocator_construction_args<_Ty>(_Al, piecewise_construct,
Expand All @@ -2385,8 +2378,7 @@ _NODISCARD constexpr auto uses_allocator_construction_args(const _Alloc& _Al, pa
}

#if _HAS_CXX23
_EXPORT_STD template <class _Ty, class _Alloc, class _Uty1, class _Uty2,
enable_if_t<_Is_specialization_v<_Ty, pair>, int>>
_EXPORT_STD template <class _Ty, class _Alloc, class _Uty1, class _Uty2, enable_if_t<_Is_cv_pair<_Ty>, int>>
_NODISCARD constexpr auto uses_allocator_construction_args(
const _Alloc& _Al, const pair<_Uty1, _Uty2>&& _Pair) noexcept {
// equivalent to
Expand All @@ -2399,7 +2391,7 @@ _NODISCARD constexpr auto uses_allocator_construction_args(
#endif // _HAS_CXX23

_EXPORT_STD template <class _Ty, class _Alloc, class _Uty,
enable_if_t<_Is_specialization_v<_Ty, pair> && !_Is_deducible_as_pair<_Uty&>, int>>
enable_if_t<_Is_cv_pair<_Ty> && !_Is_deducible_as_pair<_Uty&>, int>>
_NODISCARD constexpr auto uses_allocator_construction_args(const _Alloc& _Al, _Uty&& _Ux) noexcept {
struct _Pair_remaker {
const _Alloc& _Al;
Expand Down
Loading