variant icon indicating copy to clipboard operation
variant copied to clipboard

Implement swap.

Open joto opened this issue 10 years ago • 1 comments

In the current code there is no implementation for swap() which means std::swap() will be used. This should do the right thing (as long as the move constructor and move assignment do the right thing) and the tests show this.

But this solution is not optimal, because the default std::swap() will always do one move construction and two move assignments (in this case of the variant). If there is a more efficient swap for the type in the variant, it will not be used. The upcoming standard P0088R0 describes the effects of swap as: "if index() == rhs.index(), calls swap(get<i>(*this), get<i>(hrs)) with i being index(). Else calls swap(*this, hrs)."

We might want to implement our own swap in the future.

joto avatar Jan 29 '16 14:01 joto

@joto - do you have plans for swap? Should we steal swap from std::variant ?

artemp avatar Jan 06 '17 15:01 artemp