|
Boost : |
From: David Abrahams (dave_at_[hidden])
Date: 2002-11-01 22:43:17
"Andrei Alexandrescu" <andrewalex_at_[hidden]> writes:
> "David Abrahams" <dave_at_[hidden]> wrote in message
> news:uiszghmba.fsf_at_boost-consulting.com...
> > And, BTW, techniques like Mojo are not transparent. They /do/ affect
> > interface in subtle ways.
>
> That's true; however, Kevin's point is that Foo(T) and Foo(const T&) are not
> different semantic interfaces. I agree with that. It is true that they are
> different syntactic interfaces, and that if one is really nitpicky, there
> are conceivable semantic differences in what you can do and what you can't
> in each case. (For example, you can change the exceptions thrown if you
> create the copy inside Foo.) My belief, however, is that the semantics are
> identical beyond reasonable concern.
That's what I wanted to think, but then there was Doug Gregor's
example:
template <class T> int f(T);
template <class T> int g(T const&);
void h(int);
int x1 = f(h);
int x2 = g(h);
> (This discussion is independent of Mojo. I believe the advice to
> ***consider*** replacing Foo(const T&) with Foo(T) if you plan on making a
> copy of T inside Foo is valid regardless on whether you implement the Mojo
> protocol or not.)
Yeah, well it was my suggestion that we consider replacing `T const&'
with `T' in argument lists in the documentation if the argument may be
copied, even if we actually use T const& in the
implementation. However, that would be lying to the user, because then
she can't pass a function without taking its address.
Yes, this is another reason to pass arguments by value when you might
copy.
-- David Abrahams dave_at_[hidden] * http://www.boost-consulting.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk