Boost logo

Boost-Commit :

From: fernando.cacciola_at_[hidden]
Date: 2007-11-02 18:55:50


Author: fcacciola
Date: 2007-11-02 18:55:49 EDT (Fri, 02 Nov 2007)
New Revision: 40704
URL: http://svn.boost.org/trac/boost/changeset/40704

Log:
Merged changests from RC_1_34_0 - base rev 33417
Removed:
   trunk/libs/optional/test/optional_test_ref_fail2.cpp
Text files modified:
   trunk/libs/optional/doc/optional.html | 453 +++++++++++++++++++++++++--------------
   trunk/libs/optional/test/Jamfile.v2 | 2
   trunk/libs/optional/test/optional_test.cpp | 58 ++++
   trunk/libs/optional/test/optional_test_ref.cpp | 18 +
   4 files changed, 362 insertions(+), 169 deletions(-)

Modified: trunk/libs/optional/doc/optional.html
==============================================================================
--- trunk/libs/optional/doc/optional.html (original)
+++ trunk/libs/optional/doc/optional.html 2007-11-02 18:55:49 EDT (Fri, 02 Nov 2007)
@@ -3,6 +3,7 @@
 <HTML>
 
 <HEAD>
+<meta http-equiv="Content-Language" content="en-us">
 <meta name="GENERATOR" content="Microsoft FrontPage 5.0">
 <meta name="ProgId" content="FrontPage.Editor.Document">
 <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1252">
@@ -23,6 +24,7 @@
   <DT>Examples</DT>
   <DT>Optional references</DT>
   <DT>Rebinding semantics for assignment of optional references</DT>
+ <DT>none_t and none</DT>
   <DT>In-Place Factories</DT>
   <DT>A note about optional<bool></DT>
   <DT>Exception Safety Guarantees</DT>
@@ -138,7 +140,7 @@
 <u>purpose</u> of optional&lt;T&gt; suggests
 an alternative model: a <i>container</i> that either has a value of T or nothing.
 </p>
-<p>As of this writing I don't know of any precedence for a variable-size fixed-capacity (of 1)
+<p>As of this writing I don't know of any precedent for a variable-size fixed-capacity (of 1)
 stack-based container model for optional values, yet I believe this is the consequence of
 the lack of practical implementations of such a container rather than an inherent shortcoming
 of the container model.</p>
@@ -348,7 +350,7 @@
     T const& get() const ;
     T& get() ;
 
- T<span lang="es"> const&amp;</span> get_value_or( T const&amp; default ) const ; <u><i>[new in 1.34]</u></i>
+ T const&amp; get_value_or( T const&amp; default ) const ; <u><i>[new in 1.34]</u></i>
     
     T const* operator -&gt;() const ;
     T* operator -&gt;() ;
@@ -383,11 +385,59 @@
 
 template&lt;class T&gt; inline bool operator >= ( optional&lt;T&gt; const& x, optional&lt;T&gt; const& y ) ;
 
+template&lt;class T&gt; inline bool operator == ( optional&lt;T&gt; const& x, T const& n ) ; <u><i>[new in 1.34]</u></i>
+
+template&lt;class T&gt; inline bool operator != ( optional&lt;T&gt; const& x, T const& n ) ; <u><i>[new in 1.34]</u></i>
+
+template&lt;class T&gt; inline bool operator < ( optional&lt;T&gt; const& x, T const& n ) ; <u><i>[new in 1.34]</u></i>
+
+template&lt;class T&gt; inline bool operator > ( optional&lt;T&gt; const& x, T const& n ) ; <u><i>[new in 1.34]</u></i>
+
+template&lt;class T&gt; inline bool operator <= ( optional&lt;T&gt; const& x, T const& n ) ; <u><i>[new in 1.34]</u></i>
+
+template&lt;class T&gt; inline bool operator >= ( optional&lt;T&gt; const& x, T const& n ) ; <u><i>[new in 1.34]</u></i>
+
+template&lt;class T&gt; inline bool operator == ( T const& n, optional&lt;T&gt; const& y ) ; <u><i>[new in 1.34]</u></i>
+
+template&lt;class T&gt; inline bool operator != ( T const& n, optional&lt;T&gt; const& y ) ; <u><i>[new in 1.34]</u></i>
+
+template&lt;class T&gt; inline bool operator < ( T const& n, optional&lt;T&gt; const& y ) ; <u><i>[new in 1.34]</u></i>
+
+template&lt;class T&gt; inline bool operator > ( T const& n, optional&lt;T&gt; const& y ) ; <u><i>[new in 1.34]</u></i>
+
+template&lt;class T&gt; inline bool operator <= ( T const& n, optional&lt;T&gt; const& y ) ; <u><i>[new in 1.34]</u></i>
+
+template&lt;class T&gt; inline bool operator >= ( T const& n, optional&lt;T&gt; const& y ) ; <u><i>[new in 1.34]</u></i>
+
+template&lt;class T&gt; inline bool operator == ( optional&lt;T&gt; const& x, none_t n ) ; <u><i>[new in 1.34]</u></i>
+
+template&lt;class T&gt; inline bool operator != ( optional&lt;T&gt; const& x, none_t n ) ; <u><i>[new in 1.34]</u></i>
+
+template&lt;class T&gt; inline bool operator < ( optional&lt;T&gt; const& x, none_t n ) ; <u><i>[new in 1.34]</u></i>
+
+template&lt;class T&gt; inline bool operator > ( optional&lt;T&gt; const& x, none_t n ) ; <u><i>[new in 1.34]</u></i>
+
+template&lt;class T&gt; inline bool operator <= ( optional&lt;T&gt; const& x, none_t n ) ; <u><i>[new in 1.34]</u></i>
+
+template&lt;class T&gt; inline bool operator >= ( optional&lt;T&gt; const& x, none_t n ) ; <u><i>[new in 1.34]</u></i>
+
+template&lt;class T&gt; inline bool operator == ( none_t n, optional&lt;T&gt; const& y ) ; <u><i>[new in 1.34]</u></i>
+
+template&lt;class T&gt; inline bool operator != ( none_t n, optional&lt;T&gt; const& y ) ; <u><i>[new in 1.34]</u></i>
+
+template&lt;class T&gt; inline bool operator < ( none_t n, optional&lt;T&gt; const& y ) ; <u><i>[new in 1.34]</u></i>
+
+template&lt;class T&gt; inline bool operator > ( none_t n, optional&lt;T&gt; const& y ) ; <u><i>[new in 1.34]</u></i>
+
+template&lt;class T&gt; inline bool operator <= ( none_t n, optional&lt;T&gt; const& y ) ; <u><i>[new in 1.34]</u></i>
+
+template&lt;class T&gt; inline bool operator >= ( none_t n, optional&lt;T&gt; const& y ) ; <u><i>[new in 1.34]</u></i>
+
 template&lt;class T&gt; inline optional&lt;T&gt; make_optional ( T const& v ) ; <u><i>[new in 1.34]</u></i>
 
 template&lt;class T&gt; inline optional&lt;T&gt; make_optional ( bool condition, T const& v ) ; <u><i>[new in 1.34]</u></i>
 
-template&lt;class T&gt; inline T <span lang="es">const&amp; </span>get_<span lang="es">optional_</span>value_or ( optional&lt;T&gt; const& opt, T const& default ) ; <u><i>[new in 1.34]</u></i>
+template&lt;class T&gt; inline T const&amp; get_optional_value_or ( optional&lt;T&gt; const& opt, T const& default ) ; <u><i>[new in 1.34]</u></i>
 
 template&lt;class T&gt; inline T const& get ( optional&lt;T&gt; const& opt ) ;
 
@@ -457,9 +507,11 @@
 </blockquote>
 <p><b>Example:</b></p>
   <blockquote>
- <pre>#include &lt;boost/none.hpp&gt;</pre>
- <pre>optional&lt;T&gt; n(none) ;
-assert ( !n ) ;</pre>
+<pre>
+#include &lt;boost/none.hpp&gt;
+optional&lt;int&gt; n(boost::none) ;
+assert ( !n ) ;
+</pre>
 </blockquote>
 </blockquote>
 
@@ -476,9 +528,11 @@
 </p>
 <p><b>Example:</b></p>
 <blockquote>
-<pre>T v;
+<pre>
+T v;
 optional&lt;T&gt; opt(v);
-assert ( *opt == v ) ;</pre>
+assert ( *opt == v ) ;
+</pre>
 </blockquote>
 </blockquote>
 
@@ -492,29 +546,32 @@
 <p><b>Throws:</b> Nothing.</p>
 <p><b>Example:</b></p>
 <blockquote>
-<pre>T v;
+<pre>
+T v;
 T&amp; vref = v ;
 optional&lt;T&amp;&gt; opt(vref);
 assert ( *opt == v ) ;
 ++ v ; // mutate referee
-assert (*opt == v); </pre>
+assert (*opt == v);
+</pre>
 </blockquote>
 </blockquote>
 
 <HR>
 
 <pre>optional&lt;T <i>(not a ref)</i>&gt;::optional( bool condition, T const&amp; v ) ;
-optional&lt;T&amp;&gt; <span lang="es"> </span>::optional( bool condition, T&amp; <span lang="es"> </span> v ) ;
+optional&lt;T&amp;&gt; ::optional( bool condition, T&amp; v ) ;
 </pre>
 
 <blockquote>
 <p>If <i>condition</i> is <code>true</code>, same as:</p>
 <pre>optional&lt;T <i>(not a ref)</i>&gt;::optional( T const&amp; v )
-optional&lt;T&amp;&gt;<span lang="es"> </span>::optional( T&amp;<span lang="es"> </span> v )
+optional&lt;T&amp;&gt; ::optional( T&amp; v )
 </pre>
 <p>otherwise, same as:</p>
-<pre>optional&lt;T <i>(not a ref)</i>&gt;::optional()
-optional&lt;T&amp;&gt;<span lang="es"> </span>::optional()
+<pre>
+optional&lt;T <i>(not a ref)</i>&gt;::optional()
+optional&lt;T&amp;&gt; ::optional()
 </pre>
 </blockquote>
 
@@ -533,7 +590,8 @@
 </p>
 <p><b>Example:</b></p>
 <blockquote>
- <pre>optional&lt;T&gt; uninit ;
+<pre>
+optional&lt;T&gt; uninit ;
 assert (!uninit);
 
 optional&lt;T&gt; uinit2 ( uninit ) ;
@@ -562,7 +620,8 @@
 reefer to the same object<b> </b>(they alias).</p>
 <p><b>Example:</b></p>
 <blockquote>
- <pre>optional&lt;T&amp;&gt; uninit ;
+<pre>
+optional&lt;T&amp;&gt; uninit ;
 assert (!uninit);
 
 optional&lt;T&amp;&gt; uinit2 ( uninit ) ;
@@ -605,7 +664,8 @@
 <p><b>Example:</b></p>
 <blockquote>
 
-<pre>optional&lt;double&gt; x(123.4);
+<pre>
+optional&lt;double&gt; x(123.4);
 assert ( *x == 123.4 ) ;
 
 optional&lt;int&gt; y(x) ;
@@ -633,7 +693,8 @@
 <p><b>Example:</b></p>
 <blockquote>
 
-<pre>class C { C ( char, double, std::string ) ; } ;
+<pre>
+class C { C ( char, double, std::string ) ; } ;
 
 C v('A',123.4,&quot;hello&quot;);
 
@@ -649,6 +710,27 @@
 
 <HR>
 
+<pre>optional&amp; optional&lt;T</i>&gt;::operator= ( none_t n ) ;</pre>
+<blockquote>
+<p><b>Effect:</b> Same as opeator=(optional const&amp; rhs), when rhs is default-constructed (uninitialized).</p>
+<p><b>Postconditions:</b> <b>*this</b> is uninitialized</p>
+<p><b>Example:</b></p>
+<blockquote>
+<pre>
+#include &lt;boost/none.hpp&gt;
+
+optional&lt;int&gt; def ;
+optional&lt;int&gt; opt(123) ;
+
+opt = boost::none ;
+
+assert ( opt == def ) ;
+</pre>
+</blockquote>
+</blockquote>
+
+<HR>
+
 <pre>optional&amp; optional&lt;T <i>(not a ref)</i>&gt;::operator= ( T const&amp; rhs ) ;</pre>
 <blockquote>
 <p><b>Effect:</b> Assigns the value 'rhs' to an <b>optional</b>.</p>
@@ -664,7 +746,8 @@
 properly uninitialized]</p>
 <p><b>Example:</b></p>
 <blockquote>
- <pre>T x;
+<pre>
+T x;
 optional&lt;T&gt; def ;
 optional&lt;T&gt; opt(x) ;
 
@@ -687,7 +770,8 @@
 new object. See here for details on this behavior.</p>
 <p><b>Example:</b></p>
 <blockquote>
- <pre>int a = 1 ;
+<pre>
+int a = 1 ;
 int b = 2 ;
 T&amp; ra = a ;
 T&amp; rb = b ;
@@ -817,7 +901,7 @@
 <HR>
 <pre>void optional&lt;T&gt;::reset() ;</pre>
 <blockquote>
-<p><b>Deprecated: </b>Same as operator=( detail::none_t );</p>
+<p><b>Deprecated: </b>Same as operator=( none_t n);</p>
 </blockquote>
 
 <HR>
@@ -852,32 +936,6 @@
 
 <HR>
 
-<pre>T const&amp; optional&lt;T <i>(not a ref)</i>&gt;::get_value_or( T const&amp; default) const ;
-T&amp; optional&lt;T <i>(not a ref)</i>&gt;::get_value_or( T&amp; default ) ;
-
-inline T const&amp; get_optional_value_or ( optional&lt;T<i> (not a ref)</i>&gt; const&amp; o, T const&amp; default ) ;
-inline T&amp; get_optional_value_or ( optional&lt;T <i>(not a ref)</i>&gt;&amp; o, T&amp; default ) ;
-</pre>
-<blockquote>
-<p><b>Returns:</b> A reference to the contained value, if any, or <code>default</code></p>
-<p><b>Throws:</b> Nothing.</p>
-<p><b>Example:</b></p>
-<blockquote>
- <pre>T v, z ;
-optional&lt;T&gt; def;
-T const&amp; y = def.get_value_or(z);
-assert ( y == z ) ;
-
-optional&lt;T&gt; opt ( v );
-T const&amp; u = get_optional_value_or(opt,z);
-assert ( u == v ) ;
-assert ( u != z ) ;
-</pre>
- </blockquote>
- <pre></pre>
-</blockquote>
-<HR>
-
 
 <pre>T const&amp; optional&lt;T&amp;&gt;::operator*() const ;
 T &amp; optional&lt;T<i>&amp;</i>&gt;::operator*();</pre>
@@ -907,29 +965,66 @@
 
 <HR>
 
-<pre>T const* optional&lt;T <i>(not a ref)</i>&gt;::get_ptr() const ;
-T* optional&lt;T <i>(not a ref)</i>&gt;::get_ptr() ;
+<pre>T const&amp; optional&lt;T&gt;::get_value_or( T const&amp; default) const ;
+T&amp; optional&lt;T&gt;::get_value_or( T&amp; default ) ;
+
+inline T const&amp; get_optional_value_or ( optional&lt;T&gt; const&amp; o, T const&amp; default ) ;
+inline T&amp; get_optional_value_or ( optional&lt;T&gt;&amp; o, T&amp; default ) ;
+</pre>
+<blockquote>
+<p><b>Returns:</b> A reference to the contained value (which can be itself a reference), if any, or <code>default</code></p>
+<p><b>Throws:</b> Nothing.</p>
+<p><b>Example:</b></p>
+<blockquote>
+ <pre>T v, z ;
+optional&lt;T&gt; def;
+T const&amp; y = def.get_value_or(z);
+assert ( y == z ) ;
+
+optional&lt;T&gt; opt ( v );
+T const&amp; u = get_optional_value_or(opt,z);
+assert ( u == v ) ;
+assert ( u != z ) ;
+</pre>
+ </blockquote>
+ <pre></pre>
+</blockquote>
+
+<HR>
+
+<pre>T const* optional&lt;T&gt;::get_ptr() const ;
+T* optional&lt;T&gt;::get_ptr() ;
 
-inline T const* get_pointer ( optional&lt;T <i>(not a ref)</i>&gt; const&amp; ) ;
-inline T* get_pointer ( optional&lt;T <i>(not a ref)</i>&gt; &amp;) ;
+inline T const* get_pointer ( optional&lt;T&gt; const&amp; ) ;
+inline T* get_pointer ( optional&lt;T&gt; &amp;) ;
 </pre>
 <blockquote>
 <p><b>Returns:</b> If <b>*this</b> is initialized, a pointer to the contained
 value; else 0 (<i>null</i>).
 </p>
 <p><b>Throws:</b> Nothing.</p>
+<p><b>Notes:</b> If T is a reference type, the pointer is to the referenced object</p>
 <p><b>Notes:</b> The contained value is permanently stored within *this, so
-you should not hold nor delete this pointer
+you should not hold nor delete this pointer.
 </p>
 <p><b>Example:</b></p>
 <blockquote>
- <pre>T v;
-optional&lt;T&gt; opt(v);
-optional&lt;T&gt; const copt(v);
-T* p = opt.get_ptr() ;
-T const* cp = copt.get_ptr();
+ <pre>int v=123;
+optional&lt;int&gt; opt(v);
+optional&lt;int&gt; const copt(v);
+int* p = opt.get_ptr() ;
+int const* cp = copt.get_ptr();
 assert ( p == get_pointer(opt) );
 assert ( cp == get_pointer(copt) ) ;
+
+int& rv = v ;
+optional&lt;int&amp;&gt; optr(rv);
+
+*(optr.get_ptr()) = 456 ;
+
+assert ( v == 456 );
+
+
 </pre>
 </blockquote>
 </blockquote>
@@ -938,13 +1033,14 @@
 <HR>
 
 
-<pre>T const* optional&lt;T <i>(not a ref)</i>&gt;::operator -&gt;() const ;
-T* optional&lt;T <i>(not a ref)</i>&gt;::operator -&gt;() ;
+<pre>T const* optional&lt;T&gt;::operator -&gt;() const ;
+T* optional&lt;T&gt;::operator -&gt;() ;
 </pre>
 <blockquote>
 <p><b>Requirements: *this</b> is initialized.</p>
 <p><b>Returns:</b> A pointer to the contained value.</p>
 <p><b>Throws:</b> Nothing.</p>
+<p><b>Notes:</b> If T is a reference type, the pointer is to the referenced object</p>
 <p><b>Notes:</b> The requirement is asserted via BOOST_ASSERT().</p>
 <p><b>Example:</b></p>
 <blockquote>
@@ -952,6 +1048,14 @@
 X x ;
 optional&lt;X&gt; opt (x);
 opt-&gt;mdata = 2 ;
+
+X& rx = x ;
+
+optional&lt;X&amp;&gt; optr (rx);
+optr-&gt;mdata = 4 ;
+
+assert ( x.mdata = 4 )
+
 </pre>
 </blockquote>
 </blockquote>
@@ -1155,12 +1259,49 @@
 </blockquote>
 
 <HR>
+<pre>
+bool operator == ( optional&lt;T&gt; const&amp; x, T const&amp; n );
+bool operator != ( optional&lt;T&gt; const&amp; x, T const&amp; n );
+bool operator &lt; ( optional&lt;T&gt; const&amp; x, T const&amp; n );
+bool operator &gt; ( optional&lt;T&gt; const&amp; x, T const&amp; n );
+bool operator &lt;= ( optional&lt;T&gt; const&amp; x, T const&amp; n );
+bool operator &gt;= ( optional&lt;T&gt; const&amp; x, T const&amp; n );
+bool operator == ( T const&amp; n, optional&lt;T&gt; const&amp; y );
+bool operator != ( T const&amp; n, optional&lt;T&gt; const&amp; y );
+bool operator &lt; ( T const&amp; n, optional&lt;T&gt; const&amp; y );
+bool operator &gt; ( T const&amp; n, optional&lt;T&gt; const&amp; y );
+bool operator &lt;= ( T const&amp; n, optional&lt;T&gt; const&amp; y );
+bool operator &gt;= ( T const&amp; n, optional&lt;T&gt; const&amp; y );
+</pre>
+<blockquote>
+ <p><b>Returns:</b> The result obtained by replacing the argument 'n' by optional&lt;T&gt;(n).</p>
+</blockquote>
+
+<HR>
+<pre>
+bool operator == ( optional&lt;T&gt; const&amp; x, none_t n );
+bool operator != ( optional&lt;T&gt; const&amp; x, none_t n );
+bool operator &lt; ( optional&lt;T&gt; const&amp; x, none_t n );
+bool operator &gt; ( optional&lt;T&gt; const&amp; x, none_t n );
+bool operator &lt;= ( optional&lt;T&gt; const&amp; x, none_t n );
+bool operator &gt;= ( optional&lt;T&gt; const&amp; x, none_t n );
+bool operator == ( none_t n, optional&lt;T&gt; const&amp; y );
+bool operator != ( none_t n, optional&lt;T&gt; const&amp; y );
+bool operator &lt; ( none_t n, optional&lt;T&gt; const&amp; y );
+bool operator &gt; ( none_t n, optional&lt;T&gt; const&amp; y );
+bool operator &lt;= ( none_t n, optional&lt;T&gt; const&amp; y );
+bool operator &gt;= ( none_t n, optional&lt;T&gt; const&amp; y );
+</pre>
+<blockquote>
+ <p><b>Returns:</b> The result obtained by replacing the argument 'n' by optional&lt;T&gt;().</p>
+</blockquote>
+<HR>
 
 <pre>void swap ( optional&lt;T&gt;&amp x, optional&lt;T&gt&amp y );</pre>
 
 <blockquote>
 <p><b>Effect:</b> If both <b>x</b> and <b>y</b> are initialized, calls <code>swap(*x,*y)</code> using std::swap.<br>
-If only one is initialized, say x, calls: <code>y.reset(*x); x.reset();</code><br>
+If only one is initialized, say x, calls: <code>y = *x; x = boost:none;</code><br>
 If none is initialized, does nothing. </p>
 <p><b>Postconditions:</b> The states of x and y interchanged.</p>
 <p><b>Throws:</b> If both are initialized, whatever swap(T&amp;,T&amp;) throws.
