[Boost-bugs] [Boost C++ Libraries] #1841: Optional: C++0x features

Subject: [Boost-bugs] [Boost C++ Libraries] #1841: Optional: C++0x features
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2008-04-18 15:25:06


#1841: Optional: C++0x features
--------------------------------------+-------------------------------------
 Reporter: jgottman_at_[hidden] | Owner: fcacciola
     Type: Feature Requests | Status: new
Milestone: Boost 1.36.0 | Component: optional
  Version: Boost 1.35.0 | Severity: Optimization
 Keywords: |
--------------------------------------+-------------------------------------
 There are a couple of features in C++0x that would be very useful in the
 optional library. First is the emplace function (see [http://www.open-
 std.org/jtc1/sc22/wg21/docs/papers/2007/n2345.pdf]). This is how the
 C++0x containers will do in-place construction; optional should allow it
 as well so the same operation can be done in the same way. One issue is
 what to do if we call emplace on an optional that is not empty. We could
 assert, throw an exception, reset and then construct in-place, or
 construct out-of-place and then swap. Personally I prefer the third
 option.

 Second, optional should make use of rvalue-references where available.
 Note that if swap() were implemented using the move constructor and move
 assignment operator, then it would just do the right thing with respect to
 iterators to the standard containers.


 {{{
 template<class T>
 inline
 void optional_swap ( optional<T>& x, optional<T>& y )
 {
   if ( !x && !!y )
   {
     x.reset(std::move(*y));
     y.reset();
   }
   else if ( !!x && !y )
   {
     y.reset(std::move(*x));
     x.reset();
   }
   else if ( !!x && !!y )
   {
 // GCC > 3.2 and all other compilers have the using declaration at
 function scope (FLC)
 #ifndef BOOST_OPTIONAL_STD_SWAP_INTRODUCED_AT_NS_SCOPE
     // allow for Koenig lookup
     using std::swap ;
 #endif
     swap(*x,*y);
   }
 }
 }}}

--
Ticket URL: <http://svn.boost.org/trac/boost/ticket/1841>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.


This archive was generated by hypermail 2.1.7 : 2017-02-16 18:49:57 UTC