@@ -106,6 +106,12 @@ template<class... Ts> struct Variant {
106106 enum { npos = sizeof ...(Ts) }; // invalid state after exception - only destruction checks!
107107
108108private:
109+ static constexpr bool isNothrowCopyConstructible () {
110+ return (true && ... && std::is_nothrow_copy_constructible_v<Ts>);
111+ }
112+ static constexpr bool isNothrowCopyAssignable () {
113+ return (true && ... && std::is_nothrow_copy_constructible_v<Ts>);
114+ }
109115 template <class > struct IndexedVariant ;
110116
111117 template <size_t ... Is> struct IndexedVariant <std::index_sequence<Is...>> {
@@ -118,20 +124,20 @@ template<class... Ts> struct Variant {
118124 WhichValue which{npos};
119125 alignas (Ts...) std::byte storage[storage_size];
120126
121- constexpr IndexedVariant () {
127+ constexpr IndexedVariant () noexcept (std::is_nothrow_default_constructible_v<First>) {
122128 constructAs<First>();
123129 which = 0 ; // only initialize once constuction was successful
124130 }
125- ~IndexedVariant () {
131+ ~IndexedVariant () noexcept {
126132 if (which == npos) return ;
127133 destruct ();
128134 }
129135
130- constexpr IndexedVariant (const IndexedVariant& o) {
136+ constexpr IndexedVariant (const IndexedVariant& o) noexcept (isNothrowCopyConstructible()) {
131137 (((Is == o.which ? (constructAs<Ts>(*o.asPtr <Ts>()), 0 ) : 0 ), ...));
132138 which = o.which ;
133139 }
134- constexpr auto operator =(const IndexedVariant& o) -> IndexedVariant& {
140+ constexpr auto operator =(const IndexedVariant& o) noexcept (isNothrowCopyAssignable()) -> IndexedVariant& {
135141 if (which == o.which ) {
136142 (((Is == o.which ? (*amendAsPtr<Ts>() = *o.asPtr <Ts>(), 0 ) : 0 ), ...));
137143 }
@@ -144,11 +150,11 @@ template<class... Ts> struct Variant {
144150 return *this ;
145151 }
146152
147- constexpr IndexedVariant (IndexedVariant&& o) {
153+ constexpr IndexedVariant (IndexedVariant&& o) noexcept {
148154 (((Is == o.which ? (constructAs<Ts>(std::move (*o.amendAsPtr <Ts>())), 0 ) : 0 ), ...));
149155 which = o.which ; // o.which is needed for destruction!
150156 }
151- constexpr auto operator =(IndexedVariant&& o) -> IndexedVariant& {
157+ constexpr auto operator =(IndexedVariant&& o) noexcept -> IndexedVariant& {
152158 if (which == o.which ) {
153159 (((Is == o.which ? (*amendAsPtr<Ts>() = std::move (*o.amendAsPtr <Ts>()), 0 ) : 0 ), ...));
154160 }
0 commit comments