mapbox/variant

Implement swap.

Opened this issue · 1 comments

joto commented

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 - do you have plans for swap? Should we steal swap from std::variant ?