id summary reporter owner description type status milestone component version severity resolution keywords cc 7960 Optimization for move_assign and assign Antony Polukhin ebf "Current implementation of assignment and move assignment creates a `temp` variable if direct_assigner or direct_mover fail. We can avoid it, by checking if the type of variable to assign exactly matches one of the variant types. If it matches, we can do assign without creation of temporary variable. Here is some pseudo-code to show it: {{{ template void move_assign(T&& rhs) { // If direct T-to-T move assignment is not possible... detail::variant::direct_mover direct_move(rhs); if (this->apply_visitor(direct_move) == false) { if (is_in_varaint_types::value) { // ... but T is in varaint types, then destroy // content of storage and assign move_assigner visitor(*this, type_to_int::value); visitor.internal_visit(rhs, 0); } else { // ...then convert rhs to variant and assign: // // While potentially inefficient, the following construction of a // variant allows T as any type convertible to one of the bounded // types without excessive code redundancy. // variant temp( detail::variant::move(rhs) ); variant_assign( detail::variant::move(temp) ); } } } }}}" Feature Requests closed To Be Determined variant Boost 1.53.0 Optimization obsolete variant optimization assignment move