Compare commits

...

9 Commits

Author SHA1 Message Date
20f9f6d2e9 This commit was manufactured by cvs2svn to create tag
'Version_1_30_2'.

[SVN r19685]
2003-08-18 18:40:31 +00:00
4de6323f45 Fix the GCC workaround!
[SVN r19647]
2003-08-16 18:48:23 +00:00
579269c39e New fix for std swap (for gcc >= 3.3)
[SVN r19624]
2003-08-15 21:27:29 +00:00
a38ccb92b5 Fix couple of typos
[SVN r19623]
2003-08-15 21:23:47 +00:00
a78ee6a73a Fixes for optional_test:
Added missing #include

      Upgraded to the latest intel-win32-tools.jam in order to handle
      intel5 compatibility.


[SVN r19595]
2003-08-14 14:40:41 +00:00
929847570c Merged to RC
[SVN r17957]
2003-03-17 13:42:06 +00:00
63a928a510 Merged typename fix from trunk to branch.
[SVN r17913]
2003-03-14 13:00:11 +00:00
650b4a89b3 Alignment bug fixed
[SVN r17892]
2003-03-13 15:38:04 +00:00
f8fb254fff This commit was manufactured by cvs2svn to create branch 'RC_1_30_0'.
[SVN r17693]
2003-03-01 19:43:06 +00:00
3 changed files with 27 additions and 17 deletions

View File

@ -191,15 +191,15 @@ bool operator != ( optional<T> const& lhs, optional<T> const&amp
<P>This meaning of the null pointer value allowed pointers to became a defacto standard
for handling optional objects because all you have to do to refer to a value which you
don't really have is to use a null pointer value of the appropriate type.
Pointers have been used for decades -from the days of C APIs to modern C++ libraries-
to <i>refer</i> to optional (that is, possibly inexistent) objects; particularly
Pointers have been used for decades&mdash;from the days of C APIs to modern C++ libraries&mdash;to
<i>refer</i> to optional (that is, possibly inexistent) objects; particularly
as optional arguments to a function, but also quite often as optional data members.</P>
<P>The possible presence of a null pointer value makes the operations that access the
pointee's value possibly undefined, therefore, expressions which use dereference
and access operators, such as: <code>( *p = 2 )</code> and <code>( p-&gt;foo())</code>,
implicitly convey the notion of optionality, and this information is tied to
the <i>syntax</i> of the expressions. That is, the presence of operators * and -&gt; tell by
themselves -without any additional context-, that the expression will be undefined unless
themselves&mdash;without any additional context&mdash;that the expression will be undefined unless
the implied pointee actually exist.<br>
Furthermore, the existence of the pointee can be tested by a comparison against
the null pointer value or via a conversion to bool, which allows expressions of
@ -228,7 +228,7 @@ them. The problem resides in the shallow-copy of pointer semantics: if you need
possible undefined value because of the idiomatic aid present in the OptionalPointee
concept incarnated by pointers. <br>
Therefore, the final solution which is presented in this library is to shape the
previously discussed optional -which is a value-based container- as a model
previously discussed optional&mdash;which is a value-based container&mdash;as a model
of the OptionalPointee concept.
</p>
<h3>Optional&lt;T&gt; as a model of OptionalPointee</h3>
@ -240,7 +240,7 @@ them. The problem resides in the shallow-copy of pointer semantics: if you need
However, it is particularly important that optional<> objects are not mistaken by pointers,
they are not. <u><b>optional&lt;&gt; does not model a pointer</b></u>.
For instance, optional&lt;&gt; has not shallow-copy so does not alias: two different optionals
never refer to the <i>same</i> value (but my have <i>equivalent</i> values).<br>
never refer to the <i>same</i> value (but may have <i>equivalent</i> values).<br>
The difference between an optional&lt;T&gt; and a pointer must be kept in mind, particularly
because the semantics of relational operators are different: since optional&lt;T&gt;
is a value-wrapper, relational operators are deep: they compare optional values;
@ -806,20 +806,19 @@ class Fred
<H2><A NAME="bool">A note about optional&lt;bool&gt;</A></H2>
<p><code>optional&lt;bool&gt;</code> should be used with special caution and consideration.</p>
<p>First, it is functionally similar to a tristate boolean (false,maybe,true)
-such as <u>boost::tribool</u> (not yet formally in boost)-,
except that in a tristate boolean, the <i>maybe</i> state
<u>represents a valid value</u>, unlike the corresponding state
<p>First, it is functionally similar to a tristate boolean (false,maybe,true) &mdash;such as
<u>boost::tribool</u> (not yet formally in boost)&mdash;except that in a tristate boolean,
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 bool instead of a tribool is really needed</p>
<p>Second, optional&lt;&gt; provides and implicit conversion to bool. This conversion
refers to the initialization state and not to the contained value.<br>
<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>
<pre>
void foo ( bool v ) ;
void bar()
{
optional&lt;bool&gt; v = try();
optional&lt;bool&gt; v = Try();
// The following intended to pass the <b>value</b> of 'v' to foo():
foo(v);
@ -978,6 +977,6 @@ HREF="http://www.boost.org">www.boost.org</A>, and the boost discussion list at
<A
HREF="http://www.yahoogroups.com/list/boost">www.yahoogroups.com/list/boost</A>.
</P>
</u></BODY>
</BODY>
</HTML>

View File

@ -57,7 +57,8 @@ namespace boost
union dummy_u
{
char data[ sizeof(T) ];
type_with_alignment< ::boost::alignment_of<T>::value > aligner_;
BOOST_DEDUCED_TYPENAME type_with_alignment<
::boost::alignment_of<T>::value >::type aligner_;
} dummy_ ;
public:
@ -270,9 +271,11 @@ bool operator != ( optional<T> const& x, optional<T> const& y )
//
namespace optional_detail {
#ifdef __GNUC__
// workaround for GCC (JM):
// GCC < 3.2 gets the using declaration at namespace scope (FLC, DWA)
#if BOOST_WORKAROUND(__GNUC__, < 3) \
|| BOOST_WORKAROUND(__GNUC__, == 3) && __GNUC_MINOR__ <= 2
using std::swap;
#define BOOST_OPTIONAL_STD_SWAP_INTRODUCED_AT_NS_SCOPE
#endif
// optional's swap:
@ -295,13 +298,17 @@ void optional_swap ( optional<T>& x, optional<T>& y )
}
else if ( !!x && !!y )
{
#ifndef __GNUC__
// 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);
}
}
#undef BOOST_OPTIONAL_STD_SWAP_INTRODUCED_AT_NS_SCOPE
} // namespace optional_detail
template<class T> inline void swap ( optional<T>& x, optional<T>& y )

View File

@ -16,6 +16,10 @@
#include<stdexcept>
#include<string>
#ifdef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP
# include <boost/get_pointer.hpp>
#endif
#define BOOST_ENABLE_ASSERT_HANDLER
#include "boost/optional.hpp"