mirror of
https://github.com/boostorg/optional.git
synced 2025-07-16 13:52:08 +02:00
Primary template optional<> does not handle references
This commit is contained in:
@ -31,29 +31,38 @@
|
||||
<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">
|
||||
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><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>
|
||||
</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
|
||||
Release 1.59</a>
|
||||
<span class="phrase"><a name="boost_optional.relnotes.boost_release_1_60"></a></span><a class="link" href="relnotes.html#boost_optional.relnotes.boost_release_1_60">Boost
|
||||
Release 1.60</a>
|
||||
</h4>
|
||||
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
|
||||
For C++03 compilers, added 0-argument overload for member function <code class="computeroutput"><span class="identifier">emplace</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>.
|
||||
Changed the implementation of <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">none</span></code>
|
||||
again. Now it is a const object with internal linkage (as any other tag).
|
||||
This fixes <a href="https://svn.boost.org/trac/boost/ticket/11203" target="_top">Trac
|
||||
#11203</a>.
|
||||
</li></ul></div>
|
||||
<h4>
|
||||
<a name="boost_optional.relnotes.h2"></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
|
||||
Release 1.59</a>
|
||||
</h4>
|
||||
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
|
||||
<li class="listitem">
|
||||
For C++03 compilers, added 0-argument overload for member function <code class="computeroutput"><span class="identifier">emplace</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>
|
||||
<li class="listitem">
|
||||
Fixed <a href="https://svn.boost.org/trac/boost/ticket/11241" target="_top">Trac #11241</a>.
|
||||
</li>
|
||||
</ul></div>
|
||||
<h4>
|
||||
<a name="boost_optional.relnotes.h3"></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
|
||||
Release 1.58</a>
|
||||
</h4>
|
||||
@ -89,7 +98,7 @@
|
||||
</li>
|
||||
</ul></div>
|
||||
<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_57"></a></span><a class="link" href="relnotes.html#boost_optional.relnotes.boost_release_1_57">Boost
|
||||
Release 1.57</a>
|
||||
</h4>
|
||||
@ -99,7 +108,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>.
|
||||
</li></ul></div>
|
||||
<h4>
|
||||
<a name="boost_optional.relnotes.h4"></a>
|
||||
<a name="boost_optional.relnotes.h5"></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
|
||||
Release 1.56</a>
|
||||
</h4>
|
||||
|
@ -146,7 +146,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
||||
<td align="left"><p><small>Last revised: October 05, 2015 at 14:34:49 GMT</small></p></td>
|
||||
<td align="left"><p><small>Last revised: February 12, 2016 at 21:19:23 GMT</small></p></td>
|
||||
<td align="right"><div class="copyright-footer"></div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
|
@ -29,7 +29,7 @@ class none_t {};
|
||||
struct none_t
|
||||
{
|
||||
struct init_tag{};
|
||||
explicit none_t(init_tag){} // to prevent default constructor
|
||||
explicit none_t(init_tag){} // to disable default constructor
|
||||
};
|
||||
|
||||
#endif // old implementation workarounds
|
||||
|
1059
include/boost/optional/detail/old_optional_implementation.hpp
Normal file
1059
include/boost/optional/detail/old_optional_implementation.hpp
Normal file
File diff suppressed because it is too large
Load Diff
54
include/boost/optional/detail/optional_aligned_storage.hpp
Normal file
54
include/boost/optional/detail/optional_aligned_storage.hpp
Normal file
@ -0,0 +1,54 @@
|
||||
// Copyright (C) 2003, 2008 Fernando Luis Cacciola Carballal.
|
||||
// Copyright (C) 2016 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:
|
||||
// fernando_cacciola@hotmail.com
|
||||
// akrzemi1@gmail.com
|
||||
|
||||
#ifndef BOOST_OPTIONAL_OPTIONAL_DETAIL_OPTIONAL_ALIGNED_STORAGE_AJK_12FEB2016_HPP
|
||||
#define BOOST_OPTIONAL_OPTIONAL_DETAIL_OPTIONAL_ALIGNED_STORAGE_AJK_12FEB2016_HPP
|
||||
|
||||
namespace boost {
|
||||
|
||||
namespace optional_detail {
|
||||
// This local class is used instead of that in "aligned_storage.hpp"
|
||||
// because I've found the 'official' class to ICE BCB5.5
|
||||
// when some types are used with optional<>
|
||||
// (due to sizeof() passed down as a non-type template parameter)
|
||||
template <class T>
|
||||
class aligned_storage
|
||||
{
|
||||
// Borland ICEs if unnamed unions are used for this!
|
||||
union
|
||||
// This works around GCC warnings about breaking strict aliasing rules when casting storage address to T*
|
||||
#if defined(BOOST_OPTIONAL_DETAIL_USE_ATTRIBUTE_MAY_ALIAS)
|
||||
__attribute__((__may_alias__))
|
||||
#endif
|
||||
dummy_u
|
||||
{
|
||||
char data[ sizeof(T) ];
|
||||
BOOST_DEDUCED_TYPENAME type_with_alignment<
|
||||
::boost::alignment_of<T>::value >::type aligner_;
|
||||
} dummy_ ;
|
||||
|
||||
public:
|
||||
|
||||
#if defined(BOOST_OPTIONAL_DETAIL_USE_ATTRIBUTE_MAY_ALIAS)
|
||||
void const* address() const { return &dummy_; }
|
||||
void * address() { return &dummy_; }
|
||||
#else
|
||||
void const* address() const { return dummy_.data; }
|
||||
void * address() { return dummy_.data; }
|
||||
#endif
|
||||
} ;
|
||||
|
||||
} // namespace optional_detail
|
||||
} // namespace boost
|
||||
|
||||
#endif // header guard
|
36
include/boost/optional/detail/optional_factory_support.hpp
Normal file
36
include/boost/optional/detail/optional_factory_support.hpp
Normal file
@ -0,0 +1,36 @@
|
||||
// Copyright (C) 2003, 2008 Fernando Luis Cacciola Carballal.
|
||||
// Copyright (C) 2016 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:
|
||||
// fernando_cacciola@hotmail.com
|
||||
// akrzemi1@gmail.com
|
||||
|
||||
#ifndef BOOST_OPTIONAL_OPTIONAL_DETAIL_OPTIONAL_FACTORY_SUPPORT_AJK_12FEB2016_HPP
|
||||
#define BOOST_OPTIONAL_OPTIONAL_DETAIL_OPTIONAL_FACTORY_SUPPORT_AJK_12FEB2016_HPP
|
||||
|
||||
// Daniel Wallin discovered that bind/apply.hpp badly interacts with the apply<>
|
||||
// member template of a factory as used in the optional<> implementation.
|
||||
// He proposed this simple fix which is to move the call to apply<> outside
|
||||
// namespace boost.
|
||||
namespace boost_optional_detail
|
||||
{
|
||||
template <class T, class Factory>
|
||||
inline void construct(Factory const& factory, void* address)
|
||||
{
|
||||
factory.BOOST_NESTED_TEMPLATE apply<T>(address);
|
||||
}
|
||||
}
|
||||
|
||||
namespace boost
|
||||
{
|
||||
class in_place_factory_base ;
|
||||
class typed_in_place_factory_base ;
|
||||
}
|
||||
|
||||
#endif // header guard
|
@ -1,4 +1,4 @@
|
||||
// Copyright (C) 2015 Andrzej Krzemienski.
|
||||
// Copyright (C) 2015-2016 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
|
||||
@ -167,9 +167,8 @@ public:
|
||||
#endif // BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES
|
||||
};
|
||||
|
||||
// TODO: what if no rvalue refs
|
||||
} // namespace boost
|
||||
|
||||
#endif // 0
|
||||
#endif // 1/0
|
||||
|
||||
#endif // header guard
|
||||
|
@ -39,163 +39,50 @@
|
||||
#include <boost/type_traits/is_lvalue_reference.hpp>
|
||||
#include <boost/type_traits/is_nothrow_move_assignable.hpp>
|
||||
#include <boost/type_traits/is_nothrow_move_constructible.hpp>
|
||||
#include <boost/type_traits/is_reference.hpp>
|
||||
#include <boost/type_traits/is_rvalue_reference.hpp>
|
||||
#include <boost/type_traits/is_same.hpp>
|
||||
#include <boost/mpl/if.hpp>
|
||||
#include <boost/mpl/bool.hpp>
|
||||
#include <boost/mpl/not.hpp>
|
||||
#include <boost/detail/reference_content.hpp>
|
||||
#include <boost/move/utility.hpp>
|
||||
#include <boost/none.hpp>
|
||||
#include <boost/utility/compare_pointees.hpp>
|
||||
|
||||
#include <boost/optional/optional_fwd.hpp>
|
||||
#include <boost/optional/detail/optional_config.hpp>
|
||||
#include <boost/optional/detail/optional_factory_support.hpp>
|
||||
#include <boost/optional/detail/optional_aligned_storage.hpp>
|
||||
|
||||
// Daniel Wallin discovered that bind/apply.hpp badly interacts with the apply<>
|
||||
// member template of a factory as used in the optional<> implementation.
|
||||
// He proposed this simple fix which is to move the call to apply<> outside
|
||||
// namespace boost.
|
||||
namespace boost_optional_detail
|
||||
{
|
||||
template <class T, class Factory>
|
||||
inline void construct(Factory const& factory, void* address)
|
||||
{
|
||||
factory.BOOST_NESTED_TEMPLATE apply<T>(address);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef BOOST_OPTIONAL_CONFIG_USE_OLD_IMPLEMENTATION_OF_OPTIONAL
|
||||
#include <boost/optional/detail/old_optional_implementation.hpp>
|
||||
#else
|
||||
namespace boost {
|
||||
|
||||
class in_place_factory_base ;
|
||||
class typed_in_place_factory_base ;
|
||||
|
||||
// This forward is needed to refer to namespace scope swap from the member swap
|
||||
template<class T> void swap ( optional<T>& x, optional<T>& y );
|
||||
|
||||
namespace optional_detail {
|
||||
// This local class is used instead of that in "aligned_storage.hpp"
|
||||
// because I've found the 'official' class to ICE BCB5.5
|
||||
// when some types are used with optional<>
|
||||
// (due to sizeof() passed down as a non-type template parameter)
|
||||
template <class T>
|
||||
class aligned_storage
|
||||
{
|
||||
// Borland ICEs if unnamed unions are used for this!
|
||||
union
|
||||
// This works around GCC warnings about breaking strict aliasing rules when casting storage address to T*
|
||||
#if defined(BOOST_OPTIONAL_DETAIL_USE_ATTRIBUTE_MAY_ALIAS)
|
||||
__attribute__((__may_alias__))
|
||||
#endif
|
||||
dummy_u
|
||||
{
|
||||
char data[ sizeof(T) ];
|
||||
BOOST_DEDUCED_TYPENAME type_with_alignment<
|
||||
::boost::alignment_of<T>::value >::type aligner_;
|
||||
} dummy_ ;
|
||||
|
||||
public:
|
||||
|
||||
#if defined(BOOST_OPTIONAL_DETAIL_USE_ATTRIBUTE_MAY_ALIAS)
|
||||
void const* address() const { return &dummy_; }
|
||||
void * address() { return &dummy_; }
|
||||
#else
|
||||
void const* address() const { return dummy_.data; }
|
||||
void * address() { return dummy_.data; }
|
||||
#endif
|
||||
} ;
|
||||
|
||||
template<class T>
|
||||
struct types_when_isnt_ref
|
||||
{
|
||||
typedef T const& reference_const_type ;
|
||||
typedef T & reference_type ;
|
||||
#ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES
|
||||
typedef T && rval_reference_type ;
|
||||
typedef T && reference_type_of_temporary_wrapper;
|
||||
#ifdef BOOST_MOVE_OLD_RVALUE_REF_BINDING_RULES
|
||||
// GCC 4.4 has support for an early draft of rvalue references. The conforming version below
|
||||
// causes warnings about returning references to a temporary.
|
||||
static T&& move(T&& r) { return r; }
|
||||
#else
|
||||
static rval_reference_type move(reference_type r) { return boost::move(r); }
|
||||
#endif
|
||||
#endif
|
||||
typedef T const* pointer_const_type ;
|
||||
typedef T * pointer_type ;
|
||||
typedef T const& argument_type ;
|
||||
} ;
|
||||
|
||||
template<class T>
|
||||
struct types_when_is_ref
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME remove_reference<T>::type raw_type ;
|
||||
|
||||
typedef raw_type& reference_const_type ;
|
||||
typedef raw_type& reference_type ;
|
||||
#ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES
|
||||
typedef BOOST_DEDUCED_TYPENAME remove_const<raw_type>::type&& rval_reference_type ;
|
||||
typedef raw_type& reference_type_of_temporary_wrapper;
|
||||
static reference_type move(reference_type r) { return r; }
|
||||
#endif
|
||||
typedef raw_type* pointer_const_type ;
|
||||
typedef raw_type* pointer_type ;
|
||||
typedef raw_type& argument_type ;
|
||||
} ;
|
||||
|
||||
template <class To, class From>
|
||||
void prevent_binding_rvalue_ref_to_optional_lvalue_ref()
|
||||
{
|
||||
#ifndef BOOST_OPTIONAL_CONFIG_ALLOW_BINDING_TO_RVALUES
|
||||
BOOST_STATIC_ASSERT_MSG(
|
||||
!boost::is_lvalue_reference<To>::value || !boost::is_rvalue_reference<From>::value,
|
||||
"binding rvalue references to optional lvalue references is disallowed");
|
||||
#endif
|
||||
}
|
||||
|
||||
struct optional_tag {} ;
|
||||
|
||||
|
||||
template<class T>
|
||||
class optional_base : public optional_tag
|
||||
{
|
||||
private :
|
||||
|
||||
typedef
|
||||
#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
|
||||
BOOST_DEDUCED_TYPENAME
|
||||
#endif
|
||||
::boost::detail::make_reference_content<T>::type internal_type ;
|
||||
|
||||
typedef T internal_type ;
|
||||
typedef aligned_storage<internal_type> storage_type ;
|
||||
|
||||
typedef types_when_isnt_ref<T> types_when_not_ref ;
|
||||
typedef types_when_is_ref<T> types_when_ref ;
|
||||
|
||||
typedef optional_base<T> this_type ;
|
||||
|
||||
protected :
|
||||
|
||||
typedef T value_type ;
|
||||
|
||||
typedef mpl::true_ is_reference_tag ;
|
||||
typedef mpl::false_ is_not_reference_tag ;
|
||||
|
||||
typedef BOOST_DEDUCED_TYPENAME is_reference<T>::type is_reference_predicate ;
|
||||
|
||||
public:
|
||||
typedef BOOST_DEDUCED_TYPENAME mpl::if_<is_reference_predicate,types_when_ref,types_when_not_ref>::type types ;
|
||||
|
||||
protected:
|
||||
typedef BOOST_DEDUCED_TYPENAME types::reference_type reference_type ;
|
||||
typedef BOOST_DEDUCED_TYPENAME types::reference_const_type reference_const_type ;
|
||||
typedef T & reference_type ;
|
||||
typedef T const& reference_const_type ;
|
||||
#ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES
|
||||
typedef BOOST_DEDUCED_TYPENAME types::rval_reference_type rval_reference_type ;
|
||||
typedef BOOST_DEDUCED_TYPENAME types::reference_type_of_temporary_wrapper reference_type_of_temporary_wrapper ;
|
||||
typedef T && rval_reference_type ;
|
||||
typedef T && reference_type_of_temporary_wrapper ;
|
||||
#endif
|
||||
typedef BOOST_DEDUCED_TYPENAME types::pointer_type pointer_type ;
|
||||
typedef BOOST_DEDUCED_TYPENAME types::pointer_const_type pointer_const_type ;
|
||||
typedef BOOST_DEDUCED_TYPENAME types::argument_type argument_type ;
|
||||
typedef T * pointer_type ;
|
||||
typedef T const* pointer_const_type ;
|
||||
typedef T const& argument_type ;
|
||||
|
||||
// Creates an optional<T> uninitialized.
|
||||
// No-throw
|
||||
@ -295,7 +182,7 @@ class optional_base : public optional_tag
|
||||
if (is_initialized())
|
||||
{
|
||||
if ( rhs.is_initialized() )
|
||||
assign_value(rhs.get_impl(), is_reference_predicate() );
|
||||
assign_value(rhs.get_impl());
|
||||
else destroy();
|
||||
}
|
||||
else
|
||||
@ -312,7 +199,7 @@ class optional_base : public optional_tag
|
||||
if (is_initialized())
|
||||
{
|
||||
if ( rhs.is_initialized() )
|
||||
assign_value(boost::move(rhs.get_impl()), is_reference_predicate() );
|
||||
assign_value( boost::move(rhs.get_impl()) );
|
||||
else destroy();
|
||||
}
|
||||
else
|
||||
@ -331,9 +218,9 @@ class optional_base : public optional_tag
|
||||
{
|
||||
if ( rhs.is_initialized() )
|
||||
#ifndef BOOST_OPTIONAL_CONFIG_RESTORE_ASSIGNMENT_OF_NONCONVERTIBLE_TYPES
|
||||
assign_value(rhs.get(), is_reference_predicate() );
|
||||
assign_value( rhs.get() );
|
||||
#else
|
||||
assign_value(static_cast<value_type>(rhs.get()), is_reference_predicate() );
|
||||
assign_value( static_cast<value_type>(rhs.get()) );
|
||||
#endif
|
||||
|
||||
else destroy();
|
||||
@ -358,7 +245,7 @@ class optional_base : public optional_tag
|
||||
if (is_initialized())
|
||||
{
|
||||
if ( rhs.is_initialized() )
|
||||
assign_value(static_cast<ref_type>(rhs.get()), is_reference_predicate() );
|
||||
assign_value( static_cast<ref_type>(rhs.get()) );
|
||||
else destroy();
|
||||
}
|
||||
else
|
||||
@ -373,7 +260,7 @@ class optional_base : public optional_tag
|
||||
void assign ( argument_type val )
|
||||
{
|
||||
if (is_initialized())
|
||||
assign_value(val, is_reference_predicate() );
|
||||
assign_value(val);
|
||||
else construct(val);
|
||||
}
|
||||
|
||||
@ -382,7 +269,7 @@ class optional_base : public optional_tag
|
||||
void assign ( rval_reference_type val )
|
||||
{
|
||||
if (is_initialized())
|
||||
assign_value( boost::move(val), is_reference_predicate() );
|
||||
assign_value( boost::move(val) );
|
||||
else construct( boost::move(val) );
|
||||
}
|
||||
#endif
|
||||
@ -441,7 +328,7 @@ class optional_base : public optional_tag
|
||||
#ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES
|
||||
void construct ( rval_reference_type val )
|
||||
{
|
||||
::new (m_storage.address()) internal_type( types::move(val) ) ;
|
||||
::new (m_storage.address()) internal_type( boost::move(val) ) ;
|
||||
m_initialized = true ;
|
||||
}
|
||||
#endif
|
||||
@ -504,7 +391,6 @@ class optional_base : public optional_tag
|
||||
template<class Expr>
|
||||
void construct ( Expr&& factory, in_place_factory_base const* )
|
||||
{
|
||||
BOOST_STATIC_ASSERT ( ::boost::mpl::not_<is_reference_predicate>::value ) ;
|
||||
boost_optional_detail::construct<value_type>(factory, m_storage.address());
|
||||
m_initialized = true ;
|
||||
}
|
||||
@ -513,7 +399,6 @@ class optional_base : public optional_tag
|
||||
template<class Expr>
|
||||
void construct ( Expr&& factory, typed_in_place_factory_base const* )
|
||||
{
|
||||
BOOST_STATIC_ASSERT ( ::boost::mpl::not_<is_reference_predicate>::value ) ;
|
||||
factory.apply(m_storage.address()) ;
|
||||
m_initialized = true ;
|
||||
}
|
||||
@ -538,7 +423,6 @@ class optional_base : public optional_tag
|
||||
template<class Expr>
|
||||
void construct ( Expr const& factory, in_place_factory_base const* )
|
||||
{
|
||||
BOOST_STATIC_ASSERT ( ::boost::mpl::not_<is_reference_predicate>::value ) ;
|
||||
boost_optional_detail::construct<value_type>(factory, m_storage.address());
|
||||
m_initialized = true ;
|
||||
}
|
||||
@ -547,7 +431,6 @@ class optional_base : public optional_tag
|
||||
template<class Expr>
|
||||
void construct ( Expr const& factory, typed_in_place_factory_base const* )
|
||||
{
|
||||
BOOST_STATIC_ASSERT ( ::boost::mpl::not_<is_reference_predicate>::value ) ;
|
||||
factory.apply(m_storage.address()) ;
|
||||
m_initialized = true ;
|
||||
}
|
||||
@ -589,7 +472,7 @@ class optional_base : public optional_tag
|
||||
template<class Expr>
|
||||
void assign_expr_to_initialized ( Expr&& expr, void const* )
|
||||
{
|
||||
assign_value(boost::forward<Expr>(expr), is_reference_predicate());
|
||||
assign_value( boost::forward<Expr>(expr) );
|
||||
}
|
||||
#else
|
||||
// Constructs using any expression implicitly convertible to the single argument
|
||||
@ -610,7 +493,7 @@ class optional_base : public optional_tag
|
||||
template<class Expr>
|
||||
void assign_expr_to_initialized ( Expr const& expr, void const* )
|
||||
{
|
||||
assign_value(expr, is_reference_predicate());
|
||||
assign_value(expr);
|
||||
}
|
||||
|
||||
#endif
|
||||
@ -637,7 +520,7 @@ class optional_base : public optional_tag
|
||||
{
|
||||
// An exception can be thrown here.
|
||||
// It it happens, THIS will be left uninitialized.
|
||||
new (m_storage.address()) internal_type(types::move(expr.get())) ;
|
||||
new (m_storage.address()) internal_type(boost::move(expr.get())) ;
|
||||
m_initialized = true ;
|
||||
}
|
||||
}
|
||||
@ -657,24 +540,22 @@ class optional_base : public optional_tag
|
||||
#endif
|
||||
#endif // defined BOOST_OPTIONAL_WEAK_OVERLOAD_RESOLUTION
|
||||
|
||||
void assign_value ( argument_type val, is_not_reference_tag ) { get_impl() = val; }
|
||||
void assign_value ( argument_type val, is_reference_tag ) { construct(val); }
|
||||
void assign_value ( argument_type val ) { get_impl() = val; }
|
||||
#ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES
|
||||
void assign_value ( rval_reference_type val, is_not_reference_tag ) { get_impl() = static_cast<rval_reference_type>(val); }
|
||||
void assign_value ( rval_reference_type val, is_reference_tag ) { construct( static_cast<rval_reference_type>(val) ); }
|
||||
void assign_value ( rval_reference_type val ) { get_impl() = static_cast<rval_reference_type>(val); }
|
||||
#endif
|
||||
|
||||
void destroy()
|
||||
{
|
||||
if ( m_initialized )
|
||||
destroy_impl(is_reference_predicate()) ;
|
||||
destroy_impl() ;
|
||||
}
|
||||
|
||||
reference_const_type get_impl() const { return dereference(get_object(), is_reference_predicate() ) ; }
|
||||
reference_type get_impl() { return dereference(get_object(), is_reference_predicate() ) ; }
|
||||
reference_const_type get_impl() const { return dereference(get_object()) ; }
|
||||
reference_type get_impl() { return dereference(get_object()) ; }
|
||||
|
||||
pointer_const_type get_ptr_impl() const { return cast_ptr(get_object(), is_reference_predicate() ) ; }
|
||||
pointer_type get_ptr_impl() { return cast_ptr(get_object(), is_reference_predicate() ) ; }
|
||||
pointer_const_type get_ptr_impl() const { return cast_ptr(get_object()) ; }
|
||||
pointer_type get_ptr_impl() { return cast_ptr(get_object()) ; }
|
||||
|
||||
private :
|
||||
|
||||
@ -697,26 +578,21 @@ class optional_base : public optional_tag
|
||||
#endif
|
||||
|
||||
// reference_content<T> lacks an implicit conversion to T&, so the following is needed to obtain a proper reference.
|
||||
reference_const_type dereference( internal_type const* p, is_not_reference_tag ) const { return *p ; }
|
||||
reference_type dereference( internal_type* p, is_not_reference_tag ) { return *p ; }
|
||||
reference_const_type dereference( internal_type const* p, is_reference_tag ) const { return p->get() ; }
|
||||
reference_type dereference( internal_type* p, is_reference_tag ) { return p->get() ; }
|
||||
reference_const_type dereference( internal_type const* p ) const { return *p ; }
|
||||
reference_type dereference( internal_type* p ) { return *p ; }
|
||||
|
||||
#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x581))
|
||||
void destroy_impl ( is_not_reference_tag ) { get_ptr_impl()->internal_type::~internal_type() ; m_initialized = false ; }
|
||||
void destroy_impl ( ) { get_ptr_impl()->internal_type::~internal_type() ; m_initialized = false ; }
|
||||
#else
|
||||
void destroy_impl ( is_not_reference_tag ) { get_ptr_impl()->~T() ; m_initialized = false ; }
|
||||
void destroy_impl ( ) { get_ptr_impl()->~T() ; m_initialized = false ; }
|
||||
#endif
|
||||
|
||||
void destroy_impl ( is_reference_tag ) { m_initialized = false ; }
|
||||
|
||||
// If T is of reference type, trying to get a pointer to the held value must result in a compile-time error.
|
||||
// Decent compilers should disallow conversions from reference_content<T>* to T*, but just in case,
|
||||
// the following olverloads are used to filter out the case and guarantee an error in case of T being a reference.
|
||||
pointer_const_type cast_ptr( internal_type const* p, is_not_reference_tag ) const { return p ; }
|
||||
pointer_type cast_ptr( internal_type * p, is_not_reference_tag ) { return p ; }
|
||||
pointer_const_type cast_ptr( internal_type const* p, is_reference_tag ) const { return &p->get() ; }
|
||||
pointer_type cast_ptr( internal_type * p, is_reference_tag ) { return &p->get() ; }
|
||||
pointer_const_type cast_ptr( internal_type const* p ) const { return p ; }
|
||||
pointer_type cast_ptr( internal_type * p ) { return p ; }
|
||||
|
||||
bool m_initialized ;
|
||||
storage_type m_storage ;
|
||||
@ -760,7 +636,7 @@ class optional : public optional_detail::optional_base<T>
|
||||
// Creates an optional<T> initialized with 'move(val)'.
|
||||
// Can throw if T::T(T &&) does
|
||||
optional ( rval_reference_type val ) : base( boost::forward<T>(val) )
|
||||
{optional_detail::prevent_binding_rvalue_ref_to_optional_lvalue_ref<T, rval_reference_type>();}
|
||||
{}
|
||||
#endif
|
||||
|
||||
// Creates an optional<T> initialized with 'val' IFF cond is true, otherwise creates an uninitialized optional.
|
||||
@ -815,7 +691,7 @@ class optional : public optional_detail::optional_base<T>
|
||||
boost::is_same<BOOST_DEDUCED_TYPENAME boost::decay<Expr>::type, none_t>::value >::type* = 0
|
||||
)
|
||||
: base(boost::forward<Expr>(expr),boost::addressof(expr))
|
||||
{optional_detail::prevent_binding_rvalue_ref_to_optional_lvalue_ref<T, Expr&&>();}
|
||||
{}
|
||||
|
||||
#else
|
||||
template<class Expr>
|
||||
@ -852,7 +728,6 @@ class optional : public optional_detail::optional_base<T>
|
||||
>::type
|
||||
operator= ( Expr&& expr )
|
||||
{
|
||||
optional_detail::prevent_binding_rvalue_ref_to_optional_lvalue_ref<T, Expr&&>();
|
||||
this->assign_expr(boost::forward<Expr>(expr),boost::addressof(expr));
|
||||
return *this ;
|
||||
}
|
||||
@ -920,7 +795,6 @@ class optional : public optional_detail::optional_base<T>
|
||||
// Assigns from a T (deep-moves the rhs value)
|
||||
optional& operator= ( rval_reference_type val )
|
||||
{
|
||||
optional_detail::prevent_binding_rvalue_ref_to_optional_lvalue_ref<T, rval_reference_type>();
|
||||
this->assign( boost::move(val) ) ;
|
||||
return *this ;
|
||||
}
|
||||
@ -1003,7 +877,7 @@ class optional : public optional_detail::optional_base<T>
|
||||
#if (!defined BOOST_NO_CXX11_REF_QUALIFIERS) && (!defined BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES)
|
||||
reference_const_type operator *() const& { return this->get() ; }
|
||||
reference_type operator *() & { return this->get() ; }
|
||||
reference_type_of_temporary_wrapper operator *() && { return base::types::move(this->get()) ; }
|
||||
reference_type_of_temporary_wrapper operator *() && { return boost::move(this->get()) ; }
|
||||
#else
|
||||
reference_const_type operator *() const { return this->get() ; }
|
||||
reference_type operator *() { return this->get() ; }
|
||||
@ -1029,7 +903,7 @@ class optional : public optional_detail::optional_base<T>
|
||||
reference_type_of_temporary_wrapper value() &&
|
||||
{
|
||||
if (this->is_initialized())
|
||||
return base::types::move(this->get()) ;
|
||||
return boost::move(this->get()) ;
|
||||
else
|
||||
throw_exception(bad_optional_access());
|
||||
}
|
||||
@ -1067,7 +941,7 @@ class optional : public optional_detail::optional_base<T>
|
||||
value_type value_or ( U&& v ) &&
|
||||
{
|
||||
if (this->is_initialized())
|
||||
return base::types::move(get());
|
||||
return boost::move(get());
|
||||
else
|
||||
return boost::forward<U>(v);
|
||||
}
|
||||
@ -1115,7 +989,7 @@ class optional : public optional_detail::optional_base<T>
|
||||
value_type value_or_eval ( F f ) &&
|
||||
{
|
||||
if (this->is_initialized())
|
||||
return base::types::move(get());
|
||||
return boost::move(get());
|
||||
else
|
||||
return f();
|
||||
}
|
||||
@ -1135,6 +1009,12 @@ class optional : public optional_detail::optional_base<T>
|
||||
BOOST_EXPLICIT_OPERATOR_BOOL_NOEXCEPT()
|
||||
} ;
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif // BOOST_OPTIONAL_CONFIG_USE_OLD_IMPLEMENTATION_OF_OPTIONAL
|
||||
|
||||
namespace boost {
|
||||
|
||||
#ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES
|
||||
template<class T>
|
||||
class optional<T&&>
|
||||
@ -1239,6 +1119,10 @@ get_pointer ( optional<T>& opt )
|
||||
return opt.get_ptr() ;
|
||||
}
|
||||
|
||||
} // namespace boost
|
||||
|
||||
namespace boost {
|
||||
|
||||
// The following declaration prevents a bug where operator safe-bool is used upon streaming optional object if you forget the IO header.
|
||||
template<class CharType, class CharTrait>
|
||||
std::basic_ostream<CharType, CharTrait>&
|
||||
|
@ -20,6 +20,7 @@ namespace boost {
|
||||
|
||||
template<class T> class optional ;
|
||||
|
||||
// This forward is needed to refer to namespace scope swap from the member swap
|
||||
template<class T> void swap ( optional<T>& , optional<T>& );
|
||||
|
||||
template<class T> struct optional_swap_should_use_default_constructor ;
|
||||
|
@ -209,13 +209,13 @@ namespace boost {
|
||||
//
|
||||
|
||||
template <> struct optional_swap_should_use_default_constructor<
|
||||
optional_swap_test::class_whose_default_ctor_should_be_used> : mpl::true_ {} ;
|
||||
optional_swap_test::class_whose_default_ctor_should_be_used> : true_type {} ;
|
||||
|
||||
template <> struct optional_swap_should_use_default_constructor<
|
||||
optional_swap_test::class_whose_default_ctor_should_not_be_used> : mpl::false_ {} ;
|
||||
optional_swap_test::class_whose_default_ctor_should_not_be_used> : false_type {} ;
|
||||
|
||||
template <class T> struct optional_swap_should_use_default_constructor<
|
||||
optional_swap_test::template_whose_default_ctor_should_be_used<T> > : mpl::true_ {} ;
|
||||
optional_swap_test::template_whose_default_ctor_should_be_used<T> > : true_type {} ;
|
||||
|
||||
|
||||
//
|
||||
|
Reference in New Issue
Block a user