@@ -1169,7 +1310,7 @@
 If only one is initialized, T::~T() and T::T( T const& ) is called. </p>
 <p><b>Exception Safety:</b> If both are initialized, this operation has the exception
 safety guarantees of swap(T&,T&).<br>
-If only one is initialized, it has the same <b>basic</b> guarantee as optional&lt;T&gt;::reset( T const& ). </p>
+If only one is initialized, it has the same <b>basic</b> guarantee as optional&lt;T&gt;::operator=( T const& ). </p>
 <p><b>Example:</b></p>
 <blockquote>
       <pre>T x(12);
@@ -1219,12 +1360,12 @@
 <pre>optional&lt;string&gt; name ;
 if ( database.open() )
 {
-&nbsp; name.reset ( database.lookup(employer_name) ) ;
+&nbsp; name = database.lookup(employer_name) ;
 }
 else
 {
 &nbsp; if ( can_ask_user )
-&nbsp;&nbsp;&nbsp; name.reset ( user.ask(employer_name) ) ;
+&nbsp;&nbsp;&nbsp; name = user.ask(employer_name) ;
 }
 
 if ( name )
@@ -1245,7 +1386,7 @@
 &nbsp;&nbsp;&nbsp; void clip_in_rect ( rect const&amp; rect )
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ....
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; m_clipping_rect.reset ( rect ) ; // initialized here.
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; m_clipping_rect = rect ; // initialized here.
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
 
 &nbsp;&nbsp;&nbsp; void draw ( canvas& cvs )
@@ -1289,16 +1430,17 @@
   <li>Converting assignment</li>
   <li>InPlace construction</li>
   <li>InPlace assignment</li>
- <li>Value-access via pointer</li>
 </ul>
 <p>Also, even though optional&lt;T&amp;&gt; treats it wrapped pseudo-object much as a real
-value, a true real reference is stored so aliasing will ocurr: </p>
+value, a true real reference is stored, thus aliasing can ocurr: </p>
 
 <ul>
- <li>Copies of optional&lt;T&amp;&gt; will copy the references but all these references
+ <li>Copies of optional&lt;T&amp;&gt; copies the reference, but all copied references
   will nonetheless reefer to the same object.</li>
- <li>Value-access will actually provide access to the referenced object rather
+ <li>Value-access provides access to the referenced object rather
   than the reference itself.</li>
+ <li>Pointer-access provides a pointer to the referenced object rather
+ than a pointer to the reference itself.</li>
 </ul>
 
 <HR>
@@ -1309,7 +1451,7 @@
 <pre>int x = 1 ;
 int&amp; rx = x ;
 optional&lt;int&amp;&gt; ora ;
-optional&lt;int&amp;&gt; orb(x) ;
+optional&lt;int&amp;&gt; orb(rx) ;
 ora = orb ; // now 'ora'&nbsp;is bound to 'x' through 'rx'
 *ora = 2 ; // Changes value of 'x' through 'ora'
 assert(x==2);
@@ -1320,7 +1462,7 @@
 int&amp; ra = a ;
 int b = 2 ;
 int&amp; rb = b ;
-ra = rb ; // Changes the value of 'a' to 'b'
+ra = rb ; // Changes the VALUE of 'a' to that of 'b'
 assert(a==b);
 b = 3 ;
 assert(ra!=b); // 'ra' is not rebound to 'b'
@@ -1346,38 +1488,68 @@
 It is true that optional&lt;U&gt; strives to behave as much as possible as U does
 whenever it is initialized; but in the case when U is T&amp;, doing so would result
 in inconsistent behavior w.r.t to the lvalue initialization state.</p>
