226 changes: 115 additions & 111 deletions include/boost/optional/optional.hpp
Expand Up @@ -60,19 +60,34 @@
#include <boost/optional/detail/optional_factory_support.hpp>
#include <boost/optional/detail/optional_aligned_storage.hpp>

namespace boost { namespace optional_detail {

template <typename T>
struct optional_value_type
{
};

template <typename T>
struct optional_value_type< ::boost::optional<T> >
{
typedef T type;
};

}} // namespace boost::optional_detail

#ifdef BOOST_OPTIONAL_CONFIG_USE_OLD_IMPLEMENTATION_OF_OPTIONAL
#include <boost/optional/detail/old_optional_implementation.hpp>
#else
namespace boost {

namespace optional_ns {

// a tag for in-place initialization of contained value
struct in_place_init_t
{
struct init_tag{};
explicit in_place_init_t(init_tag){}
};
};
const in_place_init_t in_place_init ((in_place_init_t::init_tag()));

// a tag for conditional in-place initialization of contained value
Expand All @@ -82,7 +97,7 @@ struct in_place_init_if_t
explicit in_place_init_if_t(init_tag){}
};
const in_place_init_if_t in_place_init_if ((in_place_init_if_t::init_tag()));

} // namespace optional_ns

using optional_ns::in_place_init_t;
Expand Down Expand Up @@ -252,7 +267,7 @@ class optional_base : public optional_tag
construct(rhs.get_impl());
}
}

#ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES
// Assigns from another optional<T> (deep-moves the rhs value)
void assign ( optional_base&& rhs )
Expand All @@ -269,7 +284,7 @@ class optional_base : public optional_tag
construct(boost::move(rhs.get_impl()));
}
}
#endif
#endif

// Assigns from another _convertible_ optional<U> (deep-copies the rhs value)
template<class U>
Expand All @@ -283,7 +298,7 @@ class optional_base : public optional_tag
#else
assign_value( static_cast<value_type>(rhs.get()) );
#endif

else destroy();
}
else
Expand Down Expand Up @@ -316,15 +331,15 @@ class optional_base : public optional_tag
}
}
#endif

// Assigns from a T (deep-copies the rhs value)
void assign ( argument_type val )
{
if (is_initialized())
assign_value(val);
else construct(val);
}

#ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES
// Assigns from a T (deep-moves the rhs value)
void assign ( rval_reference_type val )
Expand Down Expand Up @@ -385,7 +400,7 @@ class optional_base : public optional_tag
::new (m_storage.address()) value_type(val) ;
m_initialized = true ;
}

#ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES
void construct ( rval_reference_type val )
{
Expand All @@ -411,15 +426,15 @@ class optional_base : public optional_tag
destroy();
construct(in_place_init, boost::forward<Args>(args)...);
}

template<class... Args>
explicit optional_base ( in_place_init_t, Args&&... args )
:
m_initialized(false)
{
construct(in_place_init, boost::forward<Args>(args)...);
}

template<class... Args>
explicit optional_base ( in_place_init_if_t, bool cond, Args&&... args )
:
Expand All @@ -435,41 +450,41 @@ class optional_base : public optional_tag
::new (m_storage.address()) value_type( boost::forward<Arg>(arg) );
m_initialized = true ;
}

void construct ( in_place_init_t )
{
::new (m_storage.address()) value_type();
m_initialized = true ;
}

template<class Arg>
void emplace_assign ( Arg&& arg )
{
destroy();
construct(in_place_init, boost::forward<Arg>(arg)) ;
}

void emplace_assign ()
{
destroy();
construct(in_place_init) ;
}

template<class Arg>
explicit optional_base ( in_place_init_t, Arg&& arg )
:
m_initialized(false)
{
construct(in_place_init, boost::forward<Arg>(arg));
}

explicit optional_base ( in_place_init_t )
:
m_initialized(false)
{
construct(in_place_init);
}

template<class Arg>
explicit optional_base ( in_place_init_if_t, bool cond, Arg&& arg )
:
Expand All @@ -478,7 +493,7 @@ class optional_base : public optional_tag
if ( cond )
construct(in_place_init, boost::forward<Arg>(arg));
}

