mirror of
https://github.com/boostorg/optional.git
synced 2025-07-15 21:32:17 +02:00
Compare commits
4 Commits
boost-1.30
...
svn-branch
Author | SHA1 | Date | |
---|---|---|---|
4de6323f45 | |||
579269c39e | |||
a38ccb92b5 | |||
a78ee6a73a |
@ -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<> does not model a pointer</b></u>.
|
||||
For instance, optional<> 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<T> and a pointer must be kept in mind, particularly
|
||||
because the semantics of relational operators are different: since optional<T>
|
||||
is a value-wrapper, relational operators are deep: they compare optional values;
|
||||
@ -818,7 +818,7 @@ Using optional<bool> can lead to subtle errors due to the implicit bool co
|
||||
void foo ( bool v ) ;
|
||||
void bar()
|
||||
{
|
||||
optional<bool> v = try();
|
||||
optional<bool> v = Try();
|
||||
|
||||
// The following intended to pass the <b>value</b> of 'v' to foo():
|
||||
foo(v);
|
||||
|
@ -271,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:
|
||||
@ -296,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 )
|
||||
|
@ -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"
|
||||
|
Reference in New Issue
Block a user