|
Boost : |
From: Beman Dawes (bdawes_at_[hidden])
Date: 2002-08-01 17:04:09
At 12:03 PM 8/1/2002, Jurko wrote:
>How about this example:
>
>// Some kind of a container class. Has a non const
>// member function void add( const Value& ) which adds
>// another value to the the container.
>class A;
>
>// A useful utility function.
>void foo( const A& );
>
>// A function that returns an object of class A by value.
>const A bar( void );
>
>Now we couldn't do this:
>foo( bar().add( someMissingValue ) );
>
>And in order to achieve the same effect we would have to
>eather copy the object returned by bar (potentially very
>expensive!) or give up using the useful foo function in this
>case (assuming we can't or don't want to change how foo()
>or bar() work).
>
>But then again I'm using the const value return rule and never
>came up against a real-world case where it presented even a
>slight problem.
As Bill Kempf pointed out, there are classes where that sort of non-const
operation chaining is an intended and desirable use. But that doesn't seem
to be the case with several of the path functions which return by value.
--Beman
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk