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
> >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
> 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.


Boost list run by bdawes at, gregod at, cpdaniel at, john at