File tree 4 files changed +32
-11
lines changed
4 files changed +32
-11
lines changed Original file line number Diff line number Diff line change @@ -139,22 +139,26 @@ struct champ
139
139
140
140
static node_t * empty ()
141
141
{
142
- static const auto node = node_t::make_inner_n (0 );
143
- return node->inc ();
142
+ static const auto empty_ = []{
143
+ constexpr auto size = node_t::sizeof_inner_n (0 );
144
+ static std::aligned_storage_t <size, alignof (std::max_align_t )> storage;
145
+ return node_t::make_inner_n_into (&storage, size, 0u );
146
+ }();
147
+ return empty_->inc ();
144
148
}
145
149
146
- champ (node_t * r, size_t sz = 0 )
150
+ champ (node_t * r, size_t sz = 0 ) noexcept
147
151
: root{r}
148
152
, size{sz}
149
153
{}
150
154
151
- champ (const champ& other)
155
+ champ (const champ& other) noexcept
152
156
: champ{other.root , other.size }
153
157
{
154
158
inc ();
155
159
}
156
160
157
- champ (champ&& other)
161
+ champ (champ&& other) noexcept
158
162
: champ{empty ()}
159
163
{
160
164
swap (*this , other);
@@ -167,13 +171,13 @@ struct champ
167
171
return *this ;
168
172
}
169
173
170
- champ& operator =(champ&& other)
174
+ champ& operator =(champ&& other) noexcept
171
175
{
172
176
swap (*this , other);
173
177
return *this ;
174
178
}
175
179
176
- friend void swap (champ& x, champ& y)
180
+ friend void swap (champ& x, champ& y) noexcept
177
181
{
178
182
using std::swap;
179
183
swap (x.root , y.root );
Original file line number Diff line number Diff line change @@ -222,12 +222,11 @@ struct node
222
222
return can_mutate (impl.d .data .inner .values , e);
223
223
}
224
224
225
- static node_t * make_inner_n ( count_t n)
225
+ static node_t * make_inner_n_into ( void * buffer, std:: size_t size, count_t n)
226
226
{
227
227
assert (n <= branches<B>);
228
- auto m = heap::allocate (sizeof_inner_n (n));
229
- auto p = new (m) node_t ;
230
- assert (p == (node_t *) m);
228
+ assert (size >= sizeof_inner_n (n));
229
+ auto p = new (buffer) node_t ;
231
230
#if IMMER_TAGGED_NODE
232
231
p->impl .d .kind = node_t ::kind_t ::inner;
233
232
#endif
@@ -237,6 +236,13 @@ struct node
237
236
return p;
238
237
}
239
238
239
+ static node_t * make_inner_n (count_t n)
240
+ {
241
+ assert (n <= branches<B>);
242
+ auto m = heap::allocate (sizeof_inner_n (n));
243
+ return make_inner_n_into (m, sizeof_inner_n (n), n);
244
+ }
245
+
240
246
static node_t * make_inner_n (count_t n, values_t * values)
241
247
{
242
248
auto p = make_inner_n (n);
Original file line number Diff line number Diff line change @@ -547,4 +547,9 @@ class map
547
547
impl_t impl_ = impl_t ::empty();
548
548
};
549
549
550
+ static_assert (std::is_nothrow_move_constructible<map<int , int >>::value,
551
+ " map is not nothrow move constructible" );
552
+ static_assert (std::is_nothrow_move_assignable<map<int , int >>::value,
553
+ " map is not nothrow move assignable" );
554
+
550
555
} // namespace immer
Original file line number Diff line number Diff line change @@ -292,4 +292,10 @@ class set
292
292
impl_t impl_ = impl_t ::empty();
293
293
};
294
294
295
+ static_assert (std::is_nothrow_move_constructible<set<int >>::value,
296
+ " set is not nothrow move constructible" );
297
+ static_assert (std::is_nothrow_move_assignable<set<int >>::value,
298
+ " set is not nothrow move assignable" );
299
+
300
+
295
301
} // namespace immer
You can’t perform that action at this time.
0 commit comments