forked from boostorg/optional
Merge branch 'develop'
This commit is contained in:
@ -13,7 +13,9 @@
|
||||
|
||||
[heading Boost Release 1.63]
|
||||
* Added two new in-place constructors. They work similarly to `emplace()` functions: they initialize the contained value by perfect-forwarding the obtained arguments. One constructor always initializes the contained value, the other based on a boolean condition.
|
||||
* Syntax `o = {}` now correctly un-initializes optional, just like in `std::optional`.
|
||||
* Fixed [@https://svn.boost.org/trac/boost/ticket/12203 Trac #12203].
|
||||
* Fixed [@https://svn.boost.org/trac/boost/ticket/12563 Trac #12563].
|
||||
|
||||
|
||||
[heading Boost Release 1.62]
|
||||
|
@ -38,9 +38,17 @@
|
||||
obtained arguments. One constructor always initializes the contained value,
|
||||
the other based on a boolean condition.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
Syntax <code class="computeroutput"><span class="identifier">o</span> <span class="special">=</span>
|
||||
<span class="special">{}</span></code> now correctly un-initializes
|
||||
optional, just like in <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">optional</span></code>.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
Fixed <a href="https://svn.boost.org/trac/boost/ticket/12203" target="_top">Trac #12203</a>.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
Fixed <a href="https://svn.boost.org/trac/boost/ticket/12563" target="_top">Trac #12563</a>.
|
||||
</li>
|
||||
</ul></div>
|
||||
<h4>
|
||||
<a name="boost_optional.relnotes.h1"></a>
|
||||
|
@ -145,7 +145,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: November 06, 2016 at 00:39:48 GMT</small></p></td>
|
||||
<td align="left"><p><small>Last revised: November 24, 2016 at 22:27:48 GMT</small></p></td>
|
||||
<td align="right"><div class="copyright-footer"></div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
|
@ -96,4 +96,21 @@
|
||||
|
||||
#endif // defined(__GNUC__)
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && !defined(BOOST_NO_CXX11_DECLTYPE) && !BOOST_WORKAROUND(BOOST_MSVC, < 1800) && !BOOST_WORKAROUND(BOOST_GCC_VERSION, < 40500) && !defined(__SUNPRO_CC)
|
||||
// this condition is a copy paste from is_constructible.hpp
|
||||
// I also disable SUNPRO, as it seems not to support type_traits correctly
|
||||
#else
|
||||
# define BOOST_OPTIONAL_DETAIL_NO_IS_CONSTRUCTIBLE_TRAIT
|
||||
#endif
|
||||
|
||||
#if defined __SUNPRO_CC
|
||||
# define BOOST_OPTIONAL_DETAIL_NO_SFINAE_FRIENDLY_CONSTRUCTORS
|
||||
#elif (defined _MSC_FULL_VER) && (_MSC_FULL_VER < 190023026)
|
||||
# define BOOST_OPTIONAL_DETAIL_NO_SFINAE_FRIENDLY_CONSTRUCTORS
|
||||
#elif defined BOOST_GCC && !defined BOOST_GCC_CXX11
|
||||
# define BOOST_OPTIONAL_DETAIL_NO_SFINAE_FRIENDLY_CONSTRUCTORS
|
||||
#elif defined BOOST_GCC_VERSION && BOOST_GCC_VERSION < 40800
|
||||
# define BOOST_OPTIONAL_DETAIL_NO_SFINAE_FRIENDLY_CONSTRUCTORS
|
||||
#endif
|
||||
|
||||
#endif // header guard
|
||||
|
@ -733,26 +733,30 @@ struct is_optional_related
|
||||
boost::true_type, boost::false_type>::type
|
||||
{};
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && !defined(BOOST_NO_CXX11_DECLTYPE) && !BOOST_WORKAROUND(BOOST_MSVC, < 1800) && !BOOST_WORKAROUND(BOOST_GCC_VERSION, < 40500) && !defined(__SUNPRO_CC)
|
||||
// this condition is a copy paste from is_constructible.hpp
|
||||
// I also disable SUNPRO, as it seems not to support type_traits correctly
|
||||
#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
|
||||
|| 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
|
||||
{};
|
||||
|
||||
template <typename T, typename U>
|
||||
struct is_optional_constructible : boost::is_constructible<T, U>
|
||||
{};
|
||||
|
||||
#else
|
||||
|
||||
#define BOOST_OPTIONAL_DETAIL_NO_IS_CONSTRUCTIBLE_TRAIT
|
||||
|
||||
template <typename, typename>
|
||||
struct is_convertible_to_T_or_factory : boost::true_type
|
||||
{};
|
||||
|
||||
template <typename T, typename U>
|
||||
struct is_optional_constructible : boost::true_type
|
||||
{};
|
||||
|
||||
#endif // is_convertible condition
|
||||
|
||||
template <typename T, typename U>
|
||||
@ -812,7 +816,11 @@ class optional : public optional_detail::optional_base<T>
|
||||
// Requires a valid conversion from U to T.
|
||||
// Can throw if T::T(U const&) does
|
||||
template<class U>
|
||||
explicit optional ( optional<U> const& rhs )
|
||||
explicit optional ( optional<U> const& rhs
|
||||
#ifndef BOOST_OPTIONAL_DETAIL_NO_SFINAE_FRIENDLY_CONSTRUCTORS
|
||||
,typename boost::enable_if< optional_detail::is_optional_constructible<T, U const&> >::type* = 0
|
||||
#endif
|
||||
)
|
||||
:
|
||||
base()
|
||||
{
|
||||
@ -825,7 +833,11 @@ class optional : public optional_detail::optional_base<T>
|
||||
// Requires a valid conversion from U to T.
|
||||
// Can throw if T::T(U&&) does
|
||||
template<class U>
|
||||
explicit optional ( optional<U> && rhs )
|
||||
explicit optional ( optional<U> && rhs
|
||||
#ifndef BOOST_OPTIONAL_DETAIL_NO_SFINAE_FRIENDLY_CONSTRUCTORS
|
||||
,typename boost::enable_if< optional_detail::is_optional_constructible<T, U> >::type* = 0
|
||||
#endif
|
||||
)
|
||||
:
|
||||
base()
|
||||
{
|
||||
@ -944,6 +956,19 @@ class optional : public optional_detail::optional_base<T>
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX
|
||||
|
||||
// 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 )
|
||||
@ -951,7 +976,7 @@ class optional : public optional_detail::optional_base<T>
|
||||
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 )
|
||||
@ -960,7 +985,9 @@ class optional : public optional_detail::optional_base<T>
|
||||
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)
|
||||
|
@ -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 ]
|
||||
@ -41,7 +42,7 @@ import testing ;
|
||||
[ run optional_test_emplace.cpp ]
|
||||
[ run optional_test_minimum_requirements.cpp ]
|
||||
[ run optional_test_msvc_bug_workaround.cpp ]
|
||||
[ compile optional_test_sfinae_friendly_value_ctor.cpp ]
|
||||
[ compile optional_test_sfinae_friendly_ctor.cpp ]
|
||||
[ compile-fail optional_test_ref_convert_assign_const_int_prevented.cpp ]
|
||||
[ compile-fail optional_test_fail1.cpp ]
|
||||
[ compile-fail optional_test_fail3a.cpp ]
|
||||
|
@ -23,6 +23,31 @@
|
||||
using boost::optional;
|
||||
using boost::none;
|
||||
|
||||
template <typename U>
|
||||
struct superconv
|
||||
{
|
||||
#ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES
|
||||
template <typename T>
|
||||
superconv(T&&) { BOOST_STATIC_ASSERT(sizeof(T) == 0); }
|
||||
#else
|
||||
template <typename T>
|
||||
superconv(const T&) { BOOST_STATIC_ASSERT(sizeof(T) == 0); }
|
||||
template <typename T>
|
||||
superconv( T&) { BOOST_STATIC_ASSERT(sizeof(T) == 0); }
|
||||
#endif
|
||||
|
||||
superconv() {}
|
||||
};
|
||||
|
||||
void test_optional_of_superconverting_T() // compile-time test
|
||||
{
|
||||
#ifndef BOOST_OPTIONAL_DETAIL_NO_IS_CONSTRUCTIBLE_TRAIT
|
||||
superconv<optional<int> > s;
|
||||
superconv<optional<int> > & rs = s;
|
||||
optional<superconv<optional<int> > > os = rs;
|
||||
#endif
|
||||
}
|
||||
|
||||
void test_optional_optional_T()
|
||||
{
|
||||
optional<int> oi1 (1), oiN;
|
||||
@ -39,6 +64,7 @@ void test_optional_optional_T()
|
||||
int main()
|
||||
{
|
||||
test_optional_optional_T();
|
||||
|
||||
test_optional_of_superconverting_T();
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
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();
|
||||
}
|
49
test/optional_test_sfinae_friendly_ctor.cpp
Normal file
49
test/optional_test_sfinae_friendly_ctor.cpp
Normal file
@ -0,0 +1,49 @@
|
||||
// Copyright (C) 2014 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
|
||||
|
||||
using boost::optional;
|
||||
|
||||
#if (!defined BOOST_OPTIONAL_DETAIL_NO_IS_CONSTRUCTIBLE_TRAIT)
|
||||
|
||||
struct X {};
|
||||
struct Y {};
|
||||
|
||||
struct Resource
|
||||
{
|
||||
explicit Resource(const X&) {}
|
||||
};
|
||||
|
||||
BOOST_STATIC_ASSERT(( boost::is_constructible<Resource, const X&>::value ));
|
||||
BOOST_STATIC_ASSERT(( !boost::is_constructible<Resource, const Y&>::value ));
|
||||
|
||||
BOOST_STATIC_ASSERT(( boost::is_constructible<optional<Resource>, const X&>::value ));
|
||||
BOOST_STATIC_ASSERT(( !boost::is_constructible<optional<Resource>, const Y&>::value ));
|
||||
|
||||
#ifndef BOOST_OPTIONAL_DETAIL_NO_SFINAE_FRIENDLY_CONSTRUCTORS
|
||||
BOOST_STATIC_ASSERT(( boost::is_constructible< optional< optional<int> >, optional<int> >::value ));
|
||||
BOOST_STATIC_ASSERT(( !boost::is_constructible< optional<int>, optional< optional<int> > >::value ));
|
||||
|
||||
BOOST_STATIC_ASSERT(( boost::is_constructible< optional< optional<int> >, const optional<int>& >::value ));
|
||||
BOOST_STATIC_ASSERT(( !boost::is_constructible< optional<int>, const optional< optional<int> >& >::value ));
|
||||
|
||||
BOOST_STATIC_ASSERT(( boost::is_constructible<optional<Resource>, const optional<X>&>::value ));
|
||||
BOOST_STATIC_ASSERT(( !boost::is_constructible<optional<Resource>, const optional<Y>&>::value ));
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
int main() { }
|
@ -1,38 +0,0 @@
|
||||
// Copyright (C) 2014 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
|
||||
|
||||
using boost::optional;
|
||||
|
||||
#if (!defined BOOST_OPTIONAL_DETAIL_NO_IS_CONSTRUCTIBLE_TRAIT)
|
||||
|
||||
struct X {};
|
||||
struct Y {};
|
||||
|
||||
struct Resource
|
||||
{
|
||||
explicit Resource(const X&) {}
|
||||
};
|
||||
|
||||
BOOST_STATIC_ASSERT(( boost::is_constructible<Resource, const X&>::value));
|
||||
BOOST_STATIC_ASSERT((!boost::is_constructible<Resource, const Y&>::value));
|
||||
|
||||
BOOST_STATIC_ASSERT(( boost::is_constructible<optional<Resource>, const X&>::value));
|
||||
BOOST_STATIC_ASSERT((!boost::is_constructible<optional<Resource>, const Y&>::value));
|
||||
|
||||
#endif
|
||||
|
||||
int main() { }
|
Reference in New Issue
Block a user