Skip to content

Commit 2474a61

Browse files
committed
Utilize P1144's library functions if present
1 parent 9e52541 commit 2474a61

File tree

1 file changed

+90
-4
lines changed

1 file changed

+90
-4
lines changed

libs/core/type_support/include/hpx/type_support/uninitialized_relocate_n_primitive.hpp

Lines changed: 90 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,8 @@
2222

2323
namespace hpx::experimental::util {
2424

25-
#if defined(__cpp_lib_trivially_relocatable)
26-
using std::uninitialized_relocate;
27-
#else
25+
namespace detail { // Utility metafunctions
2826

29-
namespace detail {
3027
struct buffer_memcpy_tag
3128
{
3229
};
@@ -81,7 +78,96 @@ namespace hpx::experimental::util {
8178
>;
8279
// clang-format on
8380
};
81+
} // namespace detail
82+
83+
#if defined(HPX_HAVE_P1144_RELOCATE_AT)
84+
//////////////////////////////
85+
// uninitialized_relocate_n //
86+
//////////////////////////////
87+
template <typename InIter, typename FwdIter, typename Size,
88+
typename Dummy> // Dummy is used retain the same signature
89+
// as the implementation before P1144
90+
// clang-format off
91+
std::tuple<InIter, FwdIter> uninitialized_relocate_n_primitive(InIter first, Size n,
92+
FwdIter dst, Dummy) noexcept(
93+
detail::relocation_traits<InIter, FwdIter>::is_noexcept_relocatable_v)
94+
// clang-format on
95+
{
96+
static_assert(
97+
detail::relocation_traits<InIter, FwdIter>::valid_relocation,
98+
"uninitialized_move(first, last, dst) must be well-formed");
99+
100+
return std::uninitialized_relocate_n(first, n, dst);
101+
}
102+
103+
template <typename InIter, typename Size, typename FwdIter>
104+
std::tuple<InIter, FwdIter> uninitialized_relocate_n_primitive(InIter first,
105+
Size n, FwdIter dst) noexcept(detail::relocation_traits<InIter,
106+
FwdIter>::is_noexcept_relocatable_v)
107+
{
108+
return uninitialized_relocate_n_primitive(first, n, dst, bool{});
109+
}
110+
111+
////////////////////////////
112+
// uninitialized_relocate //
113+
////////////////////////////
114+
template <typename InIter, typename Sent, typename FwdIter,
115+
typename Dummy> // Dummy is used retain the same signature
116+
// as the implementation before P1144
117+
// clang-format off
118+
std::tuple<InIter, FwdIter> uninitialized_relocate_primitive(InIter first, Sent last,
119+
FwdIter dst, Dummy) noexcept(
120+
detail::relocation_traits<InIter, FwdIter>::is_noexcept_relocatable_v)
121+
// clang-format on
122+
{
123+
// TODO CHECK SENT
124+
static_assert(
125+
detail::relocation_traits<InIter, FwdIter>::valid_relocation,
126+
"uninitialized_move(first, last, dst) must be well-formed");
127+
128+
return std::uninitialized_relocate(first, last, dst);
129+
}
130+
131+
template <typename InIter, typename Sent, typename FwdIter>
132+
std::tuple<InIter, FwdIter> uninitialized_relocate_primitive(InIter first,
133+
Sent last, FwdIter dst) noexcept(detail::relocation_traits<InIter,
134+
FwdIter>::is_noexcept_relocatable_v)
135+
{
136+
return uninitialized_relocate_primitive(first, last, dst, bool{});
137+
}
138+
139+
/////////////////////////////////////
140+
// uninitialized_relocate_backward //
141+
/////////////////////////////////////
142+
template <typename BiIter1, typename BiIter2,
143+
typename Dummy> // Dummy is used retain the same signature
144+
// as the implementation before P1144
145+
// clang-format off
146+
std::tuple<BiIter1, BiIter2> uninitialized_relocate_backward_primitive(BiIter1 first, BiIter1 last,
147+
BiIter2 dst_last, Dummy) noexcept(
148+
detail::relocation_traits<BiIter1, BiIter2>::is_noexcept_relocatable_v)
149+
// clang-format on
150+
{
151+
// TODO CHECK SENT
152+
static_assert(
153+
detail::relocation_traits<BiIter1, BiIter2>::valid_relocation,
154+
"uninitialized_move(first, last, dst) must be well-formed");
155+
156+
return std::uninitialized_relocate_backward(first, last, dst_last);
157+
}
84158

159+
template <typename BiIter1, typename BiIter2>
160+
std::tuple<BiIter1, BiIter2> uninitialized_relocate_backward_primitive(
161+
BiIter1 first, BiIter1 last,
162+
BiIter2 dst_last) noexcept(detail::relocation_traits<BiIter1,
163+
BiIter2>::is_noexcept_relocatable_v)
164+
{
165+
return uninitialized_relocate_backward_primitive(
166+
first, last, dst_last, bool{});
167+
}
168+
#else
169+
170+
namespace detail {
85171
//////////////////////////////
86172
// uninitialized_relocate_n //
87173
//////////////////////////////

0 commit comments

Comments
 (0)