forked from boostorg/optional
Merge branch 'develop'
This commit is contained in:
@ -11,6 +11,12 @@
|
|||||||
|
|
||||||
[section:relnotes Release Notes]
|
[section:relnotes Release Notes]
|
||||||
|
|
||||||
|
[heading Boost Release 1.67]
|
||||||
|
|
||||||
|
* Fixed [@https://github.com/boostorg/optional/issues/46 issue #46].
|
||||||
|
* Fixed `-Wzero-as-null-pointer-constant` warnings.
|
||||||
|
|
||||||
|
|
||||||
[heading Boost Release 1.66]
|
[heading Boost Release 1.66]
|
||||||
|
|
||||||
* On newer compilers `optional` is now trivially-copyable for scalar `T`s. This uses a different storage (just `T` rather than `aligned_storage`). We require the compiler to support defaulted functions.
|
* On newer compilers `optional` is now trivially-copyable for scalar `T`s. This uses a different storage (just `T` rather than `aligned_storage`). We require the compiler to support defaulted functions.
|
||||||
|
@ -147,7 +147,7 @@ class optional_base : public optional_tag
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Creates an optional<T> initialized with 'val' IFF cond is true, otherwise creates an uninitialzed optional<T>.
|
// Creates an optional<T> initialized with 'val' IFF cond is true, otherwise creates an uninitialized optional<T>.
|
||||||
// Can throw if T::T(T const&) does
|
// Can throw if T::T(T const&) does
|
||||||
optional_base ( bool cond, argument_type val )
|
optional_base ( bool cond, argument_type val )
|
||||||
:
|
:
|
||||||
@ -730,7 +730,7 @@ class optional : public optional_detail::optional_base<T>
|
|||||||
explicit optional ( Expr&& expr,
|
explicit optional ( Expr&& expr,
|
||||||
BOOST_DEDUCED_TYPENAME boost::disable_if_c<
|
BOOST_DEDUCED_TYPENAME boost::disable_if_c<
|
||||||
(boost::is_base_of<optional_detail::optional_tag, BOOST_DEDUCED_TYPENAME boost::decay<Expr>::type>::value) ||
|
(boost::is_base_of<optional_detail::optional_tag, BOOST_DEDUCED_TYPENAME boost::decay<Expr>::type>::value) ||
|
||||||
boost::is_same<BOOST_DEDUCED_TYPENAME boost::decay<Expr>::type, none_t>::value >::type* = 0
|
boost::is_same<BOOST_DEDUCED_TYPENAME boost::decay<Expr>::type, none_t>::value, bool >::type = true
|
||||||
)
|
)
|
||||||
: base(boost::forward<Expr>(expr),boost::addressof(expr))
|
: base(boost::forward<Expr>(expr),boost::addressof(expr))
|
||||||
{optional_detail::prevent_binding_rvalue_ref_to_optional_lvalue_ref<T, Expr&&>();}
|
{optional_detail::prevent_binding_rvalue_ref_to_optional_lvalue_ref<T, Expr&&>();}
|
||||||
|
@ -132,11 +132,11 @@ public:
|
|||||||
|
|
||||||
// the following two implement a 'conditionally explicit' constructor: condition is a hack for buggy compilers with srewed conversion construction from const int
|
// the following two implement a 'conditionally explicit' constructor: condition is a hack for buggy compilers with srewed conversion construction from const int
|
||||||
template <class U>
|
template <class U>
|
||||||
explicit optional(U& rhs, BOOST_DEDUCED_TYPENAME boost::enable_if_c<detail::is_same_decayed<T, U>::value && detail::is_const_integral_bad_for_conversion<U>::value>::type* = 0) BOOST_NOEXCEPT
|
explicit optional(U& rhs, BOOST_DEDUCED_TYPENAME boost::enable_if_c<detail::is_same_decayed<T, U>::value && detail::is_const_integral_bad_for_conversion<U>::value, bool>::type = true) BOOST_NOEXCEPT
|
||||||
: ptr_(boost::addressof(rhs)) {}
|
: ptr_(boost::addressof(rhs)) {}
|
||||||
|
|
||||||
template <class U>
|
template <class U>
|
||||||
optional(U& rhs, BOOST_DEDUCED_TYPENAME boost::enable_if_c<detail::is_same_decayed<T, U>::value && !detail::is_const_integral_bad_for_conversion<U>::value>::type* = 0) BOOST_NOEXCEPT
|
optional(U& rhs, BOOST_DEDUCED_TYPENAME boost::enable_if_c<detail::is_same_decayed<T, U>::value && !detail::is_const_integral_bad_for_conversion<U>::value, bool>::type = true) BOOST_NOEXCEPT
|
||||||
: ptr_(boost::addressof(rhs)) {}
|
: ptr_(boost::addressof(rhs)) {}
|
||||||
|
|
||||||
optional& operator=(const optional& rhs) BOOST_NOEXCEPT { ptr_ = rhs.get_ptr(); return *this; }
|
optional& operator=(const optional& rhs) BOOST_NOEXCEPT { ptr_ = rhs.get_ptr(); return *this; }
|
||||||
@ -165,11 +165,11 @@ public:
|
|||||||
optional(T&& /* rhs */) BOOST_NOEXCEPT { detail::prevent_binding_rvalue<T&&>(); }
|
optional(T&& /* rhs */) BOOST_NOEXCEPT { detail::prevent_binding_rvalue<T&&>(); }
|
||||||
|
|
||||||
template <class R>
|
template <class R>
|
||||||
optional(R&& r, BOOST_DEDUCED_TYPENAME boost::enable_if<detail::no_unboxing_cond<T, R> >::type* = 0) BOOST_NOEXCEPT
|
optional(R&& r, BOOST_DEDUCED_TYPENAME boost::enable_if<detail::no_unboxing_cond<T, R>, bool>::type = true) BOOST_NOEXCEPT
|
||||||
: ptr_(boost::addressof(r)) { detail::prevent_binding_rvalue<R>(); }
|
: ptr_(boost::addressof(r)) { detail::prevent_binding_rvalue<R>(); }
|
||||||
|
|
||||||
template <class R>
|
template <class R>
|
||||||
optional(bool cond, R&& r, BOOST_DEDUCED_TYPENAME boost::enable_if<detail::is_no_optional<R> >::type* = 0) BOOST_NOEXCEPT
|
optional(bool cond, R&& r, BOOST_DEDUCED_TYPENAME boost::enable_if<detail::is_no_optional<R>, bool>::type = true) BOOST_NOEXCEPT
|
||||||
: ptr_(cond ? boost::addressof(r) : 0) { detail::prevent_binding_rvalue<R>(); }
|
: ptr_(cond ? boost::addressof(r) : 0) { detail::prevent_binding_rvalue<R>(); }
|
||||||
|
|
||||||
template <class R>
|
template <class R>
|
||||||
@ -177,19 +177,19 @@ public:
|
|||||||
operator=(R&& r) BOOST_NOEXCEPT { detail::prevent_binding_rvalue<R>(); ptr_ = boost::addressof(r); return *this; }
|
operator=(R&& r) BOOST_NOEXCEPT { detail::prevent_binding_rvalue<R>(); ptr_ = boost::addressof(r); return *this; }
|
||||||
|
|
||||||
template <class R>
|
template <class R>
|
||||||
void emplace(R&& r, BOOST_DEDUCED_TYPENAME boost::enable_if<detail::is_no_optional<R> >::type* = 0) BOOST_NOEXCEPT
|
void emplace(R&& r, BOOST_DEDUCED_TYPENAME boost::enable_if<detail::is_no_optional<R>, bool>::type = true) BOOST_NOEXCEPT
|
||||||
{ detail::prevent_binding_rvalue<R>(); ptr_ = boost::addressof(r); }
|
{ detail::prevent_binding_rvalue<R>(); ptr_ = boost::addressof(r); }
|
||||||
|
|
||||||
template <class R>
|
template <class R>
|
||||||
T& get_value_or(R&& r, BOOST_DEDUCED_TYPENAME boost::enable_if<detail::is_no_optional<R> >::type* = 0) const BOOST_NOEXCEPT
|
T& get_value_or(R&& r, BOOST_DEDUCED_TYPENAME boost::enable_if<detail::is_no_optional<R>, bool>::type = true) const BOOST_NOEXCEPT
|
||||||
{ detail::prevent_binding_rvalue<R>(); return ptr_ ? *ptr_ : r; }
|
{ detail::prevent_binding_rvalue<R>(); return ptr_ ? *ptr_ : r; }
|
||||||
|
|
||||||
template <class R>
|
template <class R>
|
||||||
T& value_or(R&& r, BOOST_DEDUCED_TYPENAME boost::enable_if<detail::is_no_optional<R> >::type* = 0) const BOOST_NOEXCEPT
|
T& value_or(R&& r, BOOST_DEDUCED_TYPENAME boost::enable_if<detail::is_no_optional<R>, bool>::type = true) const BOOST_NOEXCEPT
|
||||||
{ detail::prevent_binding_rvalue<R>(); return ptr_ ? *ptr_ : r; }
|
{ detail::prevent_binding_rvalue<R>(); return ptr_ ? *ptr_ : r; }
|
||||||
|
|
||||||
template <class R>
|
template <class R>
|
||||||
void reset(R&& r, BOOST_DEDUCED_TYPENAME boost::enable_if<detail::is_no_optional<R> >::type* = 0) BOOST_NOEXCEPT
|
void reset(R&& r, BOOST_DEDUCED_TYPENAME boost::enable_if<detail::is_no_optional<R>, bool>::type = true) BOOST_NOEXCEPT
|
||||||
{ detail::prevent_binding_rvalue<R>(); ptr_ = boost::addressof(r); }
|
{ detail::prevent_binding_rvalue<R>(); ptr_ = boost::addressof(r); }
|
||||||
|
|
||||||
template <class F>
|
template <class F>
|
||||||
@ -200,15 +200,15 @@ public:
|
|||||||
|
|
||||||
// the following two implement a 'conditionally explicit' constructor
|
// the following two implement a 'conditionally explicit' constructor
|
||||||
template <class U>
|
template <class U>
|
||||||
explicit optional(U& v, BOOST_DEDUCED_TYPENAME boost::enable_if_c<detail::no_unboxing_cond<T, U>::value && detail::is_const_integral_bad_for_conversion<U>::value >::type* = 0) BOOST_NOEXCEPT
|
explicit optional(U& v, BOOST_DEDUCED_TYPENAME boost::enable_if_c<detail::no_unboxing_cond<T, U>::value && detail::is_const_integral_bad_for_conversion<U>::value, bool>::type = true) BOOST_NOEXCEPT
|
||||||
: ptr_(boost::addressof(v)) { }
|
: ptr_(boost::addressof(v)) { }
|
||||||
|
|
||||||
template <class U>
|
template <class U>
|
||||||
optional(U& v, BOOST_DEDUCED_TYPENAME boost::enable_if_c<detail::no_unboxing_cond<T, U>::value && !detail::is_const_integral_bad_for_conversion<U>::value >::type* = 0) BOOST_NOEXCEPT
|
optional(U& v, BOOST_DEDUCED_TYPENAME boost::enable_if_c<detail::no_unboxing_cond<T, U>::value && !detail::is_const_integral_bad_for_conversion<U>::value, bool>::type = true) BOOST_NOEXCEPT
|
||||||
: ptr_(boost::addressof(v)) { }
|
: ptr_(boost::addressof(v)) { }
|
||||||
|
|
||||||
template <class U>
|
template <class U>
|
||||||
optional(bool cond, U& v, BOOST_DEDUCED_TYPENAME boost::enable_if<detail::is_no_optional<U> >::type* = 0) BOOST_NOEXCEPT : ptr_(cond ? boost::addressof(v) : 0) {}
|
optional(bool cond, U& v, BOOST_DEDUCED_TYPENAME boost::enable_if<detail::is_no_optional<U>, bool>::type = true) BOOST_NOEXCEPT : ptr_(cond ? boost::addressof(v) : 0) {}
|
||||||
|
|
||||||
template <class U>
|
template <class U>
|
||||||
BOOST_DEDUCED_TYPENAME boost::enable_if<detail::is_no_optional<U>, optional<T&>&>::type
|
BOOST_DEDUCED_TYPENAME boost::enable_if<detail::is_no_optional<U>, optional<T&>&>::type
|
||||||
@ -219,19 +219,19 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <class U>
|
template <class U>
|
||||||
void emplace(U& v, BOOST_DEDUCED_TYPENAME boost::enable_if<detail::is_no_optional<U> >::type* = 0) BOOST_NOEXCEPT
|
void emplace(U& v, BOOST_DEDUCED_TYPENAME boost::enable_if<detail::is_no_optional<U>, bool>::type = true) BOOST_NOEXCEPT
|
||||||
{ ptr_ = boost::addressof(v); }
|
{ ptr_ = boost::addressof(v); }
|
||||||
|
|
||||||
template <class U>
|
template <class U>
|
||||||
T& get_value_or(U& v, BOOST_DEDUCED_TYPENAME boost::enable_if<detail::is_no_optional<U> >::type* = 0) const BOOST_NOEXCEPT
|
T& get_value_or(U& v, BOOST_DEDUCED_TYPENAME boost::enable_if<detail::is_no_optional<U>, bool>::type = true) const BOOST_NOEXCEPT
|
||||||
{ return ptr_ ? *ptr_ : v; }
|
{ return ptr_ ? *ptr_ : v; }
|
||||||
|
|
||||||
template <class U>
|
template <class U>
|
||||||
T& value_or(U& v, BOOST_DEDUCED_TYPENAME boost::enable_if<detail::is_no_optional<U> >::type* = 0) const BOOST_NOEXCEPT
|
T& value_or(U& v, BOOST_DEDUCED_TYPENAME boost::enable_if<detail::is_no_optional<U>, bool>::type = true) const BOOST_NOEXCEPT
|
||||||
{ return ptr_ ? *ptr_ : v; }
|
{ return ptr_ ? *ptr_ : v; }
|
||||||
|
|
||||||
template <class U>
|
template <class U>
|
||||||
void reset(U& v, BOOST_DEDUCED_TYPENAME boost::enable_if<detail::is_no_optional<U> >::type* = 0) BOOST_NOEXCEPT
|
void reset(U& v, BOOST_DEDUCED_TYPENAME boost::enable_if<detail::is_no_optional<U>, bool>::type = true) BOOST_NOEXCEPT
|
||||||
{ ptr_ = boost::addressof(v); }
|
{ ptr_ = boost::addressof(v); }
|
||||||
|
|
||||||
template <class F>
|
template <class F>
|
||||||
|
@ -149,7 +149,7 @@ class optional_base : public optional_tag
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Creates an optional<T> initialized with 'val' IFF cond is true, otherwise creates an uninitialzed optional<T>.
|
// Creates an optional<T> initialized with 'val' IFF cond is true, otherwise creates an uninitialized optional<T>.
|
||||||
// Can throw if T::T(T const&) does
|
// Can throw if T::T(T const&) does
|
||||||
optional_base ( bool cond, argument_type val )
|
optional_base ( bool cond, argument_type val )
|
||||||
:
|
:
|
||||||
@ -160,7 +160,7 @@ class optional_base : public optional_tag
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES
|
#ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES
|
||||||
// Creates an optional<T> initialized with 'move(val)' IFF cond is true, otherwise creates an uninitialzed optional<T>.
|
// Creates an optional<T> initialized with 'move(val)' IFF cond is true, otherwise creates an uninitialized optional<T>.
|
||||||
// Can throw if T::T(T &&) does
|
// Can throw if T::T(T &&) does
|
||||||
optional_base ( bool cond, rval_reference_type val )
|
optional_base ( bool cond, rval_reference_type val )
|
||||||
:
|
:
|
||||||
@ -747,7 +747,7 @@ class optional_base : public optional_tag
|
|||||||
|
|
||||||
private :
|
private :
|
||||||
|
|
||||||
#if BOOST_WORKAROUND(BOOST_MSVC, <= 1600)
|
#if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1900))
|
||||||
void destroy_impl ( ) { m_storage.ptr_ref()->~T() ; m_initialized = false ; }
|
void destroy_impl ( ) { m_storage.ptr_ref()->~T() ; m_initialized = false ; }
|
||||||
#else
|
#else
|
||||||
void destroy_impl ( ) { m_storage.ref().T::~T() ; m_initialized = false ; }
|
void destroy_impl ( ) { m_storage.ref().T::~T() ; m_initialized = false ; }
|
||||||
@ -884,7 +884,7 @@ class optional
|
|||||||
template<class U>
|
template<class U>
|
||||||
explicit optional ( optional<U> const& rhs
|
explicit optional ( optional<U> const& rhs
|
||||||
#ifndef BOOST_OPTIONAL_DETAIL_NO_SFINAE_FRIENDLY_CONSTRUCTORS
|
#ifndef BOOST_OPTIONAL_DETAIL_NO_SFINAE_FRIENDLY_CONSTRUCTORS
|
||||||
,typename boost::enable_if< optional_detail::is_optional_constructible<T, U const&> >::type* = 0
|
,BOOST_DEDUCED_TYPENAME boost::enable_if< optional_detail::is_optional_constructible<T, U const&>, bool>::type = true
|
||||||
#endif
|
#endif
|
||||||
)
|
)
|
||||||
:
|
:
|
||||||
@ -901,7 +901,7 @@ class optional
|
|||||||
template<class U>
|
template<class U>
|
||||||
explicit optional ( optional<U> && rhs
|
explicit optional ( optional<U> && rhs
|
||||||
#ifndef BOOST_OPTIONAL_DETAIL_NO_SFINAE_FRIENDLY_CONSTRUCTORS
|
#ifndef BOOST_OPTIONAL_DETAIL_NO_SFINAE_FRIENDLY_CONSTRUCTORS
|
||||||
,typename boost::enable_if< optional_detail::is_optional_constructible<T, U> >::type* = 0
|
,BOOST_DEDUCED_TYPENAME boost::enable_if< optional_detail::is_optional_constructible<T, U>, bool>::type = true
|
||||||
#endif
|
#endif
|
||||||
)
|
)
|
||||||
:
|
:
|
||||||
@ -927,7 +927,7 @@ class optional
|
|||||||
|
|
||||||
template<class Expr>
|
template<class Expr>
|
||||||
explicit optional ( Expr&& expr,
|
explicit optional ( Expr&& expr,
|
||||||
BOOST_DEDUCED_TYPENAME boost::enable_if< optional_detail::is_optional_val_init_candidate<T, Expr> >::type* = 0
|
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))
|
: base(boost::forward<Expr>(expr),boost::addressof(expr))
|
||||||
{}
|
{}
|
||||||
|
@ -43,6 +43,7 @@ import testing ;
|
|||||||
[ run optional_test_emplace.cpp ]
|
[ run optional_test_emplace.cpp ]
|
||||||
[ run optional_test_minimum_requirements.cpp ]
|
[ run optional_test_minimum_requirements.cpp ]
|
||||||
[ run optional_test_msvc_bug_workaround.cpp ]
|
[ run optional_test_msvc_bug_workaround.cpp ]
|
||||||
|
[ run optional_test_member_T.cpp ]
|
||||||
[ run optional_test_tc_base.cpp ]
|
[ run optional_test_tc_base.cpp ]
|
||||||
[ compile optional_test_sfinae_friendly_ctor.cpp ]
|
[ compile optional_test_sfinae_friendly_ctor.cpp ]
|
||||||
[ compile-fail optional_test_ref_convert_assign_const_int_prevented.cpp ]
|
[ compile-fail optional_test_ref_convert_assign_const_int_prevented.cpp ]
|
||||||
|
44
test/optional_test_member_T.cpp
Normal file
44
test/optional_test_member_T.cpp
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
// 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
|
||||||
|
|
||||||
|
#include "boost/core/lightweight_test.hpp"
|
||||||
|
|
||||||
|
struct Status
|
||||||
|
{
|
||||||
|
enum T
|
||||||
|
{
|
||||||
|
DISCONNECTED,
|
||||||
|
CONNECTING,
|
||||||
|
CONNECTED,
|
||||||
|
};
|
||||||
|
|
||||||
|
T mValue;
|
||||||
|
};
|
||||||
|
|
||||||
|
void test_member_T()
|
||||||
|
{
|
||||||
|
boost::optional<Status> x = Status();
|
||||||
|
x->mValue = Status::CONNECTED;
|
||||||
|
|
||||||
|
BOOST_TEST(x->mValue == Status::CONNECTED);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
test_member_T();
|
||||||
|
return boost::report_errors();
|
||||||
|
}
|
Reference in New Issue
Block a user