@@ -63,9 +63,6 @@ union inline_array_or_vector {
6363 heap_vector (std::size_t count, VectorT value) : vec(count, value) {}
6464 };
6565
66- static_assert (std::is_nothrow_move_assignable<ArrayT>::value,
67- " this class is not exception safe" );
68-
6966 inline_array iarray;
7067 heap_vector hvector;
7168
@@ -84,20 +81,16 @@ union inline_array_or_vector {
8481 return result;
8582 }
8683
87- void destruct () {
88- if (!is_inline ()) {
84+ inline_array_or_vector () : iarray () {}
85+
86+ ~inline_array_or_vector () {
87+ if (is_inline ()) {
88+ iarray.~inline_array ();
89+ } else {
8990 hvector.~heap_vector ();
90- } else if (!std::is_trivially_destructible<ArrayT>::value) {
91- for (size_t i = 0 ; i < iarray.size ; ++i) {
92- iarray.arr [i].~ArrayT ();
93- }
9491 }
9592 }
9693
97- inline_array_or_vector () : iarray () {}
98-
99- ~inline_array_or_vector () { destruct (); }
100-
10194 // Disable copy ctor and assignment.
10295 inline_array_or_vector (const inline_array_or_vector &) = delete ;
10396 inline_array_or_vector &operator =(const inline_array_or_vector &) = delete ;
@@ -116,7 +109,11 @@ union inline_array_or_vector {
116109 return *this ;
117110 }
118111
119- destruct ();
112+ if (is_inline ()) {
113+ iarray.~inline_array ();
114+ } else {
115+ hvector.~heap_vector ();
116+ }
120117
121118 if (rhs.is_inline ()) {
122119 new (&iarray) inline_array (std::move (rhs.iarray ));
@@ -218,7 +215,9 @@ struct small_vector {
218215 heap_vector hv;
219216 hv.vec .reserve (reserved_size);
220217 static_assert (std::is_nothrow_move_assignable<T>::value,
221- " this class is not exception safe" );
218+ " this conversion is not exception safe" );
219+ static_assert (std::is_nothrow_move_constructible<heap_vector>::value,
220+ " this conversion is not exception safe" );
222221 std::move (ha.arr .begin (), ha.arr .begin () + ha.size , std::back_inserter (hv.vec ));
223222 new (&m_repr.hvector ) heap_vector (std::move (hv));
224223 }
0 commit comments