explicit optional_base ( in_place_init_if_t, bool cond )
:
m_initialized(false)
Expand All @@ -488,21 +503,21 @@ class optional_base : public optional_tag
}

#else

template<class Arg>
void construct ( in_place_init_t, const Arg& arg )
{
::new (m_storage.address()) value_type( arg );
m_initialized = true ;
}

template<class Arg>
void construct ( in_place_init_t, Arg& arg )
{
::new (m_storage.address()) value_type( arg );
m_initialized = true ;
}

void construct ( in_place_init_t )
{
::new (m_storage.address()) value_type();
Expand All @@ -515,20 +530,20 @@ class optional_base : public optional_tag
destroy();
construct(in_place_init, arg);
}

template<class Arg>
void emplace_assign ( Arg& arg )
{
destroy();
construct(in_place_init, arg);
}

void emplace_assign ()
{
destroy();
construct(in_place_init);
}

template<class Arg>
explicit optional_base ( in_place_init_t, const Arg& arg )
: m_initialized(false)
Expand All @@ -542,29 +557,29 @@ class optional_base : public optional_tag
{
construct(in_place_init, arg);
}

explicit optional_base ( in_place_init_t )
: m_initialized(false)
{
construct(in_place_init);
}

template<class Arg>
explicit optional_base ( in_place_init_if_t, bool cond, const Arg& arg )
: m_initialized(false)
{
if ( cond )
construct(in_place_init, arg);
}

template<class Arg>
explicit optional_base ( in_place_init_if_t, bool cond, Arg& arg )
: m_initialized(false)
{
if ( cond )
construct(in_place_init, arg);
}
}

explicit optional_base ( in_place_init_if_t, bool cond )
: m_initialized(false)
{
Expand Down Expand Up @@ -758,17 +773,6 @@ class optional_base : public optional_tag
storage_type m_storage ;
} ;

template <typename T>
struct optional_value_type
{
};

template <typename T>
struct optional_value_type< ::boost::optional<T> >
{
typedef T type;
};

#include <boost/optional/detail/optional_trivially_copyable_base.hpp>

// definition of metafunciton is_optional_val_init_candidate
Expand All @@ -782,7 +786,7 @@ struct is_optional_related
{};

#if !defined(BOOST_OPTIONAL_DETAIL_NO_IS_CONSTRUCTIBLE_TRAIT)

template <typename T, typename U>
struct is_convertible_to_T_or_factory
: boost::conditional< boost::is_base_of<boost::in_place_factory_base, BOOST_DEDUCED_TYPENAME boost::decay<U>::type>::value
Expand Down Expand Up @@ -871,7 +875,7 @@ class optional
#ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES
// 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 ( rval_reference_type val ) : base( boost::forward<T>(val) )
{}
#endif

Expand All @@ -882,7 +886,7 @@ class optional
#ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES
/// Creates an optional<T> initialized with 'val' IFF cond is true, otherwise creates an uninitialized optional.
// Can throw if T::T(T &&) does
optional ( bool cond, rval_reference_type val ) : base( cond, boost::forward<T>(val) )
optional ( bool cond, rval_reference_type val ) : base( cond, boost::forward<T>(val) )
{}
#endif

