2017-06-14 18:06 GMT+02:00 Peter Dimov via Boost
Andrzej Krzemienski wrote:
This does not mean that all assignments are strong. In
variant
v1, v2; v1 = v2;
the assignment is basic, because that's the guarantee > vector<string>::operator= gives.
Interesting. This satisfies the expectation that a number of people have expressed.
Exactly. For me basic is basic, regardless of whether the type stays the same, but apparently this does not match people's intuitive expectations.
But on the other hand, now that you are doing the double buffering
anyway, making the assignment strong would come almost fo free.
Not free here because the above variant doesn't double-buffer (because all alternatives are nothrow move constructible).
Ok, I see.
If we continue the example with projections: if I change from the drop
down menu from one mesh projection to another mesh projection, they are different projections, but can be encoded in the same type; maybe we should get the strong guarantee. If not in the assignment, then perhaps in a dedicated function.
You get the strong guarantee here in move assignment (because vector's move assignment doesn't throw (... except for unequal allocators ...)):
v1 = std::move(v2); // strong v1 = variant
(v2); // strong v1 = vector<string>{ "s1", "s2" }; // strong
and in emplace, because it doesn't use assignment:
v1.emplace
( ... ); // strong too
If you are not doing double buffering, how can you guarantee that `emplace` is strong? You move the original to the side? Regards, &rzej;