-<p>Imagine optional&lt;T&amp;&gt; forwarding assignment to the referenced object (thus
-changing the referenced object value but not rebinding), and consider the
-following code :</p>
-<pre>&nbsp; optional&lt;int&amp;&gt; a = get();
-&nbsp; int x = 1 ;
-&nbsp; int&amp; rx = x ;
-&nbsp; optional&lt;int&amp;&gt; b(rx);
-&nbsp; a = b ;
-</pre>
-<p>What does the assignment do?<br>
-If 'a' is <i>uninitialized</i>, the answer is clear: it binds to 'x' (we now have
-another reference to 'x').<br>
-But what if 'a' is already <i>initialized? </i>it would change the value of the
-referenced object (whatever that is); which is inconsistent with the other
-possible case.</p>
-<p>If optional&lt;T&amp;&gt; would assign just like T&amp; does, you would never be able to
-use Optional's assignment without explicitly handling the previous
-initialization state unless your code is capable of functioning whether after
-the assignment, 'a'
-aliases the same object as 'b' or not.</p>
-<p>That is, you would have to discriminate in order to be consistency.<br>
-<br>
-If in your code rebinding to another object is not an option, then is very
-likely that binding for the fist time isn't either. In such case, assignment to
-an <i>uninitialized</i> optional&lt;T&amp;&gt; shall be prohibited. It is quite
-possible that in such scenario the precondition that the lvalue must be already
-initialized exist. If it doesn't, then binding for the first time is OK while
-rebinding is not which is IMO
-very unlikely.<br>
-In such scenario, you can assign the value itself directly, as in:</p>
-<pre>assert(!!opt);
-*opt=value; </pre>
+<p>Consider the following code :</p>
+<pre>
+int x = 1 ;
+int& rx = x ;
+void foo ( optional&lt;int&amp;&gt; & outer )
+{
+ optional&lt;int&amp;&gt; b(rx);
+ outer = b ;
+}
+</pre>
+<p>What should the assignment to 'outer' do?<br>
+If 'outer' is <i>uninitialized</i>, the answer is clear: it should bind to 'x' (so we now have
+a second reference to 'x').<br>
+But what if 'outer' is already <i>initialized?</i><br>
+The assignment could change the value of the
+referenced object (whatever that is), but doing that would be inconsistent with the uninitialized case
+and then you wouldn't be able to reason at compile time about all the references to x since
+the appearance of a new reference to it would depend on wheter the lvalue ('outer')
+is initialized or not.</p>
+<p>Arguably, if rebinding the reference to another object is wrong for your code, then is
+likely that binding it for the fist time via assignment instead of intialization is also wrong.
+In that case, you can always just assign the value to the referenced object directly via
+the access operator <code>*opt=value</code>.</p>
+<p>If rebinding is wrong but first-time binding
+isn't (via assignment), you can always work around the rebinding semantics using a discriminator:</p>
+<pre>
+if ( !opt )
+ opt = value ; // first-time binding
+else *opt = value ; // assign to referee without rebinding
+</pre>
+
+<HR>
+
+<H2><A NAME="none">none_t and none</A></H2>
+<p>optional&lt;T&gt; supports uninitialized states with a convenient syntax via a constant of
+the <i>implementation-defined</i> type <code>boost::none_t</code>, identified as <code>boost::none</code>.</p>
+<p>Starting with Boost version 1.34.0, both <code>boost::none_t</code> and <code>boost::none</code> are
+included in <code>boost/none.hpp</code>, which is automatically included by <code>boost/optional/optional.hpp</code>
+</p>
+<p>This contant is similar in purpose to NULL, except that is not a <i>null pointer value</i>. You can use it to initialize
+an optional&lt;T&gt; instance, which has the same effect of a default constructor, and you can assign it which has the
+effect of reseting the optional&lt;T&gt; instance. You can also use it in relational operators to make the predicate expression
+more clear.</p>
+<p>Here are some typical examples:</p>
+<pre>
+#include "boost/optional/optional.hpp" // boost/none.hpp is included automatically
+
+boost::optional&lt;int&gt; foo ( int a )
+{
+ return some_condition(a) ? boost::make_optional(a) : boost::none ;
+
+ // NOTE: in real code you can just use this: make_optional(some_condition(a), a )
+}
+
+boost::optional&lt;int&gt; opt = boost::none ;
+
+if ( opt == boost::none )
+ opt = foo(123);
+
+opt = boost::none ;
+
+</pre>
 
 <HR>
 
@@ -1506,9 +1678,8 @@
 the <i>maybe</i> state <u>represents a valid value</u>, unlike the corresponding state
 of an uninitialized optional&lt;bool&gt;.<br>
 It should be carefully considered if an optional&lt;bool&gt; instead of a tribool is really needed</p>
-<p>Second, optional&lt;&gt; provides an implicit conversion to bool. This conversion
- refers to the initialization state and not to the contained value.<br>
-Using optional&lt;bool&gt; can lead to subtle errors due to the implicit bool conversion:</p>
+<p>Second, optional&lt;&gt; provides a simple way to test initialization state: an implicit conversion to a type that evaluates as a 'bool' in a boolean context.<br>
+Using optional&lt;bool&gt; can lead to subtle errors due to this implicit conversion:</p>
 <pre>void foo ( bool v ) ;
 void bar()
 {
@@ -1524,7 +1695,9 @@
 integral promotions don't apply (i.e. if foo() takes an 'int' instead, it won't compile). <HR>
 
 <H2><A NAME="exsafety">Exception Safety Guarantees</A></H2>
-<H3><u>Assignment and Reset:</u></H3>
+
+<H3><u>Assignment:</u></H3>
+<p><i>IMPORTANT NOTE: This changed in 1.33.1 with respect to previous versions</i></p>
 <p>Because of the current implementation (see Implementation Notes), all
 of the assignment methods:</p>
 <ul>
@@ -1537,60 +1710,17 @@
   InPlaceFactory const&amp; ) </code></li>
   <li> <code>template&lt;class TypedInPlaceFactory&gt; optional&lt;T&gt;::operator= (
   TypedInPlaceFactory const&amp; ) </code></li>
- <li> <code>optional&lt;T&gt;:::reset ( T const&amp;)</code></li>
 </ul>
-<p>Can only <i>guarantee</i> the <u>basic exception safety</u>: The lvalue optional is left <u>uninitialized</u> if an exception is thrown (any previous value is <i>first</i> destroyed using T::~T())</p>
+<p>cannot offer any <i>exception safety guarantee</i> beyond that provided by <code>T::operator=( T const&amp; )</code></p>
 <p>On the other hand, the <i>uninitializing</i> methods:</p>
 <ul>
   <li><code>optional&lt;T&gt;::operator= ( detail::none_t ) </code></li>
- <li><code>optional&lt;T&gt;::reset()</code></li>
 </ul>
