P
peter koch
Markus Schoder skrev:
I agree that assigning to already constructed objects is non-optimal
and that you have to use somewhat unintuitive code for optimal
performance in that case. But my guess is that this situation occurs
rarely. And the other solution is counterintuitive in all cases.
would reduce the exception-guarantee for no benefit at all.
general case. So I'd just have to differ.
/Peter
Unfortunately this does not work for assigning to an already existing
vector.
You can still benefit from RVO by first creating a new vector
and then swapping it into the existing one but that is all but
intuitive and only works for fast swappable objects.
I agree that assigning to already constructed objects is non-optimal
and that you have to use somewhat unintuitive code for optimal
performance in that case. But my guess is that this situation occurs
rarely. And the other solution is counterintuitive in all cases.
In the example above you most likely could. But in the general case youYou can also just do result.clear() and use it directly.
would reduce the exception-guarantee for no benefit at all.
My opinion is that readability should be the number one priority in theBecause of what I said above I still think this approach has some value
even though it is more clumsy to use.
general case. So I'd just have to differ.
/Peter