forked from boostorg/optional
Implemented reset syntax: o = {}
This commit is contained in:
@ -741,7 +741,7 @@ 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
|
||||
|| boost::is_base_of<boost::typed_in_place_factory_base, BOOST_DEDUCED_TYPENAME boost::decay<U>::type>::value
|
||||
|| boost::is_constructible<T, U&&>::value
|
||||
|| (boost::is_constructible<T, U&&>::value && !boost::is_same<T, BOOST_DEDUCED_TYPENAME boost::decay<U>::type>::value)
|
||||
, boost::true_type, boost::false_type>::type
|
||||
{};
|
||||
|
||||
@ -954,6 +954,19 @@ class optional : public optional_detail::optional_base<T>
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES
|
||||
|
||||
// Assigns from a T (deep-moves/copies the rhs value)
|
||||
template <typename T_>
|
||||
BOOST_DEDUCED_TYPENAME boost::enable_if<boost::is_same<T, BOOST_DEDUCED_TYPENAME boost::decay<T_>::type>, optional&>::type
|
||||
operator= ( T_&& val )
|
||||
{
|
||||
this->assign( boost::forward<T_>(val) ) ;
|
||||
return *this ;
|
||||
}
|
||||
#else
|
||||
|
||||
// Assigns from a T (deep-copies the rhs value)
|
||||
// Basic Guarantee: If T::( T const& ) throws, this is left UNINITIALIZED
|
||||
optional& operator= ( argument_type val )
|
||||
@ -962,13 +975,6 @@ class optional : public optional_detail::optional_base<T>
|
||||
return *this ;
|
||||
}
|
||||
|
||||
#ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES
|
||||
// Assigns from a T (deep-moves the rhs value)
|
||||
optional& operator= ( rval_reference_type val )
|
||||
{
|
||||
this->assign( boost::move(val) ) ;
|
||||
return *this ;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Assigns from a "none"
|
||||
|
@ -21,6 +21,7 @@ import testing ;
|
||||
[ run optional_test_swap.cpp ]
|
||||
[ run optional_test_conversions_from_U.cpp ]
|
||||
[ run optional_test_convert_from_T.cpp ]
|
||||
[ run optional_test_empty_braces.cpp ]
|
||||
[ run optional_test_tie.cpp ]
|
||||
[ run optional_test_ref_assign_portable_minimum.cpp ]
|
||||
[ run optional_test_ref_assign_mutable_int.cpp ]
|
||||
|
57
test/optional_test_empty_braces.cpp
Normal file
57
test/optional_test_empty_braces.cpp
Normal file
@ -0,0 +1,57 @@
|
||||
// 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/lib/optional for documentation.
|
||||
//
|
||||
// You are welcome to contact the author at:
|
||||
// akrzemi1@gmail.com
|
||||
|
||||
#include "boost/optional/optional.hpp"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#include "boost/core/lightweight_test.hpp"
|
||||
|
||||
//#ifndef BOOST_OPTIONAL_NO_CONVERTING_ASSIGNMENT
|
||||
//#ifndef BOOST_OPTIONAL_NO_CONVERTING_COPY_CTOR
|
||||
|
||||
using boost::optional;
|
||||
|
||||
struct Value
|
||||
{
|
||||
explicit Value(int) {}
|
||||
};
|
||||
|
||||
#ifndef BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX
|
||||
template <typename T>
|
||||
void test_brace_init()
|
||||
{
|
||||
optional<T> o = {};
|
||||
BOOST_TEST(!o);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void test_brace_assign()
|
||||
{
|
||||
optional<T> o;
|
||||
o = {};
|
||||
BOOST_TEST(!o);
|
||||
}
|
||||
#endif
|
||||
|
||||
int main()
|
||||
{
|
||||
#ifndef BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX
|
||||
test_brace_init<int>();
|
||||
test_brace_init<Value>();
|
||||
test_brace_assign<int>();
|
||||
test_brace_assign<Value>();
|
||||
#endif
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
Reference in New Issue
Block a user