diff --git a/include/mapnik/util/variant.hpp b/include/mapnik/util/variant.hpp index 01db3a807..031b9e915 100644 --- a/include/mapnik/util/variant.hpp +++ b/include/mapnik/util/variant.hpp @@ -609,24 +609,33 @@ public: helper_type::move(old.type_index, &old.data, &data); } - void assign(variant & rhs) +private: + VARIANT_INLINE void copy_assign(variant const& rhs) { - if (type_index == rhs.type_index) - { - helper_type::direct_swap(rhs.type_index, &rhs.data, &data); - } - else - { - helper_type::destroy(type_index, &data); - type_index = detail::invalid_value; - helper_type::copy(rhs.type_index, &rhs.data, &data); - type_index = rhs.type_index; - } + helper_type::destroy(type_index, &data); + type_index = detail::invalid_value; + helper_type::copy(rhs.type_index, &rhs.data, &data); + type_index = rhs.type_index; } - VARIANT_INLINE variant& operator=(variant other) + VARIANT_INLINE void move_assign(variant && rhs) { - assign(other); + helper_type::destroy(type_index, &data); + type_index = detail::invalid_value; + helper_type::move(rhs.type_index, &rhs.data, &data); + type_index = rhs.type_index; + } + +public: + VARIANT_INLINE variant& operator=(variant && other) + { + move_assign(std::move(other)); + return *this; + } + + VARIANT_INLINE variant& operator=(variant const& other) + { + copy_assign(other); return *this; } @@ -636,7 +645,7 @@ public: VARIANT_INLINE variant& operator=(T && rhs) noexcept { variant temp(std::forward(rhs)); - assign(temp); + move_assign(std::move(temp)); return *this; } @@ -645,7 +654,7 @@ public: VARIANT_INLINE variant& operator=(T const& rhs) { variant temp(rhs); - assign(temp); + copy_assign(temp); return *this; }