Expand All @@ -899,11 +903,11 @@ class optional
)
:
base()
{
{
if ( rhs.is_initialized() )
this->construct(rhs.get());
}

#ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES
// Creates a deep move of another convertible optional<U>
// Requires a valid conversion from U to T.
Expand Down Expand Up @@ -936,10 +940,10 @@ class optional


template<class Expr>
explicit optional ( Expr&& expr,
BOOST_DEDUCED_TYPENAME boost::enable_if< optional_detail::is_optional_val_init_candidate<T, Expr>, bool>::type = true
)
: base(boost::forward<Expr>(expr),boost::addressof(expr))
explicit optional ( Expr&& expr,
BOOST_DEDUCED_TYPENAME boost::enable_if< optional_detail::is_optional_val_init_candidate<T, Expr>, bool>::type = true
)
: base(boost::forward<Expr>(expr),boost::addressof(expr))
{}

#else
Expand Down Expand Up @@ -983,7 +987,7 @@ class optional
#ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES

template<class Expr>
BOOST_DEDUCED_TYPENAME boost::enable_if<optional_detail::is_optional_val_init_candidate<T, Expr>, optional&>::type
BOOST_DEDUCED_TYPENAME boost::enable_if<optional_detail::is_optional_val_init_candidate<T, Expr>, optional&>::type
operator= ( Expr&& expr )
{
this->assign_expr(boost::forward<Expr>(expr),boost::addressof(expr));
Expand All @@ -1009,7 +1013,7 @@ class optional
this->assign(rhs);
return *this ;
}

#ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES
// Move-assigns from another convertible optional<U> (converts && deep-moves the rhs value)
// Requires a valid conversion from U to T.
Expand Down Expand Up @@ -1040,14 +1044,14 @@ class optional
#ifndef BOOST_OPTIONAL_DETAIL_NO_DEFAULTED_MOVE_FUNCTIONS
optional& operator= ( optional && ) = default;
#else
optional& operator= ( optional && rhs )
optional& operator= ( optional && rhs )
BOOST_NOEXCEPT_IF(::boost::is_nothrow_move_constructible<T>::value && ::boost::is_nothrow_move_assignable<T>::value)
{
this->assign( static_cast<base &&>(rhs) ) ;
return *this ;
}
#endif
#endif

#endif // BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES

#ifndef BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX
Expand All @@ -1060,7 +1064,7 @@ class optional
this->assign( boost::forward<T_>(val) ) ;
return *this ;
}

#else

// Assigns from a T (deep-copies the rhs value)
Expand All @@ -1070,7 +1074,7 @@ class optional
this->assign( val ) ;
return *this ;
}

#ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES
// Assigns from a T (deep-moves the rhs value)
optional& operator= ( rval_reference_type val )
Expand All @@ -1079,9 +1083,9 @@ class optional
return *this ;
}
#endif

#endif // BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX

// Assigns from a "none"
// Which destroys the current value, if any, leaving this UNINITIALIZED
// No-throw (assuming T::~T() doesn't)
Expand All @@ -1090,7 +1094,7 @@ class optional
this->assign( none_ ) ;
return *this ;
}

#if (!defined BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES) && (!defined BOOST_NO_CXX11_VARIADIC_TEMPLATES)
// Constructs in-place
// upon exception *this is always uninitialized
Expand All @@ -1099,29 +1103,29 @@ class optional
{
this->emplace_assign( boost::forward<Args>(args)... );
}

template<class... Args>
explicit optional ( in_place_init_t, Args&&... args )
: base( in_place_init, boost::forward<Args>(args)... )
{}

template<class... Args>
explicit optional ( in_place_init_if_t, bool cond, Args&&... args )
: base( in_place_init_if, cond, boost::forward<Args>(args)... )
{}

#elif (!defined BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES)
template<class Arg>
void emplace ( Arg&& arg )
{
this->emplace_assign( boost::forward<Arg>(arg) );
}

void emplace ()
{
this->emplace_assign();
}

template<class Args>
explicit optional ( in_place_init_t, Args&& args )
: base( in_place_init, boost::forward<Args>(args) )
Expand All @@ -1130,12 +1134,12 @@ class optional
explicit optional ( in_place_init_t )
: base( in_place_init )
{}

template<class Args>
explicit optional ( in_place_init_if_t, bool cond, Args&& args )
: base( in_place_init_if, cond, boost::forward<Args>(args) )
{}

explicit optional ( in_place_init_if_t, bool cond )
: base( in_place_init_if, cond )
{}
Expand All @@ -1145,23 +1149,23 @@ class optional
{
this->emplace_assign( arg );
}

template<class Arg>
void emplace ( Arg& arg )
{
this->emplace_assign( arg );
}

void emplace ()
{
this->emplace_assign();
}

template<class Arg>
explicit optional ( in_place_init_t, const Arg& arg )
: base( in_place_init, arg )
{}

