Boost logo

Boost :

From: scleary_at_[hidden]
Date: 2000-01-11 09:44:24


> John Maddock wrote:
> >Dicission Making: What is the optimal way to pass T as an argument - as
> >const T (by value) or const T& (by reference) - in other words to
implement
> >call_traits.
>
> However, I think the real problem I'm having with it lies in the fact that
> passing by const T and passing by const T& are not equivalent, so hiding
> the difference can lead to subtle pitfalls: Aliasing can easily come back
> to bite you: an algorithm can remove something from a container that
> invalidates the reference but not the copy. This would mean that the
> correctness of an algorithm could depend on properties of the data type
and
> platform that had nothing to do with the algorithm's requirements.
>
> Thoughts?
>

Aliasing is something to be aware of :). The documentation of call_traits
should point out this issue so that you don't write code that would fail
from dangling references -- when in doubt, just pass by const T instead of
using call_traits. I think this is all that is necessary, though.

        -Steve


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk