@@ -18,9 +18,6 @@ namespace stdsharp::details
18
18
using ctor = allocator_traits::constructor;
19
19
using dtor = allocator_traits::destructor;
20
20
21
- static constexpr auto data = allocation_traits::template data<T>;
22
- static constexpr auto get = allocation_traits::template get<T>;
23
-
24
21
template <typename >
25
22
struct forward_value ;
26
23
@@ -39,7 +36,7 @@ namespace stdsharp::details
39
36
template <typename Allocation>
40
37
using forward_value_t = forward_value<Allocation>::type;
41
38
42
- constexpr void size_validate (this const auto & t, const auto &... allocations) noexcept
39
+ static constexpr void size_validate (const auto & t, const auto &... allocations) noexcept
43
40
{
44
41
( //
45
42
Expects (
@@ -50,6 +47,19 @@ namespace stdsharp::details
50
47
);
51
48
}
52
49
50
+ [[nodiscard]] constexpr auto data (this const auto & t, const auto & allocation) noexcept
51
+ {
52
+ size_validate (t, allocation);
53
+ return allocation_traits::template data<T>(allocation);
54
+ }
55
+
56
+ [[nodiscard]] constexpr decltype (auto ) get(this const auto & t, const auto & allocation) //
57
+ noexcept
58
+ {
59
+ size_validate (t, allocation);
60
+ return allocation_traits::template get<T>(allocation);
61
+ }
62
+
53
63
static constexpr struct default_construct_t
54
64
{
55
65
} default_construct{};
@@ -61,15 +71,13 @@ namespace stdsharp
61
71
template <allocator_req Allocator, typename T = Allocator::value_type>
62
72
struct allocation_value : private details ::allocation_value<Allocator, T>
63
73
{
74
+ private:
64
75
using m_base = details::allocation_value<Allocator, T>;
65
76
77
+ friend m_base;
78
+
66
79
public:
67
- using typename m_base::allocation_traits;
68
- using typename m_base::allocator_traits;
69
80
using typename m_base::allocator_type;
70
- using typename m_base::size_type;
71
- using typename m_base::default_construct_t ;
72
- using m_base::default_construct;
73
81
using m_base::data;
74
82
using m_base::get;
75
83
@@ -85,25 +93,21 @@ namespace stdsharp
85
93
private:
86
94
using typename m_base::ctor;
87
95
using typename m_base::dtor;
88
- using m_base::size_validate;
89
96
90
97
template <typename Allocation>
91
- [[nodiscard]] constexpr decltype (auto ) forward_value(const Allocation& src_allocation
92
- ) const noexcept
98
+ [[nodiscard]] constexpr decltype (auto ) forward_value(const Allocation& src) const noexcept
93
99
{
94
- size_validate (src_allocation);
95
- return static_cast <forward_value_t <Allocation>>(get (src_allocation));
100
+ return static_cast <forward_value_t <Allocation>>(get (src));
96
101
}
97
102
98
103
public:
99
104
constexpr void operator ()(
100
105
allocator_type& allocator,
101
106
const allocation<Allocator> auto & allocation,
102
- const default_construct_t /* unused*/
107
+ const m_base:: default_construct_t /* unused*/
103
108
) const noexcept (nothrow_invocable<ctor, allocator_type&, T*>)
104
109
requires std::invocable<ctor, allocator_type&, T*>
105
110
{
106
- size_validate (allocation);
107
111
ctor{}(allocator, data (allocation));
108
112
}
109
113
@@ -115,7 +119,6 @@ namespace stdsharp
115
119
const allocation<Allocator> auto & dst_allocation
116
120
) const noexcept (nothrow_invocable<ctor, allocator_type&, T*, Value>)
117
121
{
118
- size_validate (dst_allocation);
119
122
ctor{}(allocator, data (dst_allocation), forward_value (src_allocation));
120
123
}
121
124
@@ -126,7 +129,6 @@ namespace stdsharp
126
129
) const noexcept (nothrow_assignable_from<T&, Value>)
127
130
requires std::assignable_from<T&, Value>
128
131
{
129
- size_validate (dst_allocation);
130
132
get (dst_allocation) = forward_value (src_allocation);
131
133
}
132
134
@@ -135,7 +137,6 @@ namespace stdsharp
135
137
const allocation<Allocator> auto & allocation
136
138
) const noexcept
137
139
{
138
- size_validate (allocation);
139
140
dtor{}(allocator, data (allocation));
140
141
}
141
142
};
@@ -144,54 +145,50 @@ namespace stdsharp
144
145
struct allocation_value <Allocator, T[]> :// NOLINT(*-c-arrays)
145
146
private details::allocation_value<Allocator, T>
146
147
{
148
+ private:
147
149
using m_base = details::allocation_value<Allocator, T>;
148
150
151
+ friend m_base;
152
+
149
153
public:
150
- using typename m_base::allocation_traits;
151
- using typename m_base::allocator_traits;
152
154
using typename m_base::allocator_type;
153
- using typename m_base::size_type;
154
- using typename m_base::default_construct_t ;
155
- using m_base::default_construct;
156
- using m_base::data;
157
- using m_base::get;
158
155
159
156
private:
160
157
using typename m_base::ctor;
161
158
using typename m_base::dtor;
162
159
using size_t = std::size_t ;
163
- using m_base::size_validate;
164
160
165
161
size_t size_;
166
162
167
- [[nodiscard]] constexpr auto launder_begin (const auto & allocation) const noexcept
163
+ public:
164
+ [[nodiscard]] constexpr auto data (const auto & allocation) const noexcept
168
165
{
169
- size_validate (allocation);
170
- return launder_iterator{data (allocation)};
166
+ return launder_iterator{m_base::data (allocation)};
171
167
}
172
168
173
- [[nodiscard]] constexpr auto
174
- forward_launder_begin (const callocation<Allocator> auto & allocation) const noexcept
169
+ private:
170
+ template <typename Allocation>
171
+ using forward_value_t = m_base::template forward_value_t <Allocation>;
172
+
173
+ [[nodiscard]] constexpr auto forward_data (const callocation<Allocator> auto & allocation) //
174
+ const noexcept
175
175
{
176
- return launder_begin (allocation);
176
+ return data (allocation);
177
177
}
178
178
179
- [[nodiscard]] constexpr auto
180
- forward_launder_begin ( const allocation<Allocator> auto & allocation) const noexcept
179
+ [[nodiscard]] constexpr auto forward_data ( const allocation<Allocator> auto & allocation) //
180
+ const noexcept
181
181
{
182
- return std::move_iterator{launder_begin (allocation)};
182
+ return std::move_iterator{data (allocation)};
183
183
}
184
184
185
- template <typename Allocation>
186
- using forward_value_t = m_base::template forward_value_t <Allocation>;
187
-
188
- [[nodiscard]] constexpr auto forward_rng (const auto & allocation) const noexcept
185
+ public:
186
+ [[nodiscard]] constexpr auto get (const auto & allocation) const noexcept
189
187
{
190
- return std::views::counted (forward_launder_begin (allocation), size ());
188
+ return std::views::counted (data (allocation), size ());
191
189
}
192
190
193
- public:
194
- constexpr explicit allocation_value (const size_type size) noexcept : size_(size) {}
191
+ constexpr explicit allocation_value (const m_base::size_type size) noexcept : size_(size) {}
195
192
196
193
[[nodiscard]] constexpr auto size () const noexcept { return size_; }
197
194
@@ -202,12 +199,11 @@ namespace stdsharp
202
199
constexpr void operator ()(
203
200
allocator_type& allocator,
204
201
const allocation<Allocator> auto & allocation,
205
- const default_construct_t /* unused*/
202
+ const m_base:: default_construct_t /* unused*/
206
203
) const noexcept (nothrow_invocable<ctor, allocator_type&, T*>)
207
204
requires std::invocable<ctor, allocator_type&, T*>
208
205
{
209
- size_validate (allocation);
210
- auto begin = data (allocation);
206
+ auto begin = m_base::data (allocation);
211
207
for (const auto end = begin + size (); begin < end; ++begin) ctor{}(allocator, begin);
212
208
}
213
209
@@ -219,36 +215,31 @@ namespace stdsharp
219
215
) const noexcept (nothrow_invocable<ctor, allocator_type&, T*, Value>)
220
216
requires std::invocable<ctor, allocator_type&, T*, Value>
221
217
{
222
- size_validate (dst_allocation);
223
-
224
- const auto & dst_begin = data (dst_allocation);
225
- const auto & src_begin = forward_launder_begin (src_allocation);
218
+ const auto & dst_begin = m_base::data (dst_allocation);
219
+ const auto & src_begin = forward_data (src_allocation);
226
220
const auto count = size ();
227
221
228
- for (size_t i = 0 ; i < count; ++i) ctor{}(allocator, dst_begin[i] , src_begin[i]);
222
+ for (size_t i = 0 ; i < count; ++i) ctor{}(allocator, dst_begin + i , src_begin[i]);
229
223
}
230
224
231
225
template <typename Allocation, typename Value = forward_value_t <Allocation>>
232
226
constexpr void operator ()(
233
227
const Allocation& src_allocation,
234
228
const allocation<Allocator> auto & dst_allocation
235
- ) const noexcept (nothrow_assignable_from<T, Value>)
236
- requires std::assignable_from<T, Value>
229
+ ) const noexcept (nothrow_assignable_from<T& , Value>)
230
+ requires std::assignable_from<T& , Value>
237
231
{
238
- std::ranges::copy_n (
239
- launder_begin (src_allocation),
240
- size (),
241
- forward_launder_begin (dst_allocation)
242
- );
232
+ std::ranges::copy_n (forward_data (dst_allocation), size (), data (src_allocation));
243
233
}
244
234
245
235
constexpr void operator ()(
246
236
allocator_type& allocator,
247
237
const allocation<Allocator> auto & allocation
248
238
) const noexcept
249
239
{
250
- auto && begin = launder_begin (allocation);
251
- for (const auto & end = begin + size (); begin < end; ++begin) dtor{}(allocator, begin);
240
+ auto && begin = m_base::data (allocation);
241
+ for (const auto & end = begin + size (); begin < end; ++begin)
242
+ dtor{}(allocator, std::launder (begin));
252
243
}
253
244
};
254
245
}
0 commit comments