Boost logo

Boost :

Subject: Re: [boost] [optional] little addition... optional_assign_to, optional_move_to, optional_swap? - Number of numbers in MIME From exceeds maximum threshold
From: Arno Schödl (aschoedl_at_[hidden])
Date: 2009-03-07 07:00:35


> Would you like to officially
  create a request ticket for those three member functions, at
https://svn.boost.org/trac/boost/newticket ?

Done.

> // Would not compile, trying to pass an optional<T> rvalue!
> if( !optional_move( t, TryToGetT () ) {
> // ... other way to get t ...
> }
>
>The following would compile though, even if
>optional<T>::optional_move_to(T&) is non-const:
>
> if( ! TryToGetT().optional_move_to(t) {
> // ... other way to get t ...
> }

Thank you for educating me! Just for overview:

struct S;

void change( S& s ) {}

struct S {
        bool m_b;
        void func() {
                change( *this );
        }
};

change( S() ); // does not compile
S().func(); // compiles
S().m_b=true; // does not compile (!)

I found this interesting:

struct T;

void change( T& s ) {}

struct T {
        // makes R-values non-const
        operator S&() {
                return *this;
        }
};

change( S() ); // compiles

S const s;
change( s ); // does not compile

Do you know if any of this will change with C++0x? I know about rvalue references, but will any of the above change as well?

Arno

--
Dr. Arno Schoedl · aschoedl_at_[hidden] 
Technical Director 
 
think-cell Software GmbH · Invalidenstr. 34 · 10115 Berlin, Germany 
http://www.think-cell.com · phone +49-30-666473-10 · toll-free (US) +1-800-891-8091
Directors: Dr. Markus Hannebauer, Dr. Arno Schoedl · Amtsgericht Charlottenburg, HRB 85229

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk