From: Howard Hinnant (hinnant_at_[hidden])
Date: 2000-01-11 09:54:35
Kevlin Henney wrote on 1/11/2000 9:25 AM
>Just been thinking about the call_traits idea, and I'm a little unsure of
>it. For instance, "optimal" depends heavily on platform, algorithm, etc.
>Which suggests a lot of preprocessor conditionals to do the idea justice.
>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.
It is going to be the algorithm (method) writer that decides whether and
how to use call_traits, not client code. The algorithm writer will
hopefully be aware of the aliasing issues you speak of and act
accordingly. For example, a method that best takes an argument by value
to avoid aliasing problems will either not use call_traits, or perhaps
Only algorithms that can take an argument either by const T or const T&
would want to use call_traits::param_type. And only those types that are
both small and have trivial copy constructors should specialize to pass
by const T.
That being said, optimization is IMO just a small (potential) side
benefit of call_traits. The real value of call_traits lies in the
ability to handle array and reference types with ease. The solution
Dietmar Kühl presented in Kona for the make_pair("hi", ...) problem is a
perfect application for the call_traits array capability. And the same
song and dance, but with references was proposed by Steve Cleary for the
empty member optimization. Then it took the genius of Beman Dawes to
recognize the commonality and package the solution.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk