|
Boost : |
From: Aleksey Gurtovoy (alexy_at_[hidden])
Date: 2000-02-02 19:28:46
Dave Abrahams <abrahams_at_[hidden]> wrote:
> on 2/1/00 6:03 PM, Aleksey Gurtovoy at alexy_at_[hidden] wrote:
>
>> 2) probably we need two versions of each 'fill' operator - one with a
>> 'const' and another with a non-const reference to the first argument,
>> e.g.
>>
>> | template<class T1, class T2>
>> | point<T1, T2>
>> | operator <<( const point<T1, T2>&, const POINT& from ) {
>> | return point<T1, T2>( from.x, from.y );
>> | }
>> |
>> | template<class T1, class T2>
>> | point<T1, T2>&
>> | operator <<( point<T1, T2>& to, const POINT& from ) {
>> | return to.x( from.x ).y( from.y );
>> | }
>>
>> otherwise (with only 'const' reference version) the result of
>> following expression seems strange for me:
>
> Why would we bother with the one taking a const ref to its first argument?
>
Because if we sank it, we would lose a possibility to initialize point
objects by converted values, e.g.
| typedef boost::geometry2d::point<long> point;
| point p1( 10, 15 );
| POINT p2( POINT() << p1 ); // (1) now illegal
| point p3( point() << p2 ); // (2) illegal, too
instead, we have to use 'two step initialization':
| POINT p2;
| p2 << p1;
| point p3;
| p3 << p2;
I hate to write such a code and I think this is really a bad thing...
Interesting enough, it seems nor MSVC6.0 nor Metrowerks 5.3
does follow the standard in this question.
MSVC happily compiles the illegal code above and this one:
| typedef boost::geometry2d::point<long> point;
| point& foo_point( point& p ) { return p; }
|
| void f() {
| foo_point( point() ); // (3)
| foo_point( point() + point() ); // (4)
| point() = point(); // (5)
| ( point() + point() ) = point(); // (6)
| }
and gives warning messages for lines (1)-(4) only with a
warning level 4 - which is almost never used in real life
because it produces many other useless messages...
And Metrowerks 5.3 rejects only lines (1) and (4)...
but if I comment out a point's template assignment
operator, it also rejects line (6) - as if it use this
operator instead an implicitly generated copy
assignment operator...
And if I define an empty constructor for POINT struct,
e.g.
struct POINT
{
long x;
long y;
POINT() {}
};
then line (1) would be also accepted..
This is sad.. I thought Metrowerks have much better
compiler than it seems to me now...
But anyway, Dave - we need two versions of 'fill' operator, right?
-Alexy
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk