|
@@ -113,20 +113,30 @@ public:
|
|
|
|
|
|
|
|
variant(const variant<Ts...>& old) : type_id(old.type_id), data()
|
|
variant(const variant<Ts...>& old) : type_id(old.type_id), data()
|
|
|
{
|
|
{
|
|
|
- helper_t::copy(num_types - old.type_id - 1, &old.data, &data);
|
|
|
|
|
|
|
+ helper_t::copy(num_types - type_id - 1, &old.data, &data);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
variant(variant<Ts...>&& old) : type_id(old.type_id), data()
|
|
variant(variant<Ts...>&& old) : type_id(old.type_id), data()
|
|
|
{
|
|
{
|
|
|
- helper_t::move(num_types - old.type_id - 1, &old.data, &data);
|
|
|
|
|
|
|
+ helper_t::move(num_types - type_id - 1, &old.data, &data);
|
|
|
|
|
+ old.type_id = invalid_type();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Serves as both the move and the copy asignment operator.
|
|
// Serves as both the move and the copy asignment operator.
|
|
|
- variant<Ts...>& operator= (variant<Ts...> old)
|
|
|
|
|
|
|
+ variant<Ts...>& operator= (variant<Ts...> const &old)
|
|
|
{
|
|
{
|
|
|
- std::swap(type_id, old.type_id);
|
|
|
|
|
- std::swap(data, old.data);
|
|
|
|
|
-
|
|
|
|
|
|
|
+ helper_t::destroy(num_types - type_id - 1, &data);
|
|
|
|
|
+ type_id = old.type_id;
|
|
|
|
|
+ helper_t::copy(num_types - type_id - 1, &old.data, &data);
|
|
|
|
|
+ return *this;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ variant<Ts...>& operator= (variant<Ts...> &&old)
|
|
|
|
|
+ {
|
|
|
|
|
+ helper_t::destroy(num_types - type_id - 1, &data);
|
|
|
|
|
+ type_id = old.type_id;
|
|
|
|
|
+ helper_t::move(num_types - type_id - 1, &old.data, &data);
|
|
|
|
|
+ old.type_id = invalid_type();
|
|
|
return *this;
|
|
return *this;
|
|
|
}
|
|
}
|
|
|
|
|
|