mirror of
https://github.com/boostorg/optional.git
synced 2025-07-16 13:52:08 +02:00
specialization for optional ref - preliminary
This commit is contained in:
@ -11,6 +11,11 @@
|
|||||||
|
|
||||||
[section:relnotes Release Notes]
|
[section:relnotes Release Notes]
|
||||||
|
|
||||||
|
[heading Boost Release X.XX]
|
||||||
|
|
||||||
|
* Changed the implementation of `boost::none`: now it is a constant with internal linkage. This addresses [@https://svn.boost.org/trac/boost/ticket/11203 Trac #11203].
|
||||||
|
* Now `boost::optional` is specialized for reference parameters. This way the `sizeof` of optional reference is that of a pointer, and a number of bugs is avoided.
|
||||||
|
|
||||||
[heading Boost Release 1.59]
|
[heading Boost Release 1.59]
|
||||||
|
|
||||||
* For C++03 compilers, added 0-argument overload for member function `emplace()`, and therewith removed the dependency on `<boost/utility/in_place_factory.hpp>`.
|
* For C++03 compilers, added 0-argument overload for member function `emplace()`, and therewith removed the dependency on `<boost/utility/in_place_factory.hpp>`.
|
||||||
|
@ -28,6 +28,23 @@
|
|||||||
</h2></div></div></div>
|
</h2></div></div></div>
|
||||||
<h4>
|
<h4>
|
||||||
<a name="boost_optional.relnotes.h0"></a>
|
<a name="boost_optional.relnotes.h0"></a>
|
||||||
|
<span class="phrase"><a name="boost_optional.relnotes.boost_release_x_xx"></a></span><a class="link" href="relnotes.html#boost_optional.relnotes.boost_release_x_xx">Boost
|
||||||
|
Release X.XX</a>
|
||||||
|
</h4>
|
||||||
|
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
|
||||||
|
<li class="listitem">
|
||||||
|
Changed the implementation of <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">none</span></code>:
|
||||||
|
now it is a constant with internal linkage. This addresses <a href="https://svn.boost.org/trac/boost/ticket/11203" target="_top">Trac
|
||||||
|
#11203</a>.
|
||||||
|
</li>
|
||||||
|
<li class="listitem">
|
||||||
|
Now <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">optional</span></code> is specialized for reference
|
||||||
|
parameters. This way the <code class="computeroutput"><span class="keyword">sizeof</span></code>
|
||||||
|
of optional reference is that of a pointer, and a number of bugs is avoided.
|
||||||
|
</li>
|
||||||
|
</ul></div>
|
||||||
|
<h4>
|
||||||
|
<a name="boost_optional.relnotes.h1"></a>
|
||||||
<span class="phrase"><a name="boost_optional.relnotes.boost_release_1_59"></a></span><a class="link" href="relnotes.html#boost_optional.relnotes.boost_release_1_59">Boost
|
<span class="phrase"><a name="boost_optional.relnotes.boost_release_1_59"></a></span><a class="link" href="relnotes.html#boost_optional.relnotes.boost_release_1_59">Boost
|
||||||
Release 1.59</a>
|
Release 1.59</a>
|
||||||
</h4>
|
</h4>
|
||||||
@ -36,7 +53,7 @@
|
|||||||
and therewith removed the dependency on <code class="computeroutput"><span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">utility</span><span class="special">/</span><span class="identifier">in_place_factory</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code>.
|
and therewith removed the dependency on <code class="computeroutput"><span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">utility</span><span class="special">/</span><span class="identifier">in_place_factory</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code>.
|
||||||
</li></ul></div>
|
</li></ul></div>
|
||||||
<h4>
|
<h4>
|
||||||
<a name="boost_optional.relnotes.h1"></a>
|
<a name="boost_optional.relnotes.h2"></a>
|
||||||
<span class="phrase"><a name="boost_optional.relnotes.boost_release_1_58"></a></span><a class="link" href="relnotes.html#boost_optional.relnotes.boost_release_1_58">Boost
|
<span class="phrase"><a name="boost_optional.relnotes.boost_release_1_58"></a></span><a class="link" href="relnotes.html#boost_optional.relnotes.boost_release_1_58">Boost
|
||||||
Release 1.58</a>
|
Release 1.58</a>
|
||||||
</h4>
|
</h4>
|
||||||
@ -72,7 +89,7 @@
|
|||||||
</li>
|
</li>
|
||||||
</ul></div>
|
</ul></div>
|
||||||
<h4>
|
<h4>
|
||||||
<a name="boost_optional.relnotes.h2"></a>
|
<a name="boost_optional.relnotes.h3"></a>
|
||||||
<span class="phrase"><a name="boost_optional.relnotes.boost_release_1_57"></a></span><a class="link" href="relnotes.html#boost_optional.relnotes.boost_release_1_57">Boost
|
<span class="phrase"><a name="boost_optional.relnotes.boost_release_1_57"></a></span><a class="link" href="relnotes.html#boost_optional.relnotes.boost_release_1_57">Boost
|
||||||
Release 1.57</a>
|
Release 1.57</a>
|
||||||
</h4>
|
</h4>
|
||||||
@ -82,7 +99,7 @@
|
|||||||
to fix C++03 compile error on <code class="computeroutput"><span class="identifier">logic_error</span><span class="special">(</span><span class="string">"..."</span><span class="special">)</span></code>"</em></span>.
|
to fix C++03 compile error on <code class="computeroutput"><span class="identifier">logic_error</span><span class="special">(</span><span class="string">"..."</span><span class="special">)</span></code>"</em></span>.
|
||||||
</li></ul></div>
|
</li></ul></div>
|
||||||
<h4>
|
<h4>
|
||||||
<a name="boost_optional.relnotes.h3"></a>
|
<a name="boost_optional.relnotes.h4"></a>
|
||||||
<span class="phrase"><a name="boost_optional.relnotes.boost_release_1_56"></a></span><a class="link" href="relnotes.html#boost_optional.relnotes.boost_release_1_56">Boost
|
<span class="phrase"><a name="boost_optional.relnotes.boost_release_1_56"></a></span><a class="link" href="relnotes.html#boost_optional.relnotes.boost_release_1_56">Boost
|
||||||
Release 1.56</a>
|
Release 1.56</a>
|
||||||
</h4>
|
</h4>
|
||||||
|
@ -146,7 +146,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
||||||
<td align="left"><p><small>Last revised: October 01, 2015 at 13:19:55 GMT</small></p></td>
|
<td align="left"><p><small>Last revised: October 05, 2015 at 14:34:49 GMT</small></p></td>
|
||||||
<td align="right"><div class="copyright-footer"></div></td>
|
<td align="right"><div class="copyright-footer"></div></td>
|
||||||
</tr></table>
|
</tr></table>
|
||||||
<hr>
|
<hr>
|
||||||
|
55
include/boost/optional/detail/optional_config.hpp
Normal file
55
include/boost/optional/detail/optional_config.hpp
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
// Copyright (C) 2003, 2008 Fernando Luis Cacciola Carballal.
|
||||||
|
// Copyright (C) 2015 Andrzej Krzemienski.
|
||||||
|
//
|
||||||
|
// 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/libs/optional for documentation.
|
||||||
|
//
|
||||||
|
// You are welcome to contact the author at:
|
||||||
|
// akrzemi1@gmail.com
|
||||||
|
|
||||||
|
#ifndef BOOST_OPTIONAL_DETAIL_OPTIONAL_CONFIG_AJK_28JAN2015_HPP
|
||||||
|
#define BOOST_OPTIONAL_DETAIL_OPTIONAL_CONFIG_AJK_28JAN2015_HPP
|
||||||
|
|
||||||
|
#include <boost/config.hpp>
|
||||||
|
#include <boost/detail/workaround.hpp>
|
||||||
|
|
||||||
|
#if (defined BOOST_NO_CXX11_RVALUE_REFERENCES) || (defined BOOST_OPTIONAL_CONFIG_NO_RVALUE_REFERENCES)
|
||||||
|
# define BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if BOOST_WORKAROUND(BOOST_INTEL_CXX_VERSION,<=700)
|
||||||
|
// AFAICT only Intel 7 correctly resolves the overload set
|
||||||
|
// that includes the in-place factory taking functions,
|
||||||
|
// so for the other icc versions, in-place factory support
|
||||||
|
// is disabled
|
||||||
|
# define BOOST_OPTIONAL_NO_INPLACE_FACTORY_SUPPORT
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if BOOST_WORKAROUND(__BORLANDC__, <= 0x551)
|
||||||
|
// BCB (5.5.1) cannot parse the nested template struct in an inplace factory.
|
||||||
|
# define BOOST_OPTIONAL_NO_INPLACE_FACTORY_SUPPORT
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if !defined(BOOST_OPTIONAL_NO_INPLACE_FACTORY_SUPPORT) \
|
||||||
|
&& defined BOOST_BCB_PARTIAL_SPECIALIZATION_BUG
|
||||||
|
// BCB (up to 5.64) has the following bug:
|
||||||
|
// If there is a member function/operator template of the form
|
||||||
|
// template<class Expr> mfunc( Expr expr ) ;
|
||||||
|
// some calls are resolved to this even if there are other better matches.
|
||||||
|
// The effect of this bug is that calls to converting ctors and assignments
|
||||||
|
// are incorrectly sink to this general catch-all member function template as shown above.
|
||||||
|
# define BOOST_OPTIONAL_WEAK_OVERLOAD_RESOLUTION
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(__GNUC__) && !defined(__INTEL_COMPILER)
|
||||||
|
// GCC since 3.3 has may_alias attribute that helps to alleviate optimizer issues with
|
||||||
|
// regard to violation of the strict aliasing rules. The optional< T > storage type is marked
|
||||||
|
// with this attribute in order to let the compiler know that it will alias objects of type T
|
||||||
|
// and silence compilation warnings.
|
||||||
|
# define BOOST_OPTIONAL_DETAIL_USE_ATTRIBUTE_MAY_ALIAS
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // header guard
|
164
include/boost/optional/detail/optional_reference_spec.hpp
Normal file
164
include/boost/optional/detail/optional_reference_spec.hpp
Normal file
@ -0,0 +1,164 @@
|
|||||||
|
// Copyright (C) 2015 Andrzej Krzemienski.
|
||||||
|
//
|
||||||
|
// 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/libs/optional for documentation.
|
||||||
|
//
|
||||||
|
// You are welcome to contact the author at:
|
||||||
|
// akrzemi1@gmail.com
|
||||||
|
|
||||||
|
#ifndef BOOST_OPTIONAL_DETAIL_OPTIONAL_REFERENCE_SPEC_AJK_03OCT2015_HPP
|
||||||
|
#define BOOST_OPTIONAL_DETAIL_OPTIONAL_REFERENCE_SPEC_AJK_03OCT2015_HPP
|
||||||
|
|
||||||
|
# if 1
|
||||||
|
|
||||||
|
namespace boost {
|
||||||
|
|
||||||
|
namespace detail {
|
||||||
|
|
||||||
|
template <class From>
|
||||||
|
void prevent_binding_rvalue()
|
||||||
|
{
|
||||||
|
#ifndef BOOST_OPTIONAL_CONFIG_ALLOW_BINDING_TO_RVALUES
|
||||||
|
BOOST_STATIC_ASSERT_MSG(boost::is_lvalue_reference<From>::value,
|
||||||
|
"binding rvalue references to optional lvalue references is disallowed");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
typename boost::remove_reference<T>::type& forward_reference(T&& r)
|
||||||
|
{
|
||||||
|
BOOST_STATIC_ASSERT_MSG(boost::is_lvalue_reference<T>::value,
|
||||||
|
"binding rvalue references to optional lvalue references is disallowed");
|
||||||
|
return boost::forward<T>(r);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
struct is_optional_
|
||||||
|
{
|
||||||
|
static const bool value = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename U>
|
||||||
|
struct is_optional_<::boost::optional<U>>
|
||||||
|
{
|
||||||
|
static const bool value = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
struct is_no_optional
|
||||||
|
{
|
||||||
|
static const bool value = !is_optional_<typename boost::decay<T>::type>::value;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace detail
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
class optional<T&> : public optional_detail::optional_tag
|
||||||
|
{
|
||||||
|
T* ptr_;
|
||||||
|
|
||||||
|
public:
|
||||||
|
typedef T& value_type;
|
||||||
|
typedef T& reference_type;
|
||||||
|
typedef T& reference_const_type;
|
||||||
|
typedef T* pointer_type;
|
||||||
|
typedef T* pointer_const_type;
|
||||||
|
|
||||||
|
optional() BOOST_NOEXCEPT : ptr_() {}
|
||||||
|
optional(none_t) BOOST_NOEXCEPT : ptr_() {}
|
||||||
|
|
||||||
|
template <class U>
|
||||||
|
explicit optional(const optional<U&>& rhs) BOOST_NOEXCEPT : ptr_(rhs.ptr_) {}
|
||||||
|
optional(const optional& rhs) BOOST_NOEXCEPT : ptr_(rhs.ptr_) {}
|
||||||
|
|
||||||
|
|
||||||
|
optional& operator=(const optional& rhs) BOOST_NOEXCEPT { ptr_ = rhs.ptr_; return *this; }
|
||||||
|
template <class U>
|
||||||
|
optional& operator=(const optional<U&>& rhs) BOOST_NOEXCEPT { ptr_ = rhs.ptr_; return *this; }
|
||||||
|
optional& operator=(none_t) BOOST_NOEXCEPT { ptr_ = 0; return *this; }
|
||||||
|
|
||||||
|
|
||||||
|
void swap(optional& rhs) BOOST_NOEXCEPT { std::swap(ptr_, rhs.ptr_); }
|
||||||
|
T& get() const { BOOST_ASSERT(ptr_); return *ptr_; }
|
||||||
|
|
||||||
|
T* get_ptr() const BOOST_NOEXCEPT { return ptr_; }
|
||||||
|
T* operator->() const { BOOST_ASSERT(ptr_); return ptr_; }
|
||||||
|
T& operator*() const { BOOST_ASSERT(ptr_); return *ptr_; }
|
||||||
|
T& value() const { return ptr_ ? *ptr_ : (throw_exception(bad_optional_access()), *ptr_); }
|
||||||
|
|
||||||
|
|
||||||
|
template <typename F>
|
||||||
|
T& value_or_eval(F f) const { return ptr_ ? *ptr_ : detail::forward_reference(f()); }
|
||||||
|
|
||||||
|
bool operator!() const BOOST_NOEXCEPT { return ptr_ == 0; }
|
||||||
|
BOOST_EXPLICIT_OPERATOR_BOOL_NOEXCEPT()
|
||||||
|
|
||||||
|
void reset() BOOST_NOEXCEPT { ptr_ = 0; }
|
||||||
|
|
||||||
|
bool is_initialized() const BOOST_NOEXCEPT { return ptr_ != 0; }
|
||||||
|
|
||||||
|
#ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES
|
||||||
|
|
||||||
|
template <class R>
|
||||||
|
optional(R&& r, BOOST_DEDUCED_TYPENAME boost::enable_if<detail::is_no_optional<R> >::type* = 0) BOOST_NOEXCEPT
|
||||||
|
: ptr_(boost::addressof(r)) { detail::prevent_binding_rvalue<R>(); }
|
||||||
|
|
||||||
|
template <class R>
|
||||||
|
optional(bool cond, R&& r, BOOST_DEDUCED_TYPENAME boost::enable_if<detail::is_no_optional<R> >::type* = 0) BOOST_NOEXCEPT
|
||||||
|
: ptr_(cond ? boost::addressof(r) : 0) { detail::prevent_binding_rvalue<R>(); }
|
||||||
|
|
||||||
|
template <class R>
|
||||||
|
BOOST_DEDUCED_TYPENAME boost::enable_if<detail::is_no_optional<R>, optional<T&>&>::type
|
||||||
|
operator=(R&& r) BOOST_NOEXCEPT { detail::prevent_binding_rvalue<R>(); ptr_ = boost::addressof(r); return *this; }
|
||||||
|
|
||||||
|
template <class R>
|
||||||
|
void emplace(R&& r, BOOST_DEDUCED_TYPENAME boost::enable_if<detail::is_no_optional<R> >::type* = 0) BOOST_NOEXCEPT
|
||||||
|
{ detail::prevent_binding_rvalue<R>(); ptr_ = boost::addressof(r); }
|
||||||
|
|
||||||
|
template <class R>
|
||||||
|
T& get_value_or(R&& r, BOOST_DEDUCED_TYPENAME boost::enable_if<detail::is_no_optional<R> >::type* = 0) const BOOST_NOEXCEPT
|
||||||
|
{ detail::prevent_binding_rvalue<R>(); return ptr_ ? *ptr_ : r; }
|
||||||
|
|
||||||
|
template <class R>
|
||||||
|
T& value_or(R&& r, BOOST_DEDUCED_TYPENAME boost::enable_if<detail::is_no_optional<R> >::type* = 0) const BOOST_NOEXCEPT
|
||||||
|
{ detail::prevent_binding_rvalue<R>(); return ptr_ ? *ptr_ : r; }
|
||||||
|
|
||||||
|
template <class R>
|
||||||
|
void reset(R&& r, BOOST_DEDUCED_TYPENAME boost::enable_if<detail::is_no_optional<R> >::type* = 0) BOOST_NOEXCEPT
|
||||||
|
{ detail::prevent_binding_rvalue<R>(); ptr_ = boost::addressof(r); }
|
||||||
|
|
||||||
|
#else // BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES
|
||||||
|
|
||||||
|
template <class U>
|
||||||
|
optional(const U& v) BOOST_NOEXCEPT : ptr_(boost::addressof(v)) { }
|
||||||
|
|
||||||
|
template <class U>
|
||||||
|
optional(bool cond, const U& v) BOOST_NOEXCEPT : ptr_(cond ? boost::addressof(v) : 0) {}
|
||||||
|
|
||||||
|
template <class U>
|
||||||
|
optional operator=(const U& v) BOOST_NOEXCEPT { ptr_ = boost::addressof(v); return *this; }
|
||||||
|
|
||||||
|
template <class U>
|
||||||
|
void emplace(const U& v) BOOST_NOEXCEPT { ptr_ = boost::addressof(v); }
|
||||||
|
|
||||||
|
template <class U>
|
||||||
|
T& get_value_or(const U& v) const BOOST_NOEXCEPT { return ptr_ ? *ptr_ : v; }
|
||||||
|
|
||||||
|
template <class U>
|
||||||
|
T& value_or(const U& v) const BOOST_NOEXCEPT { return ptr_ ? *ptr_ : v; }
|
||||||
|
|
||||||
|
template <class U>
|
||||||
|
void reset(const U& v) BOOST_NOEXCEPT { ptr_ = boost::addressof(v); }
|
||||||
|
|
||||||
|
#endif // BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES
|
||||||
|
};
|
||||||
|
|
||||||
|
// TODO: what if no rvalue refs
|
||||||
|
} // namespace boost
|
||||||
|
|
||||||
|
#endif // 0
|
||||||
|
|
||||||
|
#endif // header guard
|
195
include/boost/optional/detail/optional_relops.hpp
Normal file
195
include/boost/optional/detail/optional_relops.hpp
Normal file
@ -0,0 +1,195 @@
|
|||||||
|
// Copyright (C) 2003, 2008 Fernando Luis Cacciola Carballal.
|
||||||
|
// Copyright (C) 2015 Andrzej Krzemienski.
|
||||||
|
//
|
||||||
|
// 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/libs/optional for documentation.
|
||||||
|
//
|
||||||
|
// You are welcome to contact the author at:
|
||||||
|
// akrzemi1@gmail.com
|
||||||
|
|
||||||
|
#ifndef BOOST_OPTIONAL_DETAIL_OPTIONAL_RELOPS_AJK_03OCT2015_HPP
|
||||||
|
#define BOOST_OPTIONAL_DETAIL_OPTIONAL_RELOPS_AJK_03OCT2015_HPP
|
||||||
|
|
||||||
|
namespace boost {
|
||||||
|
|
||||||
|
// optional's relational operators ( ==, !=, <, >, <=, >= ) have deep-semantics (compare values).
|
||||||
|
// WARNING: This is UNLIKE pointers. Use equal_pointees()/less_pointess() in generic code instead.
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// optional<T> vs optional<T> cases
|
||||||
|
//
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
inline
|
||||||
|
bool operator == ( optional<T> const& x, optional<T> const& y )
|
||||||
|
{ return equal_pointees(x,y); }
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
inline
|
||||||
|
bool operator < ( optional<T> const& x, optional<T> const& y )
|
||||||
|
{ return less_pointees(x,y); }
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
inline
|
||||||
|
bool operator != ( optional<T> const& x, optional<T> const& y )
|
||||||
|
{ return !( x == y ) ; }
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
inline
|
||||||
|
bool operator > ( optional<T> const& x, optional<T> const& y )
|
||||||
|
{ return y < x ; }
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
inline
|
||||||
|
bool operator <= ( optional<T> const& x, optional<T> const& y )
|
||||||
|
{ return !( y < x ) ; }
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
inline
|
||||||
|
bool operator >= ( optional<T> const& x, optional<T> const& y )
|
||||||
|
{ return !( x < y ) ; }
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// optional<T> vs T cases
|
||||||
|
//
|
||||||
|
template<class T>
|
||||||
|
inline
|
||||||
|
bool operator == ( optional<T> const& x, T const& y )
|
||||||
|
{ return equal_pointees(x, optional<T>(y)); }
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
inline
|
||||||
|
bool operator < ( optional<T> const& x, T const& y )
|
||||||
|
{ return less_pointees(x, optional<T>(y)); }
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
inline
|
||||||
|
bool operator != ( optional<T> const& x, T const& y )
|
||||||
|
{ return !( x == y ) ; }
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
inline
|
||||||
|
bool operator > ( optional<T> const& x, T const& y )
|
||||||
|
{ return y < x ; }
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
inline
|
||||||
|
bool operator <= ( optional<T> const& x, T const& y )
|
||||||
|
{ return !( y < x ) ; }
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
inline
|
||||||
|
bool operator >= ( optional<T> const& x, T const& y )
|
||||||
|
{ return !( x < y ) ; }
|
||||||
|
|
||||||
|
//
|
||||||
|
// T vs optional<T> cases
|
||||||
|
//
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
inline
|
||||||
|
bool operator == ( T const& x, optional<T> const& y )
|
||||||
|
{ return equal_pointees( optional<T>(x), y ); }
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
inline
|
||||||
|
bool operator < ( T const& x, optional<T> const& y )
|
||||||
|
{ return less_pointees( optional<T>(x), y ); }
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
inline
|
||||||
|
bool operator != ( T const& x, optional<T> const& y )
|
||||||
|
{ return !( x == y ) ; }
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
inline
|
||||||
|
bool operator > ( T const& x, optional<T> const& y )
|
||||||
|
{ return y < x ; }
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
inline
|
||||||
|
bool operator <= ( T const& x, optional<T> const& y )
|
||||||
|
{ return !( y < x ) ; }
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
inline
|
||||||
|
bool operator >= ( T const& x, optional<T> const& y )
|
||||||
|
{ return !( x < y ) ; }
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// optional<T> vs none cases
|
||||||
|
//
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
inline
|
||||||
|
bool operator == ( optional<T> const& x, none_t ) BOOST_NOEXCEPT
|
||||||
|
{ return !x; }
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
inline
|
||||||
|
bool operator < ( optional<T> const& x, none_t )
|
||||||
|
{ return less_pointees(x,optional<T>() ); }
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
inline
|
||||||
|
bool operator != ( optional<T> const& x, none_t ) BOOST_NOEXCEPT
|
||||||
|
{ return bool(x); }
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
inline
|
||||||
|
bool operator > ( optional<T> const& x, none_t y )
|
||||||
|
{ return y < x ; }
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
inline
|
||||||
|
bool operator <= ( optional<T> const& x, none_t y )
|
||||||
|
{ return !( y < x ) ; }
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
inline
|
||||||
|
bool operator >= ( optional<T> const& x, none_t y )
|
||||||
|
{ return !( x < y ) ; }
|
||||||
|
|
||||||
|
//
|
||||||
|
// none vs optional<T> cases
|
||||||
|
//
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
inline
|
||||||
|
bool operator == ( none_t , optional<T> const& y ) BOOST_NOEXCEPT
|
||||||
|
{ return !y; }
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
inline
|
||||||
|
bool operator < ( none_t , optional<T> const& y )
|
||||||
|
{ return less_pointees(optional<T>() ,y); }
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
inline
|
||||||
|
bool operator != ( none_t, optional<T> const& y ) BOOST_NOEXCEPT
|
||||||
|
{ return bool(y); }
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
inline
|
||||||
|
bool operator > ( none_t x, optional<T> const& y )
|
||||||
|
{ return y < x ; }
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
inline
|
||||||
|
bool operator <= ( none_t x, optional<T> const& y )
|
||||||
|
{ return !( y < x ) ; }
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
inline
|
||||||
|
bool operator >= ( none_t x, optional<T> const& y )
|
||||||
|
{ return !( x < y ) ; }
|
||||||
|
|
||||||
|
} // namespace boost
|
||||||
|
|
||||||
|
#endif // header guard
|
117
include/boost/optional/detail/optional_swap.hpp
Normal file
117
include/boost/optional/detail/optional_swap.hpp
Normal file
@ -0,0 +1,117 @@
|
|||||||
|
// Copyright (C) 2003, 2008 Fernando Luis Cacciola Carballal.
|
||||||
|
// Copyright (C) 2015 Andrzej Krzemienski.
|
||||||
|
//
|
||||||
|
// 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/libs/optional for documentation.
|
||||||
|
//
|
||||||
|
// You are welcome to contact the author at:
|
||||||
|
// akrzemi1@gmail.com
|
||||||
|
|
||||||
|
#ifndef BOOST_OPTIONAL_DETAIL_OPTIONAL_SWAP_AJK_28JAN2015_HPP
|
||||||
|
#define BOOST_OPTIONAL_DETAIL_OPTIONAL_SWAP_AJK_28JAN2015_HPP
|
||||||
|
|
||||||
|
#include <boost/core/swap.hpp>
|
||||||
|
#include <boost/optional/optional_fwd.hpp>
|
||||||
|
|
||||||
|
namespace boost {
|
||||||
|
|
||||||
|
namespace optional_detail {
|
||||||
|
|
||||||
|
template <bool use_default_constructor> struct swap_selector;
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct swap_selector<true>
|
||||||
|
{
|
||||||
|
template <class T>
|
||||||
|
static void optional_swap ( optional<T>& x, optional<T>& y )
|
||||||
|
{
|
||||||
|
const bool hasX = !!x;
|
||||||
|
const bool hasY = !!y;
|
||||||
|
|
||||||
|
if ( !hasX && !hasY )
|
||||||
|
return;
|
||||||
|
|
||||||
|
if( !hasX )
|
||||||
|
x.emplace();
|
||||||
|
else if ( !hasY )
|
||||||
|
y.emplace();
|
||||||
|
|
||||||
|
// Boost.Utility.Swap will take care of ADL and workarounds for broken compilers
|
||||||
|
boost::swap(x.get(), y.get());
|
||||||
|
|
||||||
|
if( !hasX )
|
||||||
|
y = boost::none ;
|
||||||
|
else if( !hasY )
|
||||||
|
x = boost::none ;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifdef BOOST_OPTIONAL_DETAIL_MOVE
|
||||||
|
# undef BOOST_OPTIONAL_DETAIL_MOVE
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES
|
||||||
|
# define BOOST_OPTIONAL_DETAIL_MOVE(EXPR_) boost::move(EXPR_)
|
||||||
|
#else
|
||||||
|
# define BOOST_OPTIONAL_DETAIL_MOVE(EXPR_) EXPR_
|
||||||
|
#endif
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct swap_selector<false>
|
||||||
|
{
|
||||||
|
template <class T>
|
||||||
|
static void optional_swap ( optional<T>& x, optional<T>& y )
|
||||||
|
//BOOST_NOEXCEPT_IF(::boost::is_nothrow_move_constructible<T>::value && BOOST_NOEXCEPT_EXPR(boost::swap(*x, *y)))
|
||||||
|
{
|
||||||
|
if (x)
|
||||||
|
{
|
||||||
|
if (y)
|
||||||
|
{
|
||||||
|
boost::swap(*x, *y);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
y = BOOST_OPTIONAL_DETAIL_MOVE(*x);
|
||||||
|
x = boost::none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (y)
|
||||||
|
{
|
||||||
|
x = BOOST_OPTIONAL_DETAIL_MOVE(*y);
|
||||||
|
y = boost::none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace optional_detail
|
||||||
|
|
||||||
|
#if (!defined BOOST_NO_CXX11_RVALUE_REFERENCES) && (!defined BOOST_CONFIG_RESTORE_OBSOLETE_SWAP_IMPLEMENTATION)
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
struct optional_swap_should_use_default_constructor : boost::false_type {} ;
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
struct optional_swap_should_use_default_constructor : has_nothrow_default_constructor<T> {} ;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
inline void swap ( optional<T>& x, optional<T>& y )
|
||||||
|
//BOOST_NOEXCEPT_IF(::boost::is_nothrow_move_constructible<T>::value && BOOST_NOEXCEPT_EXPR(boost::swap(*x, *y)))
|
||||||
|
{
|
||||||
|
optional_detail::swap_selector<optional_swap_should_use_default_constructor<T>::value>::optional_swap(x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace boost
|
||||||
|
|
||||||
|
#undef BOOST_OPTIONAL_DETAIL_MOVE
|
||||||
|
|
||||||
|
#endif // header guard
|
@ -20,7 +20,6 @@
|
|||||||
#include <new>
|
#include <new>
|
||||||
#include <iosfwd>
|
#include <iosfwd>
|
||||||
|
|
||||||
#include <boost/config.hpp>
|
|
||||||
#include <boost/assert.hpp>
|
#include <boost/assert.hpp>
|
||||||
#include <boost/core/addressof.hpp>
|
#include <boost/core/addressof.hpp>
|
||||||
#include <boost/core/enable_if.hpp>
|
#include <boost/core/enable_if.hpp>
|
||||||
@ -52,42 +51,7 @@
|
|||||||
#include <boost/utility/compare_pointees.hpp>
|
#include <boost/utility/compare_pointees.hpp>
|
||||||
|
|
||||||
#include <boost/optional/optional_fwd.hpp>
|
#include <boost/optional/optional_fwd.hpp>
|
||||||
|
#include <boost/optional/detail/optional_config.hpp>
|
||||||
#if (defined BOOST_NO_CXX11_RVALUE_REFERENCES) || (defined BOOST_OPTIONAL_CONFIG_NO_RVALUE_REFERENCES)
|
|
||||||
#define BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if BOOST_WORKAROUND(BOOST_INTEL_CXX_VERSION,<=700)
|
|
||||||
// AFAICT only Intel 7 correctly resolves the overload set
|
|
||||||
// that includes the in-place factory taking functions,
|
|
||||||
// so for the other icc versions, in-place factory support
|
|
||||||
// is disabled
|
|
||||||
#define BOOST_OPTIONAL_NO_INPLACE_FACTORY_SUPPORT
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if BOOST_WORKAROUND(__BORLANDC__, <= 0x551)
|
|
||||||
// BCB (5.5.1) cannot parse the nested template struct in an inplace factory.
|
|
||||||
#define BOOST_OPTIONAL_NO_INPLACE_FACTORY_SUPPORT
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if !defined(BOOST_OPTIONAL_NO_INPLACE_FACTORY_SUPPORT) \
|
|
||||||
&& BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x581) )
|
|
||||||
// BCB (up to 5.64) has the following bug:
|
|
||||||
// If there is a member function/operator template of the form
|
|
||||||
// template<class Expr> mfunc( Expr expr ) ;
|
|
||||||
// some calls are resolved to this even if there are other better matches.
|
|
||||||
// The effect of this bug is that calls to converting ctors and assignments
|
|
||||||
// are incrorrectly sink to this general catch-all member function template as shown above.
|
|
||||||
#define BOOST_OPTIONAL_WEAK_OVERLOAD_RESOLUTION
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(__GNUC__) && !defined(__INTEL_COMPILER)
|
|
||||||
// GCC since 3.3 has may_alias attribute that helps to alleviate optimizer issues with
|
|
||||||
// regard to violation of the strict aliasing rules. The optional< T > storage type is marked
|
|
||||||
// with this attribute in order to let the compiler know that it will alias objects of type T
|
|
||||||
// and silence compilation warnings.
|
|
||||||
#define BOOST_OPTIONAL_DETAIL_USE_ATTRIBUTE_MAY_ALIAS
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Daniel Wallin discovered that bind/apply.hpp badly interacts with the apply<>
|
// Daniel Wallin discovered that bind/apply.hpp badly interacts with the apply<>
|
||||||
// member template of a factory as used in the optional<> implementation.
|
// member template of a factory as used in the optional<> implementation.
|
||||||
@ -102,7 +66,6 @@ namespace boost_optional_detail
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
namespace boost {
|
namespace boost {
|
||||||
|
|
||||||
class in_place_factory_base ;
|
class in_place_factory_base ;
|
||||||
@ -252,7 +215,7 @@ class optional_base : public optional_tag
|
|||||||
:
|
:
|
||||||
m_initialized(false)
|
m_initialized(false)
|
||||||
{
|
{
|
||||||
construct(val);
|
construct(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES
|
#ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES
|
||||||
@ -1180,6 +1143,14 @@ class optional<T&&>
|
|||||||
} ;
|
} ;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
} // namespace boost
|
||||||
|
|
||||||
|
#ifndef BOOST_OPTIONAL_CONFIG_DONT_SPECIALIZE_OPTIONAL_REFS
|
||||||
|
# include <boost/optional/detail/optional_reference_spec.hpp>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace boost {
|
||||||
|
|
||||||
// Returns optional<T>(v)
|
// Returns optional<T>(v)
|
||||||
template<class T>
|
template<class T>
|
||||||
inline
|
inline
|
||||||
@ -1277,291 +1248,9 @@ operator<<(std::basic_ostream<CharType, CharTrait>& os, optional_detail::optiona
|
|||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
|
||||||
// optional's relational operators ( ==, !=, <, >, <=, >= ) have deep-semantics (compare values).
|
|
||||||
// WARNING: This is UNLIKE pointers. Use equal_pointees()/less_pointess() in generic code instead.
|
|
||||||
|
|
||||||
|
|
||||||
//
|
|
||||||
// optional<T> vs optional<T> cases
|
|
||||||
//
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
inline
|
|
||||||
bool operator == ( optional<T> const& x, optional<T> const& y )
|
|
||||||
{ return equal_pointees(x,y); }
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
inline
|
|
||||||
bool operator < ( optional<T> const& x, optional<T> const& y )
|
|
||||||
{ return less_pointees(x,y); }
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
inline
|
|
||||||
bool operator != ( optional<T> const& x, optional<T> const& y )
|
|
||||||
{ return !( x == y ) ; }
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
inline
|
|
||||||
bool operator > ( optional<T> const& x, optional<T> const& y )
|
|
||||||
{ return y < x ; }
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
inline
|
|
||||||
bool operator <= ( optional<T> const& x, optional<T> const& y )
|
|
||||||
{ return !( y < x ) ; }
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
inline
|
|
||||||
bool operator >= ( optional<T> const& x, optional<T> const& y )
|
|
||||||
{ return !( x < y ) ; }
|
|
||||||
|
|
||||||
|
|
||||||
//
|
|
||||||
// optional<T> vs T cases
|
|
||||||
//
|
|
||||||
template<class T>
|
|
||||||
inline
|
|
||||||
bool operator == ( optional<T> const& x, T const& y )
|
|
||||||
{ return equal_pointees(x, optional<T>(y)); }
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
inline
|
|
||||||
bool operator < ( optional<T> const& x, T const& y )
|
|
||||||
{ return less_pointees(x, optional<T>(y)); }
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
inline
|
|
||||||
bool operator != ( optional<T> const& x, T const& y )
|
|
||||||
{ return !( x == y ) ; }
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
inline
|
|
||||||
bool operator > ( optional<T> const& x, T const& y )
|
|
||||||
{ return y < x ; }
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
inline
|
|
||||||
bool operator <= ( optional<T> const& x, T const& y )
|
|
||||||
{ return !( y < x ) ; }
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
inline
|
|
||||||
bool operator >= ( optional<T> const& x, T const& y )
|
|
||||||
{ return !( x < y ) ; }
|
|
||||||
|
|
||||||
//
|
|
||||||
// T vs optional<T> cases
|
|
||||||
//
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
inline
|
|
||||||
bool operator == ( T const& x, optional<T> const& y )
|
|
||||||
{ return equal_pointees( optional<T>(x), y ); }
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
inline
|
|
||||||
bool operator < ( T const& x, optional<T> const& y )
|
|
||||||
{ return less_pointees( optional<T>(x), y ); }
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
inline
|
|
||||||
bool operator != ( T const& x, optional<T> const& y )
|
|
||||||
{ return !( x == y ) ; }
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
inline
|
|
||||||
bool operator > ( T const& x, optional<T> const& y )
|
|
||||||
{ return y < x ; }
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
inline
|
|
||||||
bool operator <= ( T const& x, optional<T> const& y )
|
|
||||||
{ return !( y < x ) ; }
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
inline
|
|
||||||
bool operator >= ( T const& x, optional<T> const& y )
|
|
||||||
{ return !( x < y ) ; }
|
|
||||||
|
|
||||||
|
|
||||||
//
|
|
||||||
// optional<T> vs none cases
|
|
||||||
//
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
inline
|
|
||||||
bool operator == ( optional<T> const& x, none_t ) BOOST_NOEXCEPT
|
|
||||||
{ return !x; }
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
inline
|
|
||||||
bool operator < ( optional<T> const& x, none_t )
|
|
||||||
{ return less_pointees(x,optional<T>() ); }
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
inline
|
|
||||||
bool operator != ( optional<T> const& x, none_t ) BOOST_NOEXCEPT
|
|
||||||
{ return bool(x); }
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
inline
|
|
||||||
bool operator > ( optional<T> const& x, none_t y )
|
|
||||||
{ return y < x ; }
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
inline
|
|
||||||
bool operator <= ( optional<T> const& x, none_t y )
|
|
||||||
{ return !( y < x ) ; }
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
inline
|
|
||||||
bool operator >= ( optional<T> const& x, none_t y )
|
|
||||||
{ return !( x < y ) ; }
|
|
||||||
|
|
||||||
//
|
|
||||||
// none vs optional<T> cases
|
|
||||||
//
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
inline
|
|
||||||
bool operator == ( none_t , optional<T> const& y ) BOOST_NOEXCEPT
|
|
||||||
{ return !y; }
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
inline
|
|
||||||
bool operator < ( none_t , optional<T> const& y )
|
|
||||||
{ return less_pointees(optional<T>() ,y); }
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
inline
|
|
||||||
bool operator != ( none_t, optional<T> const& y ) BOOST_NOEXCEPT
|
|
||||||
{ return bool(y); }
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
inline
|
|
||||||
bool operator > ( none_t x, optional<T> const& y )
|
|
||||||
{ return y < x ; }
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
inline
|
|
||||||
bool operator <= ( none_t x, optional<T> const& y )
|
|
||||||
{ return !( y < x ) ; }
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
inline
|
|
||||||
bool operator >= ( none_t x, optional<T> const& y )
|
|
||||||
{ return !( x < y ) ; }
|
|
||||||
|
|
||||||
namespace optional_detail {
|
|
||||||
|
|
||||||
template<bool use_default_constructor> struct swap_selector;
|
|
||||||
|
|
||||||
template<>
|
|
||||||
struct swap_selector<true>
|
|
||||||
{
|
|
||||||
template<class T>
|
|
||||||
static void optional_swap ( optional<T>& x, optional<T>& y )
|
|
||||||
{
|
|
||||||
const bool hasX = !!x;
|
|
||||||
const bool hasY = !!y;
|
|
||||||
|
|
||||||
if ( !hasX && !hasY )
|
|
||||||
return;
|
|
||||||
|
|
||||||
if( !hasX )
|
|
||||||
x.emplace();
|
|
||||||
else if ( !hasY )
|
|
||||||
y.emplace();
|
|
||||||
|
|
||||||
// Boost.Utility.Swap will take care of ADL and workarounds for broken compilers
|
|
||||||
boost::swap(x.get(),y.get());
|
|
||||||
|
|
||||||
if( !hasX )
|
|
||||||
y = boost::none ;
|
|
||||||
else if( !hasY )
|
|
||||||
x = boost::none ;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
#ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES
|
|
||||||
template<>
|
|
||||||
struct swap_selector<false>
|
|
||||||
{
|
|
||||||
template<class T>
|
|
||||||
static void optional_swap ( optional<T>& x, optional<T>& y )
|
|
||||||
//BOOST_NOEXCEPT_IF(::boost::is_nothrow_move_constructible<T>::value && BOOST_NOEXCEPT_EXPR(boost::swap(*x, *y)))
|
|
||||||
{
|
|
||||||
if(x)
|
|
||||||
{
|
|
||||||
if (y)
|
|
||||||
{
|
|
||||||
boost::swap(*x, *y);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
y = boost::move(*x);
|
|
||||||
x = boost::none;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (y)
|
|
||||||
{
|
|
||||||
x = boost::move(*y);
|
|
||||||
y = boost::none;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
#else
|
|
||||||
template<>
|
|
||||||
struct swap_selector<false>
|
|
||||||
{
|
|
||||||
template<class T>
|
|
||||||
static void optional_swap ( optional<T>& x, optional<T>& y )
|
|
||||||
{
|
|
||||||
const bool hasX = !!x;
|
|
||||||
const bool hasY = !!y;
|
|
||||||
|
|
||||||
if ( !hasX && hasY )
|
|
||||||
{
|
|
||||||
x = y.get();
|
|
||||||
y = boost::none ;
|
|
||||||
}
|
|
||||||
else if ( hasX && !hasY )
|
|
||||||
{
|
|
||||||
y = x.get();
|
|
||||||
x = boost::none ;
|
|
||||||
}
|
|
||||||
else if ( hasX && hasY )
|
|
||||||
{
|
|
||||||
// Boost.Utility.Swap will take care of ADL and workarounds for broken compilers
|
|
||||||
boost::swap(x.get(),y.get());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
#endif // !defined BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES
|
|
||||||
|
|
||||||
} // namespace optional_detail
|
|
||||||
|
|
||||||
#if (!defined BOOST_NO_CXX11_RVALUE_REFERENCES) && (!defined BOOST_CONFIG_RESTORE_OBSOLETE_SWAP_IMPLEMENTATION)
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
struct optional_swap_should_use_default_constructor : boost::false_type {} ;
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
struct optional_swap_should_use_default_constructor : has_nothrow_default_constructor<T> {} ;
|
|
||||||
|
|
||||||
#endif //BOOST_NO_CXX11_RVALUE_REFERENCES
|
|
||||||
|
|
||||||
template<class T> inline void swap ( optional<T>& x, optional<T>& y )
|
|
||||||
//BOOST_NOEXCEPT_IF(::boost::is_nothrow_move_constructible<T>::value && BOOST_NOEXCEPT_EXPR(boost::swap(*x, *y)))
|
|
||||||
{
|
|
||||||
optional_detail::swap_selector<optional_swap_should_use_default_constructor<T>::value>::optional_swap(x, y);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace boost
|
} // namespace boost
|
||||||
|
|
||||||
#endif
|
#include <boost/optional/detail/optional_relops.hpp>
|
||||||
|
#include <boost/optional/detail/optional_swap.hpp>
|
||||||
|
|
||||||
|
#endif // header guard
|
||||||
|
Reference in New Issue
Block a user