-<p>Provide the no-throw guarantee (assuming a no-throw T::~T())</p>
-<p>However, since <code>optional&lt&gt</code> itself doesn't throw any exceptions,
-the only source for exceptions here are T's constructor, so if you know the exception guarantees
-for T::T ( T const&amp; ), you know that optional's assignment and reset has the same guarantees.</p>
-<pre>//
-// Case 1: Exception thrown during assignment.
-//
-T v0(123);
-optional&ltT&gt opt0(v0);
-try
-{
-&nbsp; T v1(456);
-&nbsp; optional&ltT&gt opt1(v1);
-&nbsp; opt0 = opt1 ;
-
-&nbsp; // If no exception was thrown, assignment succeeded.
-&nbsp; assert( *opt0 == v1 ) ;
-}
-catch(...)
-{
-&nbsp; // If any exception was thrown, 'opt0' is reset to uninitialized.
-&nbsp; assert( !opt0 ) ;
-}
-
-//
-// Case 2: Exception thrown during reset(v)
-//
-T v0(123);
-optional&ltT&gt opt(v0);
-try
-{
-&nbsp; T v1(456);
-&nbsp; opt.reset ( v1 ) ;
+<p>Provides the no-throw guarantee (assuming a no-throw T::~T()) becuse it only destroys the stored object.</p>
 
-&nbsp; // If no exception was thrown, reset succeeded.
-&nbsp; assert( *opt == v1 ) ;
-}
-catch(...)
-{
-&nbsp; // If any exception was thrown, 'opt' is reset to uninitialized.
-&nbsp; assert( !opt ) ;
-}
-</pre>
 <H3><u>Swap:</u></H3>
 <p><code>void swap( optional&lt;T&gt;&amp;, optional&lt;T&gt;&amp; )</code> has the same exception guarantee as <code>swap(T&amp;,T&amp;)</code> when both optionals are initialized.<br>
-If only one of the optionals is initialized, it gives the same <i>basic</i> exception guarantee as <code>optional&lt;T&gt;::reset( T const&amp; )</code> (since <code>optional&lt;T&gt;::reset()</code> doesn't throw).<br>
+If only one of the optionals is initialized, it gives the same exception guarantee as <code>T::operator=( T const&amp; )</code> (since <code>optional&lt;T&gt;::operator=( none_t )</code> doesn't throw).<br>
 If none of the optionals is initialized, it has no-throw guarantee since it is a no-op. </p>
 
 <HR>
@@ -1604,14 +1734,11 @@
 
 <H2><A NAME="impl">Implementation Notes</A></H2>
 <p>optional&lt;T&gt; is currently implemented
- using a custom aligned storage facility built from <code>alignment_of</code> and <code>type_with_alignment</code> (both from Type Traits).
- It uses a separate boolean flag to indicate the initialization state.<br>
- Placement new with T's copy constructor and T's destructor
- are explicitly used to initialize,copy and destroy optional values.<br>
- As a result, T's default constructor is effectively by-passed, but the exception
- guarantees are basic.<br>
- It is planned to replace the current implementation with another with
- stronger exception safety, such as a future boost::variant<T,nil_t>. </p>
+ using a custom aligned storage facility built from <code>alignment_of</code> and <code>type_with_alignment</code> (both from Type Traits).
+ It uses a separate boolean flag to indicate the initialization state.</p>
+<p>Placement new with T's copy constructor and T's destructor
+ is explicitly used to initialize and destroy optional values. This allows T's default constructor to be effectively by-passed.</p>
+<p>If assignment is used and the lvalue optional is uninitialized, T's copy constructor is used. However, if it is already initialized, T's assignment operator is used. This prevents optional from offering any exception guarantee stronger than the one offered by the type T itself</p>
 
 <HR>
 
@@ -1665,12 +1792,12 @@
 </blockquote>
 <HR>
 
-<P>Revised April 21, 2005</P>
-<p>© Copyright Fernando Luis Cacciola Carballal, 2003,2004,2005</p>
+<P>Revised March 27, 2007</P>
+<p>© Copyright Fernando Luis Cacciola Carballal, 2003-2007</p>
 <p> Use, modification, and distribution are subject to the Boost Software
 License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at www.boost.org/LICENSE_1_0.txt)</p>
 <P>Developed by <A HREF="mailto:fernando_cacciola_at_[hidden]">Fernando Cacciola</A>,
 the latest version of this file can be found at <A
 HREF="http://www.boost.org">www.boost.org</A>, and the boost discussion lists</P>
 </pre></BODY>
-</HTML>
+</HTML>
\ No newline at end of file

Modified: trunk/libs/optional/test/Jamfile.v2
==============================================================================
--- trunk/libs/optional/test/Jamfile.v2 (original)
+++ trunk/libs/optional/test/Jamfile.v2 2007-11-02 18:55:49 EDT (Fri, 02 Nov 2007)
@@ -22,11 +22,9 @@
     [ run optional_test_inplace.cpp ]
     [ run optional_test_io.cpp ]
     [ compile-fail optional_test_fail1.cpp ]
- [ compile-fail optional_test_fail2.cpp ]
     [ compile-fail optional_test_fail3a.cpp ]
     [ compile-fail optional_test_fail3b.cpp ]
     [ compile-fail optional_test_ref_fail1.cpp ]
- [ compile-fail optional_test_ref_fail2.cpp ]
     [ compile-fail optional_test_ref_fail3.cpp ]
     [ compile-fail optional_test_ref_fail4.cpp ]
     [ compile-fail optional_test_inplace_fail.cpp ]

Modified: trunk/libs/optional/test/optional_test.cpp
==============================================================================
--- trunk/libs/optional/test/optional_test.cpp (original)
+++ trunk/libs/optional/test/optional_test.cpp 2007-11-02 18:55:49 EDT (Fri, 02 Nov 2007)
@@ -704,16 +704,16 @@
 {
   TRACE( std::endl << BOOST_CURRENT_FUNCTION );
 
- T v0(18);
- T v1(19);
- T v2(19);
+ T v0(0);
+ T v1(1);
+ T v2(1);
 
   optional<T> def0 ;
   optional<T> def1 ;
   optional<T> opt0(v0);
   optional<T> opt1(v1);
   optional<T> opt2(v2);
-
+
   // Check identity
   BOOST_CHECK ( def0 == def0 ) ;
   BOOST_CHECK ( opt0 == opt0 ) ;
@@ -751,6 +751,33 @@
   BOOST_CHECK ( opt1 > opt0 ) ;
   BOOST_CHECK ( opt1 <= opt2 ) ;
   BOOST_CHECK ( opt1 >= opt0 ) ;
+
+ // Compare against a value directly
+ BOOST_CHECK ( opt0 == v0 ) ;
+ BOOST_CHECK ( opt0 != v1 ) ;
+ BOOST_CHECK ( opt1 == v2 ) ;
+ BOOST_CHECK ( opt0 < v1 ) ;
+ BOOST_CHECK ( opt1 > v0 ) ;
+ BOOST_CHECK ( opt1 <= v2 ) ;
+ BOOST_CHECK ( opt1 >= v0 ) ;
+ BOOST_CHECK ( v0 != opt1 ) ;
+ BOOST_CHECK ( v1 == opt2 ) ;
+ BOOST_CHECK ( v0 < opt1 ) ;
+ BOOST_CHECK ( v1 > opt0 ) ;
+ BOOST_CHECK ( v1 <= opt2 ) ;
+ BOOST_CHECK ( v1 >= opt0 ) ;
+ BOOST_CHECK ( def0 != v0 ) ;
+ BOOST_CHECK ( !(def0 == v0) ) ;
+ BOOST_CHECK ( def0 < v0 ) ;
+ BOOST_CHECK ( !(def0 > v0) ) ;
+ BOOST_CHECK ( def0 <= v0 ) ;
+ BOOST_CHECK ( !(def0 >= v0) ) ;
+ BOOST_CHECK ( v0 != def0 ) ;
+ BOOST_CHECK ( !(v0 == def0) ) ;
+ BOOST_CHECK ( !(v0 < def0) ) ;
+ BOOST_CHECK ( v0 > def0 ) ;
+ BOOST_CHECK ( !(v0 <= def0) ) ;
+ BOOST_CHECK ( v0 >= opt0 ) ;
 }
 
 template<class T>
@@ -767,6 +794,10 @@
   BOOST_CHECK ( def0 == none ) ;
   BOOST_CHECK ( non_def != none ) ;
   BOOST_CHECK ( !def1 ) ;
+ BOOST_CHECK ( !(non_def < none) ) ;
+ BOOST_CHECK ( non_def > none ) ;
+ BOOST_CHECK ( !(non_def <= none) ) ;
+ BOOST_CHECK ( non_def >= none ) ;
 
   non_def = none ;
   BOOST_CHECK ( !non_def ) ;
@@ -774,6 +805,24 @@
   test_default_implicit_construction(T(1),none);
 }
 
