[RFA] Algorithms vs operator* and operator==
chris jefferson
caj@cs.york.ac.uk
Sun Nov 7 11:40:00 GMT 2004
Paolo Carlini wrote:
> Matt Austern wrote:
>
>> We're reinventing what Howard Hinnant calls "move semantics".
>> If we're going down this route, let's build on his work.
>
>
> I can only agree, in principle: some time ago I pointed Chris to some
> background literature about "move semantics" ;)
>
> However (comments very appreciated!) I gather that the clean and neat
> and general way to "move semantics" involves compiler support and
> Chris wants something rather simple, for the short/medium term. I'm
> under the impression that the improvement could be rather impressive
> in some cases, without too much added complexity.
>
Also, in the case of algorithms, I'm not convinced that move symantices
would help that much.
Under my understanding, move symantics can be split into two broad sections:
1) Some things involving temporaries that I'll admit I don't really
understand
2) The case where we have two variables x and y and we want to do "x=y"
without caring what happens to y, but require that y ends up in a
consistent state.
Looking at the classes I have access to, the most efficent way of
implementing (2) looks like it is usually either just doing x=y, or
doing swap(x,y). therefore move symantics are overkill for this when you
simply want to either do swap(x,y) or x=y.
Firther, if we know that we are performing swap(x,y) to "move y to x",
then we can often further optimise algorithms by never creating
temporary variables (as we don't have to bother storing x's value, it's
now in y).
Therefore, I argue that just specialising for using either swap or
assignment is a) simpler and b) at least as, and sometimes more efficent
than a general move operator.
However, I'm happy to be proved wrong by someone who knows more than me :)
Chris
More information about the Libstdc++
mailing list