template<class Arg>
explicit optional ( in_place_init_t, Arg& arg )
: base( in_place_init, arg )
Expand All @@ -1170,17 +1174,17 @@ class optional
explicit optional ( in_place_init_t )
: base( in_place_init )
{}

template<class Arg>
explicit optional ( in_place_init_if_t, bool cond, const Arg& arg )
: base( in_place_init_if, cond, arg )
{}

template<class Arg>
explicit optional ( in_place_init_if_t, bool cond, Arg& arg )
: base( in_place_init_if, cond, arg )
{}
{}

explicit optional ( in_place_init_if_t, bool cond )
: base( in_place_init_if, cond )
{}
Expand Down Expand Up @@ -1213,7 +1217,7 @@ class optional
// Returns a reference to the value if this is initialized, otherwise,
// the behaviour is UNDEFINED
// No-throw
#if (!defined BOOST_NO_CXX11_REF_QUALIFIERS) && (!defined BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES)
#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 boost::move(this->get()) ; }
Expand All @@ -1222,42 +1226,42 @@ class optional
reference_type operator *() { return this->get() ; }
#endif // !defined BOOST_NO_CXX11_REF_QUALIFIERS

#if (!defined BOOST_NO_CXX11_REF_QUALIFIERS) && (!defined BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES)
#if (!defined BOOST_NO_CXX11_REF_QUALIFIERS) && (!defined BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES)
reference_const_type value() const&
{
{
if (this->is_initialized())
return this->get() ;
else
throw_exception(bad_optional_access());
}

reference_type value() &
{
{
if (this->is_initialized())
return this->get() ;
else
throw_exception(bad_optional_access());
}

reference_type_of_temporary_wrapper value() &&
{
{
if (this->is_initialized())
return boost::move(this->get()) ;
else
throw_exception(bad_optional_access());
}

#else
#else
reference_const_type value() const
{
{
if (this->is_initialized())
return this->get() ;
else
throw_exception(bad_optional_access());
}

reference_type value()
{
{
if (this->is_initialized())
return this->get() ;
else
Expand All @@ -1269,24 +1273,24 @@ class optional
#ifndef BOOST_NO_CXX11_REF_QUALIFIERS
template <class U>
value_type value_or ( U&& v ) const&
{
{
if (this->is_initialized())
return get();
else
return boost::forward<U>(v);
}

template <class U>
value_type value_or ( U&& v ) &&
{
value_type value_or ( U&& v ) &&
{
if (this->is_initialized())
return boost::move(get());
else
return boost::forward<U>(v);
}
#elif !defined BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES
template <class U>
value_type value_or ( U&& v ) const
value_type value_or ( U&& v ) const
{
if (this->is_initialized())
return get();
Expand All @@ -1295,17 +1299,17 @@ class optional
}
#else
template <class U>
value_type value_or ( U const& v ) const
{
value_type value_or ( U const& v ) const
{
if (this->is_initialized())
return get();
else
return v;
}

template <class U>
value_type value_or ( U& v ) const
{
value_type value_or ( U& v ) const
{
if (this->is_initialized())
return get();
else
Expand All @@ -1314,7 +1318,7 @@ class optional
#endif


#if (!defined BOOST_NO_CXX11_REF_QUALIFIERS) && (!defined BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES)
#if (!defined BOOST_NO_CXX11_REF_QUALIFIERS) && (!defined BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES)
template <typename F>
value_type value_or_eval ( F f ) const&
{
Expand All @@ -1323,7 +1327,7 @@ class optional
else
return f();
}

template <typename F>
value_type value_or_eval ( F f ) &&
{
Expand All @@ -1350,7 +1354,7 @@ class optional
else
return none;
}

template <typename F>
optional<typename boost::result_of<F(reference_type_of_temporary_wrapper)>::type> map(F f) &&
{
Expand All @@ -1359,7 +1363,7 @@ class optional
else
return none;
}

template <typename F>
optional<typename optional_detail::optional_value_type<typename boost::result_of<F(reference_type)>::type>::type> flat_map(F f) &
{
Expand All @@ -1368,7 +1372,7 @@ class optional
else
return none;
}

template <typename F>
optional<typename optional_detail::optional_value_type<typename boost::result_of<F(reference_const_type)>::type>::type> flat_map(F f) const&
{
Expand All @@ -1377,7 +1381,7 @@ class optional
else
return none;
}

template <typename F>
optional<typename optional_detail::optional_value_type<typename boost::result_of<F(reference_type_of_temporary_wrapper)>::type>::type> flat_map(F f) &&
{
Expand All @@ -1386,7 +1390,7 @@ class optional
else
return none;
}

#else
template <typename F>
value_type value_or_eval ( F f ) const
Expand Down Expand Up @@ -1423,7 +1427,7 @@ class optional
else
return none;
}

template <typename F>
optional<typename optional_detail::optional_value_type<typename boost::result_of<F(reference_const_type)>::type>::type> flat_map(F f) const
{
Expand All @@ -1432,13 +1436,13 @@ class optional
else
return none;
}

#endif

bool has_value() const BOOST_NOEXCEPT { return this->is_initialized() ; }

bool operator!() const BOOST_NOEXCEPT { return !this->is_initialized() ; }

BOOST_EXPLICIT_OPERATOR_BOOL_NOEXCEPT()
} ;

Expand All @@ -1447,7 +1451,7 @@ class optional
#endif // BOOST_OPTIONAL_CONFIG_USE_OLD_IMPLEMENTATION_OF_OPTIONAL

namespace boost {

#ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES
template<class T>
class optional<T&&>
Expand Down Expand Up @@ -1576,14 +1580,14 @@ get_pointer ( optional<T>& opt )
} // 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>&
operator<<(std::basic_ostream<CharType, CharTrait>& os, optional_detail::optional_tag const&)
{
BOOST_STATIC_ASSERT_MSG(sizeof(CharType) == 0, "If you want to output boost::optional, include header <boost/optional/optional_io.hpp>");
return os;
return os;
}

} // namespace boost
Expand Down
1 change: 1 addition & 0 deletions test/Jamfile.v2
Expand Up @@ -40,6 +40,7 @@ import testing ;
[ run optional_test_io.cpp ]
[ run optional_test_move.cpp ]
[ run optional_test_noexcept_move.cpp ]
[ run optional_test_old_impl.cpp ]
[ run optional_test_equals_none.cpp ]
[ run optional_test_value_access.cpp ]
[ run optional_test_emplace.cpp ]
Expand Down
223 changes: 223 additions & 0 deletions test/optional_test_old_impl.cpp
@@ -0,0 +1,223 @@
// Copyright (C) 2014 - 2018 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/lib/optional for documentation.
//
// You are welcome to contact the author at:
// akrzemi1@gmail.com

#define BOOST_OPTIONAL_CONFIG_USE_OLD_IMPLEMENTATION_OF_OPTIONAL // does old implementation still work for basic usage?
#include "boost/optional/optional.hpp"

#ifdef __BORLANDC__
#pragma hdrstop
#endif

#include "boost/core/ignore_unused.hpp"
#include "boost/core/lightweight_test.hpp"

using boost::optional;

struct IntWrapper
{
int _i;
IntWrapper(int i) : _i(i) {}
bool operator==(IntWrapper const& rhs) const { return _i == rhs._i; }
};

template <typename T>
void test_function_value_or_for()
{
optional<T> oM0;
const optional<T> oC0;
optional<T> oM1(1);
const optional<T> oC2(2);

BOOST_TEST(oM0.value_or(5) == 5);
BOOST_TEST(oC0.value_or(5) == 5);
BOOST_TEST(oM1.value_or(5) == 1);
BOOST_TEST(oC2.value_or(5) == 2);
}

template <typename T>
void test_function_value_for()
{
optional<T> o0;
optional<T> o1(1);
const optional<T> oC(2);

try
{
T& v = o1.value();
BOOST_TEST(v == 1);
}
catch(...)
{
BOOST_TEST(false);
}

try
{
T const& v = oC.value();
BOOST_TEST(v == 2);
}
catch(...)
{
BOOST_TEST(false);
}

BOOST_TEST_THROWS(o0.value(), boost::bad_optional_access);
}

void test_function_value()
{
test_function_value_for<int>();
test_function_value_for<double>();
test_function_value_for<IntWrapper>();
}

struct FatToIntConverter
{
static int conversions;
int _val;
FatToIntConverter(int val) : _val(val) {}
operator int() const { conversions += 1; return _val; }
};

int FatToIntConverter::conversions = 0;

void test_function_value_or()
{
test_function_value_or_for<int>();
test_function_value_or_for<double>();
test_function_value_or_for<IntWrapper>();

optional<int> oi(1);
BOOST_TEST(oi.value_or(FatToIntConverter(2)) == 1);
BOOST_TEST(FatToIntConverter::conversions == 0);

oi = boost::none;
BOOST_TEST(oi.value_or(FatToIntConverter(2)) == 2);
BOOST_TEST(FatToIntConverter::conversions == 1);
}


struct FunM
{
int operator()() { return 5; }
};

struct FunC
{
int operator()() const { return 6; }
};

int funP ()
{
return 7;
}

int throw_()
{
throw int();
}

void test_function_value_or_eval()
{
optional<int> o1 = 1;
optional<int> oN;
FunM funM;
FunC funC;

BOOST_TEST_EQ(o1.value_or_eval(funM), 1);
BOOST_TEST_EQ(oN.value_or_eval(funM), 5);
BOOST_TEST_EQ(o1.value_or_eval(FunM()), 1);
BOOST_TEST_EQ(oN.value_or_eval(FunM()), 5);

BOOST_TEST_EQ(o1.value_or_eval(funC), 1);
BOOST_TEST_EQ(oN.value_or_eval(funC), 6);
BOOST_TEST_EQ(o1.value_or_eval(FunC()), 1);
BOOST_TEST_EQ(oN.value_or_eval(FunC()), 6);

BOOST_TEST_EQ(o1.value_or_eval(funP), 1);
BOOST_TEST_EQ(oN.value_or_eval(funP), 7);

#ifndef BOOST_NO_CXX11_LAMBDAS
BOOST_TEST_EQ(o1.value_or_eval([](){return 8;}), 1);
BOOST_TEST_EQ(oN.value_or_eval([](){return 8;}), 8);
#endif

try
{
BOOST_TEST_EQ(o1.value_or_eval(throw_), 1);
}
catch(...)
{
BOOST_TEST(false);
}

BOOST_TEST_THROWS(oN.value_or_eval(throw_), int);
}

const optional<std::string> makeConstOptVal()
{
return std::string("something");
}

void test_const_move()
{
std::string s5 = *makeConstOptVal();
std::string s6 = makeConstOptVal().value();
boost::ignore_unused(s5);
boost::ignore_unused(s6);
}


#if (!defined BOOST_NO_CXX11_REF_QUALIFIERS) && (!defined BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES)
struct MoveOnly
{
explicit MoveOnly(int){}
MoveOnly(MoveOnly &&){}
void operator=(MoveOnly &&);
private:
MoveOnly(MoveOnly const&);
void operator=(MoveOnly const&);
};

optional<MoveOnly> makeMoveOnly()
{
return MoveOnly(1);
}

MoveOnly moveOnlyDefault()
{
return MoveOnly(1);
}

// compile-time test
void test_move_only_getters()
{
MoveOnly m1 = *makeMoveOnly();
MoveOnly m2 = makeMoveOnly().value();
MoveOnly m3 = makeMoveOnly().value_or(MoveOnly(1));
MoveOnly m4 = makeMoveOnly().value_or_eval(moveOnlyDefault);
boost::ignore_unused(m1);
boost::ignore_unused(m2);
boost::ignore_unused(m3);
boost::ignore_unused(m4);
}

#endif // !defined BOOST_NO_CXX11_REF_QUALIFIERS

int main()
{
test_function_value();
test_function_value_or();
test_function_value_or_eval();
test_const_move();

return boost::report_errors();
}