+template<class T>
+void test_arrow( T const* )
+{
+ TRACE( std::endl << BOOST_CURRENT_FUNCTION );
+
+ T a(1234);
+
+ optional<T> oa(a) ;
+ optional<T> const coa(a) ;
+
+ BOOST_CHECK ( coa->V() == 1234 ) ;
+
+ oa->V() = 4321 ;
+
+ BOOST_CHECK ( a.V() = 1234 ) ;
+ BOOST_CHECK ( (*oa).V() = 4321 ) ;
+}
+
 void test_with_builtin_types()
 {
   TRACE( std::endl << BOOST_CURRENT_FUNCTION );
@@ -804,6 +853,7 @@
   test_throwing_swap( ARG(X) );
   test_relops( ARG(X) ) ;
   test_none( ARG(X) ) ;
+ test_arrow( ARG(X) ) ;
   BOOST_CHECK ( X::count == 0 ) ;
 }
 

Modified: trunk/libs/optional/test/optional_test_ref.cpp
==============================================================================
--- trunk/libs/optional/test/optional_test_ref.cpp (original)
+++ trunk/libs/optional/test/optional_test_ref.cpp 2007-11-02 18:55:49 EDT (Fri, 02 Nov 2007)
@@ -299,6 +299,23 @@
   BOOST_CHECK ( !non_def ) ;
 }
 
+template<class T>
+void test_arrow( T const* )
+{
+ TRACE( std::endl << BOOST_CURRENT_FUNCTION );
+
+ T a(1234);
+
+ optional<T&> oa(a) ;
+ optional<T&> const coa(a) ;
+
+ BOOST_CHECK ( coa->V() == 1234 ) ;
+
+ oa->V() = 4321 ;
+
+ BOOST_CHECK ( a.V() = 4321 ) ;
+}
+
 void test_with_builtin_types()
 {
   TRACE( std::endl << BOOST_CURRENT_FUNCTION );
@@ -315,6 +332,7 @@
   test_basics( ARG(X) );
   test_relops( ARG(X) ) ;
   test_none ( ARG(X) ) ;
+ test_arrow ( ARG(X) ) ;
 
   BOOST_CHECK ( X::count == 0 ) ;
 }

Deleted: trunk/libs/optional/test/optional_test_ref_fail2.cpp
==============================================================================
--- trunk/libs/optional/test/optional_test_ref_fail2.cpp 2007-11-02 18:55:49 EDT (Fri, 02 Nov 2007)
+++ (empty file)
@@ -1,23 +0,0 @@
-// Copyright (C) 2003, Fernando Luis Cacciola Carballal.
-//
-// Use, modification, and distribution is subject to the Boost Software
-// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
-// http://www.boost.org/LICENSE_1_0.txt)
-//
-// See http://www.boost.org/lib/optional for documentation.
-//
-// You are welcome to contact the author at:
-// fernando_cacciola_at_[hidden]
-//
-#include "boost/optional.hpp"
-
-//
-// THIS TEST SHOULD FAIL TO COMPILE
-//
-void optional_reference__test_no_ptr_access()
-{
- boost::optional<int&> opt ;
- opt.get_ptr();
-}
-
-


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk