mirror of
https://github.com/boostorg/optional.git
synced 2025-07-16 13:52:08 +02:00
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
|
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::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_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
|
, boost::true_type, boost::false_type>::type
|
||||||
{};
|
{};
|
||||||
|
|
||||||
@ -954,6 +954,19 @@ class optional : public optional_detail::optional_base<T>
|
|||||||
}
|
}
|
||||||
#endif
|
#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)
|
// Assigns from a T (deep-copies the rhs value)
|
||||||
// Basic Guarantee: If T::( T const& ) throws, this is left UNINITIALIZED
|
// Basic Guarantee: If T::( T const& ) throws, this is left UNINITIALIZED
|
||||||
optional& operator= ( argument_type val )
|
optional& operator= ( argument_type val )
|
||||||
@ -961,16 +974,9 @@ class optional : public optional_detail::optional_base<T>
|
|||||||
this->assign( val ) ;
|
this->assign( val ) ;
|
||||||
return *this ;
|
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
|
#endif
|
||||||
|
|
||||||
// Assigns from a "none"
|
// Assigns from a "none"
|
||||||
// Which destroys the current value, if any, leaving this UNINITIALIZED
|
// Which destroys the current value, if any, leaving this UNINITIALIZED
|
||||||
// No-throw (assuming T::~T() doesn't)
|
// No-throw (assuming T::~T() doesn't)
|
||||||
|
@ -21,6 +21,7 @@ import testing ;
|
|||||||
[ run optional_test_swap.cpp ]
|
[ run optional_test_swap.cpp ]
|
||||||
[ run optional_test_conversions_from_U.cpp ]
|
[ run optional_test_conversions_from_U.cpp ]
|
||||||
[ run optional_test_convert_from_T.cpp ]
|
[ run optional_test_convert_from_T.cpp ]
|
||||||
|
[ run optional_test_empty_braces.cpp ]
|
||||||
[ run optional_test_tie.cpp ]
|
[ run optional_test_tie.cpp ]
|
||||||
[ run optional_test_ref_assign_portable_minimum.cpp ]
|
[ run optional_test_ref_assign_portable_minimum.cpp ]
|
||||||
[ run optional_test_ref_assign_mutable_int.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