m_clipping_rect.reset ( rect ) ; // initialized here.
m_clipping_rect = rect ; // initialized here.
}
void draw ( canvas& cvs )
@ -1218,15 +1386,16 @@ some operations are not available in this case:</p>
<li>Converting assignment</li>
<li>InPlace construction</li>
<li>InPlace assignment</li>
<li>Value-access via pointer</li>
</ul>
<p>Also, even though optional<T&> treats it wrapped pseudo-object much as a real
value, a true real reference is stored so aliasing will ocurr: </p>
<ul>
<li>Copies of optional<T&>will copy the references but all these references
<li>Copies of optional<T&>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 the reference itself.</li>
</ul>
@ -1254,8 +1423,7 @@ assert(a==b);
b = 3 ;
assert(ra!=b); // 'ra' is not rebound to 'b'
</pre>
<p>Now, if you assign to an <i>initialized</i> optional<T&>, the effect is to <b>
rebind</b> to the new object instead of assigning the referee. This is unlike
<p>Now, if you assign to an <i>initialized</i> optional<T&>, the effect is to <b>rebind</b> to the new object instead of assigning the referee. This is unlike
bare C++ references.</p>
<pre>int a = 1 ;
int b = 2 ;
@ -1309,6 +1477,13 @@ In such scenario, you can assign the value itself directly, as in:</p>
<pre>assert(!!opt);
*opt=value; </pre>
<HR>
<H2><ANAME="none">none_t</A></H2>
<p>
</p>
<HR>
<H2><ANAME="inplace">In-Place Factories</A></H2>
@ -1358,8 +1533,7 @@ public:
</pre>
<p>A limitation of this method is that it doesn't scale well to wrapped objects with multiple
constructors nor to generic code were the constructor overloads are unknown.</p>
<p>The solution presented in this library is the family of <b>InPlaceFactories</b> and
<b>TypedInPlaceFactories</b>.<br>
<p>The solution presented in this library is the family of <b>InPlaceFactories</b> and<b>TypedInPlaceFactories</b>.<br>
These factories are a family of classes which encapsulate an increasing number of arbitrary
constructor parameters and supply a method to construct an object of a given type using those
parameters at an address specified by the user via placement new.</p>
@ -1427,10 +1601,7 @@ public:
W ( in_place(123,"hello") ) ;
}
</pre>
<p>The factories are implemented in the headers:
<ahref="../../../boost/utility/in_place_factory.hpp">in_place_factory.hpp</a> and
<p>The factories are implemented in the headers:<ahref="../../../boost/utility/in_place_factory.hpp">in_place_factory.hpp</a> and <ahref="../../../boost/utility/typed_in_place_factory.hpp">typed_in_place_factory.hpp</a></p>
<HR>
@ -1440,9 +1611,8 @@ public:
the <i>maybe</i> state <u>represents a valid value</u>, unlike the corresponding state
of an uninitialized optional<bool>.<br>
It should be carefully considered if an optional<bool> instead of a tribool is really needed</p>
<p>Second, optional<> provides an implicit conversion to bool. This conversion
refers to the initialization state and not to the contained value.<br>
Using optional<bool> can lead to subtle errors due to the implicit bool conversion:</p>
<p>Second, optional<> 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<bool> can lead to subtle errors due to this implicit conversion:</p>
<pre>void foo ( bool v ) ;
void bar()
{
@ -1458,7 +1628,9 @@ void bar()
integral promotions don't apply (i.e. if foo() takes an 'int' instead, it won't compile). <HR>
<p>Provide the no-throw guarantee (assuming a no-throw T::~T())</p>
<p>However, since <code>optional<></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& ), you know that optional's assignment and reset has the same guarantees.</p>
<pre>//
// Case 1: Exception thrown during assignment.
//
T v0(123);
optional<T> opt0(v0);
try
{
T v1(456);
optional<T> opt1(v1);
opt0 = opt1 ;
<p>Provides the no-throw guarantee (assuming a no-throw T::~T()) becuse it only destroys the stored object.</p>
// If no exception was thrown, assignment succeeded.
assert( *opt0 == v1 ) ;
}
catch(...)
{
// If any exception was thrown, 'opt0' is reset to uninitialized.
assert( !opt0 ) ;
}
//
// Case 2: Exception thrown during reset(v)
//
T v0(123);
optional<T> opt(v0);
try
{
T v1(456);
opt.reset ( v1 ) ;
// If no exception was thrown, reset succeeded.
assert( *opt == v1 ) ;
}
catch(...)
{
// If any exception was thrown, 'opt' is reset to uninitialized.
assert( !opt ) ;
}
</pre>
<H3><u>Swap:</u></H3>
<p><code>void swap( optional<T>&, optional<T>& )</code> has the same exception guarantee as <code>swap(T&,T&)</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<T>::reset( T const& )</code> (since <code>optional<T>::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& )</code> (since <code>optional<T>::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>
@ -1539,14 +1667,11 @@ T <u>is not</u> required to be <a href="http://www.sgi.com/tech/stl/DefaultConst
<H2><ANAME="impl">Implementation Notes</A></H2>
<p>optional<T> 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>
@ -1600,15 +1725,12 @@ T <u>is not</u> required to be <a href="http://www.sgi.com/tech/stl/DefaultConst
</blockquote>
<HR>
<P>Revised April 21, 2005</P>
<p><EFBFBD> Copyright Fernando Luis Cacciola Carballal, 2003,2004,2005</p>
<P>Revised March 1, 2007</P>
<p><EFBFBD> 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 <ahref="../../../LICENSE_1_0.txt">
LICENSE_1_0.txt</a> or copy at <ahref="http://www.boost.org/LICENSE_1_0.txt">
www.boost.org/LICENSE_1_0.txt</a>)</p>
License, Version 1.0. (See accompanying file <ahref="../../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or copy at <ahref="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a>)</p>
<P>Developed by <AHREF="mailto:fernando_cacciola@hotmail.com">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
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.