mirror of
https://github.com/boostorg/optional.git
synced 2025-07-14 12:56:35 +02:00
Compare commits
18 Commits
pr/remove-
...
boost-1.73
Author | SHA1 | Date | |
---|---|---|---|
a192204b41 | |||
545fd9a72f | |||
29b2dae630 | |||
2f3cf1ca84 | |||
24d29e5865 | |||
eea107d9b5 | |||
69e239530e | |||
65bb040db8 | |||
fae2791f45 | |||
0f8e356bca | |||
59277bc31f | |||
bebc606a4c | |||
106f9aee5e | |||
350ebab88a | |||
a3916b46a9 | |||
155ad5911e | |||
2854383cf7 | |||
8f992acb94 |
@ -196,11 +196,10 @@ They are empty, trivially copyable classes with disabled default constructor.
|
||||
|
||||
bool operator!() const noexcept ; ``[link reference_optional_operator_not __GO_TO__]``
|
||||
|
||||
// deprecated methods
|
||||
|
||||
// (deprecated)
|
||||
void reset() noexcept ; ``[link reference_optional_reset __GO_TO__]``
|
||||
|
||||
// deprecated methods
|
||||
|
||||
// (deprecated)
|
||||
void reset ( T const& ) ; ``[link reference_optional_reset_value __GO_TO__]``
|
||||
|
||||
@ -275,11 +274,10 @@ They are empty, trivially copyable classes with disabled default constructor.
|
||||
|
||||
bool operator!() const noexcept ; ``[link reference_optional_ref_operator_not __GO_TO__]``
|
||||
|
||||
// deprecated methods
|
||||
|
||||
// (deprecated)
|
||||
void reset() noexcept ; ``[link reference_optional_ref_reset __GO_TO__]``
|
||||
|
||||
// deprecated methods
|
||||
|
||||
// (deprecated)
|
||||
template<class R> void reset ( R && r ) noexcept ; ``[link reference_optional_ref_reset_value __GO_TO__]``
|
||||
|
||||
|
@ -541,7 +541,7 @@ __SPACE__
|
||||
[#reference_optional_reset]
|
||||
|
||||
[: `void optional<T>::reset() noexcept ;`]
|
||||
* [*Deprecated:] Same as `operator=( none_t );`
|
||||
* [*Effects:] Same as `operator=( none_t );`
|
||||
|
||||
__SPACE__
|
||||
|
||||
@ -1129,8 +1129,7 @@ __SPACE__
|
||||
|
||||
[#reference_optional_ref_reset]
|
||||
[: `void optional<T&>::reset() noexcept;`]
|
||||
* [*Effects:] Use `*this = none` instead.
|
||||
* [*Remarks:] This function is depprecated.
|
||||
* [*Effects:] Same as `*this = none`.
|
||||
|
||||
__SPACE__
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
[/
|
||||
Boost.Optional
|
||||
|
||||
Copyright (c) 2015, 2016 Andrzej Krzemienski
|
||||
Copyright (c) 2015 - 2018 Andrzej Krzemienski
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE_1_0.txt or copy at
|
||||
@ -11,6 +11,12 @@
|
||||
|
||||
[section:relnotes Release Notes]
|
||||
|
||||
[heading Boost Release 1.69]
|
||||
|
||||
* Remove deprecation mark from `reset()` method (without arguments).
|
||||
* Fixed [@https://github.com/boostorg/optional/issues/59 issue #59].
|
||||
* Fixed bug with initialization of certain wrapper types in clang with -std=c++03. See [@https://github.com/boostorg/optional/pull/64 pr #64].
|
||||
|
||||
[heading Boost Release 1.68]
|
||||
|
||||
* Added member function `has_value()` for compatibility with `std::optional` ([@https://github.com/boostorg/optional/issues/52 issue #52]).
|
||||
|
@ -486,14 +486,9 @@
|
||||
<a name="reference_optional_ref_reset"></a><div class="blockquote"><blockquote class="blockquote"><p>
|
||||
<code class="computeroutput"><span class="keyword">void</span> <span class="identifier">optional</span><span class="special"><</span><span class="identifier">T</span><span class="special">&>::</span><span class="identifier">reset</span><span class="special">()</span> <span class="keyword">noexcept</span><span class="special">;</span></code>
|
||||
</p></blockquote></div>
|
||||
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
|
||||
<li class="listitem">
|
||||
<span class="bold"><strong>Effects:</strong></span> Use <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span> <span class="special">=</span> <span class="identifier">none</span></code> instead.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
<span class="bold"><strong>Remarks:</strong></span> This function is depprecated.
|
||||
</li>
|
||||
</ul></div>
|
||||
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
|
||||
<span class="bold"><strong>Effects:</strong></span> Same as <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span> <span class="special">=</span> <span class="identifier">none</span></code>.
|
||||
</li></ul></div>
|
||||
<p>
|
||||
<span class="inlinemediaobject"><img src="../../../images/space.png" alt="space"></span>
|
||||
</p>
|
||||
|
@ -1199,8 +1199,8 @@
|
||||
<span class="special">;</span></code>
|
||||
</p></blockquote></div>
|
||||
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
|
||||
<span class="bold"><strong>Deprecated:</strong></span> Same as <code class="computeroutput"><span class="keyword">operator</span><span class="special">=(</span>
|
||||
<span class="identifier">none_t</span> <span class="special">);</span></code>
|
||||
<span class="bold"><strong>Effects:</strong></span> Same as <code class="computeroutput"><span class="keyword">operator</span><span class="special">=(</span> <span class="identifier">none_t</span>
|
||||
<span class="special">);</span></code>
|
||||
</li></ul></div>
|
||||
<p>
|
||||
<span class="inlinemediaobject"><img src="../../../images/space.png" alt="space"></span>
|
||||
|
@ -84,11 +84,10 @@
|
||||
|
||||
<span class="keyword">bool</span> <span class="keyword">operator</span><span class="special">!()</span> <span class="keyword">const</span> <span class="keyword">noexcept</span> <span class="special">;</span> <a class="link" href="detailed_semantics___optional_references.html#reference_optional_ref_operator_not"><span class="inlinemediaobject"><img src="../../../images/callouts/R.png" alt="R"></span></a>
|
||||
|
||||
<span class="comment">// deprecated methods</span>
|
||||
|
||||
<span class="comment">// (deprecated)</span>
|
||||
<span class="keyword">void</span> <span class="identifier">reset</span><span class="special">()</span> <span class="keyword">noexcept</span> <span class="special">;</span> <a class="link" href="detailed_semantics___optional_references.html#reference_optional_ref_reset"><span class="inlinemediaobject"><img src="../../../images/callouts/R.png" alt="R"></span></a>
|
||||
|
||||
<span class="comment">// deprecated methods</span>
|
||||
|
||||
<span class="comment">// (deprecated)</span>
|
||||
<span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">R</span><span class="special">></span> <span class="keyword">void</span> <span class="identifier">reset</span> <span class="special">(</span> <span class="identifier">R</span> <span class="special">&&</span> <span class="identifier">r</span> <span class="special">)</span> <span class="keyword">noexcept</span> <span class="special">;</span> <a class="link" href="detailed_semantics___optional_references.html#reference_optional_ref_reset_value"><span class="inlinemediaobject"><img src="../../../images/callouts/R.png" alt="R"></span></a>
|
||||
|
||||
|
@ -122,11 +122,10 @@
|
||||
|
||||
<span class="keyword">bool</span> <span class="keyword">operator</span><span class="special">!()</span> <span class="keyword">const</span> <span class="keyword">noexcept</span> <span class="special">;</span> <a class="link" href="detailed_semantics___optional_values.html#reference_optional_operator_not"><span class="inlinemediaobject"><img src="../../../images/callouts/R.png" alt="R"></span></a>
|
||||
|
||||
<span class="comment">// deprecated methods</span>
|
||||
|
||||
<span class="comment">// (deprecated)</span>
|
||||
<span class="keyword">void</span> <span class="identifier">reset</span><span class="special">()</span> <span class="keyword">noexcept</span> <span class="special">;</span> <a class="link" href="detailed_semantics___optional_values.html#reference_optional_reset"><span class="inlinemediaobject"><img src="../../../images/callouts/R.png" alt="R"></span></a>
|
||||
|
||||
<span class="comment">// deprecated methods</span>
|
||||
|
||||
<span class="comment">// (deprecated)</span>
|
||||
<span class="keyword">void</span> <span class="identifier">reset</span> <span class="special">(</span> <span class="identifier">T</span> <span class="keyword">const</span><span class="special">&</span> <span class="special">)</span> <span class="special">;</span> <a class="link" href="detailed_semantics___optional_values.html#reference_optional_reset_value"><span class="inlinemediaobject"><img src="../../../images/callouts/R.png" alt="R"></span></a>
|
||||
|
||||
|
@ -28,6 +28,24 @@
|
||||
</h2></div></div></div>
|
||||
<h4>
|
||||
<a name="boost_optional.relnotes.h0"></a>
|
||||
<span class="phrase"><a name="boost_optional.relnotes.boost_release_1_69"></a></span><a class="link" href="relnotes.html#boost_optional.relnotes.boost_release_1_69">Boost
|
||||
Release 1.69</a>
|
||||
</h4>
|
||||
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
|
||||
<li class="listitem">
|
||||
Remove deprecation mark from <code class="computeroutput"><span class="identifier">reset</span><span class="special">()</span></code> method (without arguments).
|
||||
</li>
|
||||
<li class="listitem">
|
||||
Fixed <a href="https://github.com/boostorg/optional/issues/59" target="_top">issue
|
||||
#59</a>.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
Fixed bug with initialization of certain wrapper types in clang with -std=c++03.
|
||||
See <a href="https://github.com/boostorg/optional/pull/64" target="_top">pr #64</a>.
|
||||
</li>
|
||||
</ul></div>
|
||||
<h4>
|
||||
<a name="boost_optional.relnotes.h1"></a>
|
||||
<span class="phrase"><a name="boost_optional.relnotes.boost_release_1_68"></a></span><a class="link" href="relnotes.html#boost_optional.relnotes.boost_release_1_68">Boost
|
||||
Release 1.68</a>
|
||||
</h4>
|
||||
@ -44,7 +62,7 @@
|
||||
</li>
|
||||
</ul></div>
|
||||
<h4>
|
||||
<a name="boost_optional.relnotes.h1"></a>
|
||||
<a name="boost_optional.relnotes.h2"></a>
|
||||
<span class="phrase"><a name="boost_optional.relnotes.boost_release_1_67"></a></span><a class="link" href="relnotes.html#boost_optional.relnotes.boost_release_1_67">Boost
|
||||
Release 1.67</a>
|
||||
</h4>
|
||||
@ -58,7 +76,7 @@
|
||||
</li>
|
||||
</ul></div>
|
||||
<h4>
|
||||
<a name="boost_optional.relnotes.h2"></a>
|
||||
<a name="boost_optional.relnotes.h3"></a>
|
||||
<span class="phrase"><a name="boost_optional.relnotes.boost_release_1_66"></a></span><a class="link" href="relnotes.html#boost_optional.relnotes.boost_release_1_66">Boost
|
||||
Release 1.66</a>
|
||||
</h4>
|
||||
@ -76,7 +94,7 @@
|
||||
</li>
|
||||
</ul></div>
|
||||
<h4>
|
||||
<a name="boost_optional.relnotes.h3"></a>
|
||||
<a name="boost_optional.relnotes.h4"></a>
|
||||
<span class="phrase"><a name="boost_optional.relnotes.boost_release_1_63"></a></span><a class="link" href="relnotes.html#boost_optional.relnotes.boost_release_1_63">Boost
|
||||
Release 1.63</a>
|
||||
</h4>
|
||||
@ -100,7 +118,7 @@
|
||||
</li>
|
||||
</ul></div>
|
||||
<h4>
|
||||
<a name="boost_optional.relnotes.h4"></a>
|
||||
<a name="boost_optional.relnotes.h5"></a>
|
||||
<span class="phrase"><a name="boost_optional.relnotes.boost_release_1_62"></a></span><a class="link" href="relnotes.html#boost_optional.relnotes.boost_release_1_62">Boost
|
||||
Release 1.62</a>
|
||||
</h4>
|
||||
@ -108,7 +126,7 @@
|
||||
Fixed <a href="https://svn.boost.org/trac/boost/ticket/12179" target="_top">Trac #12179</a>.
|
||||
</li></ul></div>
|
||||
<h4>
|
||||
<a name="boost_optional.relnotes.h5"></a>
|
||||
<a name="boost_optional.relnotes.h6"></a>
|
||||
<span class="phrase"><a name="boost_optional.relnotes.boost_release_1_61"></a></span><a class="link" href="relnotes.html#boost_optional.relnotes.boost_release_1_61">Boost
|
||||
Release 1.61</a>
|
||||
</h4>
|
||||
@ -151,7 +169,7 @@
|
||||
</li>
|
||||
</ul></div>
|
||||
<h4>
|
||||
<a name="boost_optional.relnotes.h6"></a>
|
||||
<a name="boost_optional.relnotes.h7"></a>
|
||||
<span class="phrase"><a name="boost_optional.relnotes.boost_release_1_60"></a></span><a class="link" href="relnotes.html#boost_optional.relnotes.boost_release_1_60">Boost
|
||||
Release 1.60</a>
|
||||
</h4>
|
||||
@ -162,7 +180,7 @@
|
||||
#11203</a>.
|
||||
</li></ul></div>
|
||||
<h4>
|
||||
<a name="boost_optional.relnotes.h7"></a>
|
||||
<a name="boost_optional.relnotes.h8"></a>
|
||||
<span class="phrase"><a name="boost_optional.relnotes.boost_release_1_59"></a></span><a class="link" href="relnotes.html#boost_optional.relnotes.boost_release_1_59">Boost
|
||||
Release 1.59</a>
|
||||
</h4>
|
||||
@ -176,7 +194,7 @@
|
||||
</li>
|
||||
</ul></div>
|
||||
<h4>
|
||||
<a name="boost_optional.relnotes.h8"></a>
|
||||
<a name="boost_optional.relnotes.h9"></a>
|
||||
<span class="phrase"><a name="boost_optional.relnotes.boost_release_1_58"></a></span><a class="link" href="relnotes.html#boost_optional.relnotes.boost_release_1_58">Boost
|
||||
Release 1.58</a>
|
||||
</h4>
|
||||
@ -212,7 +230,7 @@
|
||||
</li>
|
||||
</ul></div>
|
||||
<h4>
|
||||
<a name="boost_optional.relnotes.h9"></a>
|
||||
<a name="boost_optional.relnotes.h10"></a>
|
||||
<span class="phrase"><a name="boost_optional.relnotes.boost_release_1_57"></a></span><a class="link" href="relnotes.html#boost_optional.relnotes.boost_release_1_57">Boost
|
||||
Release 1.57</a>
|
||||
</h4>
|
||||
@ -222,7 +240,7 @@
|
||||
to fix C++03 compile error on <code class="computeroutput"><span class="identifier">logic_error</span><span class="special">(</span><span class="string">"..."</span><span class="special">)</span></code>"</em></span>.
|
||||
</li></ul></div>
|
||||
<h4>
|
||||
<a name="boost_optional.relnotes.h10"></a>
|
||||
<a name="boost_optional.relnotes.h11"></a>
|
||||
<span class="phrase"><a name="boost_optional.relnotes.boost_release_1_56"></a></span><a class="link" href="relnotes.html#boost_optional.relnotes.boost_release_1_56">Boost
|
||||
Release 1.56</a>
|
||||
</h4>
|
||||
|
@ -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: July 02, 2018 at 21:10:01 GMT</small></p></td>
|
||||
<td align="left"><p><small>Last revised: November 08, 2018 at 17:44:53 GMT</small></p></td>
|
||||
<td align="right"><div class="copyright-footer"></div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
|
@ -332,7 +332,7 @@ class optional_base : public optional_tag
|
||||
|
||||
public :
|
||||
|
||||
// **DEPPRECATED** Destroys the current value, if any, leaving this UNINITIALIZED
|
||||
// Destroys the current value, if any, leaving this UNINITIALIZED
|
||||
// No-throw (assuming T::~T() doesn't)
|
||||
void reset() BOOST_NOEXCEPT { destroy(); }
|
||||
|
||||
|
@ -30,7 +30,7 @@ class tc_optional_base : public optional_tag
|
||||
:
|
||||
m_initialized(false) {}
|
||||
|
||||
tc_optional_base ( argument_type val )
|
||||
tc_optional_base ( init_value_tag, argument_type val )
|
||||
:
|
||||
m_initialized(true), m_storage(val) {}
|
||||
|
||||
@ -71,7 +71,7 @@ class tc_optional_base : public optional_tag
|
||||
// Assigns from another optional<T> (deep-copies the rhs value)
|
||||
void assign ( tc_optional_base const& rhs )
|
||||
{
|
||||
this->operator=(rhs);
|
||||
*this = rhs;
|
||||
}
|
||||
|
||||
// Assigns from another _convertible_ optional<U> (deep-copies the rhs value)
|
||||
@ -127,7 +127,7 @@ class tc_optional_base : public optional_tag
|
||||
|
||||
public :
|
||||
|
||||
// **DEPPRECATED** Destroys the current value, if any, leaving this UNINITIALIZED
|
||||
// Destroys the current value, if any, leaving this UNINITIALIZED
|
||||
// No-throw (assuming T::~T() doesn't)
|
||||
void reset() BOOST_NOEXCEPT { destroy(); }
|
||||
|
||||
|
@ -107,7 +107,9 @@ using optional_ns::in_place_init_if;
|
||||
|
||||
namespace optional_detail {
|
||||
|
||||
struct optional_tag {} ;
|
||||
struct init_value_tag {};
|
||||
|
||||
struct optional_tag {};
|
||||
|
||||
|
||||
template<class T>
|
||||
@ -147,7 +149,7 @@ class optional_base : public optional_tag
|
||||
|
||||
// Creates an optional<T> initialized with 'val'.
|
||||
// Can throw if T::T(T const&) does
|
||||
optional_base ( argument_type val )
|
||||
optional_base ( init_value_tag, argument_type val )
|
||||
:
|
||||
m_initialized(false)
|
||||
{
|
||||
@ -157,7 +159,7 @@ class optional_base : public optional_tag
|
||||
#ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES
|
||||
// move-construct an optional<T> initialized from an rvalue-ref to 'val'.
|
||||
// Can throw if T::T(T&&) does
|
||||
optional_base ( rval_reference_type val )
|
||||
optional_base ( init_value_tag, rval_reference_type val )
|
||||
:
|
||||
m_initialized(false)
|
||||
{
|
||||
@ -378,7 +380,7 @@ class optional_base : public optional_tag
|
||||
|
||||
public :
|
||||
|
||||
// **DEPPRECATED** Destroys the current value, if any, leaving this UNINITIALIZED
|
||||
// Destroys the current value, if any, leaving this UNINITIALIZED
|
||||
// No-throw (assuming T::~T() doesn't)
|
||||
void reset() BOOST_NOEXCEPT { destroy(); }
|
||||
|
||||
@ -870,12 +872,12 @@ class optional
|
||||
|
||||
// Creates an optional<T> initialized with 'val'.
|
||||
// Can throw if T::T(T const&) does
|
||||
optional ( argument_type val ) : base(val) {}
|
||||
optional ( argument_type val ) : base(optional_detail::init_value_tag(), val) {}
|
||||
|
||||
#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(optional_detail::init_value_tag(), boost::forward<T>(val))
|
||||
{}
|
||||
#endif
|
||||
|
||||
|
@ -18,6 +18,7 @@ import testing ;
|
||||
{
|
||||
test-suite optional :
|
||||
[ run optional_test.cpp ]
|
||||
[ run optional_test_assign.cpp ]
|
||||
[ run optional_test_swap.cpp ]
|
||||
[ run optional_test_conversions_from_U.cpp ]
|
||||
[ run optional_test_convert_from_T.cpp ]
|
||||
@ -49,6 +50,7 @@ import testing ;
|
||||
[ run optional_test_member_T.cpp ]
|
||||
[ run optional_test_tc_base.cpp ]
|
||||
[ compile optional_test_sfinae_friendly_ctor.cpp ]
|
||||
[ compile-fail optional_test_fail_const_swap.cpp ]
|
||||
[ compile-fail optional_test_ref_convert_assign_const_int_prevented.cpp ]
|
||||
[ compile-fail optional_test_fail1.cpp ]
|
||||
[ compile-fail optional_test_fail3a.cpp ]
|
||||
@ -74,6 +76,7 @@ import testing ;
|
||||
[ run optional_test_static_properties.cpp ]
|
||||
[ compile optional_test_maybe_uninitialized_warning.cpp ]
|
||||
[ compile optional_test_deleted_default_ctor.cpp ]
|
||||
[ compile optional_test_constructible_from_other.cpp ]
|
||||
#[ run optional_xconfig_HACK_TO_LIST_PREDEFINED_MACROS.cpp ]
|
||||
[ run optional_xconfig_NO_PROPER_ASSIGN_FROM_CONST_INT_pass.cpp ]
|
||||
[ run-fail optional_xconfig_NO_PROPER_ASSIGN_FROM_CONST_INT_fail.cpp ]
|
||||
|
30
test/optional_test_assign.cpp
Normal file
30
test/optional_test_assign.cpp
Normal file
@ -0,0 +1,30 @@
|
||||
// Copyright (C) 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
|
||||
|
||||
#include "boost/core/lightweight_test.hpp"
|
||||
#include "boost/optional/optional.hpp"
|
||||
|
||||
void test_assignment_to_empty()
|
||||
{
|
||||
// this test used to fail on GCC 8.1.0/8.2.0/9.0.0 with -std=c++98
|
||||
boost::optional<int> oa, ob(1);
|
||||
BOOST_TEST(!oa);
|
||||
BOOST_TEST(ob);
|
||||
|
||||
oa = ob;
|
||||
BOOST_TEST(oa);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test_assignment_to_empty();
|
||||
return boost::report_errors();
|
||||
}
|
57
test/optional_test_constructible_from_other.cpp
Normal file
57
test/optional_test_constructible_from_other.cpp
Normal file
@ -0,0 +1,57 @@
|
||||
// Copyright (c) 2018 Andrey Semashev
|
||||
//
|
||||
// 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)
|
||||
|
||||
// The test verifies that Boost.Optional copy constructors do not attempt to invoke
|
||||
// the element type initializing constructors from templated arguments
|
||||
|
||||
#include <boost/optional/optional.hpp>
|
||||
#include <boost/core/enable_if.hpp>
|
||||
|
||||
struct no_type
|
||||
{
|
||||
char data;
|
||||
};
|
||||
|
||||
struct yes_type
|
||||
{
|
||||
char data[2];
|
||||
};
|
||||
|
||||
template< unsigned int Size >
|
||||
struct size_tag {};
|
||||
|
||||
template< typename T, typename U >
|
||||
struct is_constructible
|
||||
{
|
||||
template< typename T1, typename U1 >
|
||||
static yes_type check_helper(size_tag< sizeof(static_cast< T1 >(U1())) >*);
|
||||
template< typename T1, typename U1 >
|
||||
static no_type check_helper(...);
|
||||
|
||||
static const bool value = sizeof(check_helper< T, U >(0)) == sizeof(yes_type);
|
||||
};
|
||||
|
||||
template< typename T >
|
||||
class wrapper
|
||||
{
|
||||
public:
|
||||
wrapper() {}
|
||||
wrapper(wrapper const&) {}
|
||||
template< typename U >
|
||||
wrapper(U const&, typename boost::enable_if_c< is_constructible< T, U >::value, int >::type = 0) {}
|
||||
};
|
||||
|
||||
inline boost::optional< wrapper< int > > foo()
|
||||
{
|
||||
return boost::optional< wrapper< int > >();
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
// Invokes boost::optional copy constructor. Should not invoke wrapper constructor from U.
|
||||
boost::optional< wrapper< int > > res = foo();
|
||||
return 0;
|
||||
}
|
@ -1,4 +1,6 @@
|
||||
// Copyright 2017 Peter Dimov
|
||||
// Copyright 2017 Vinnie NotDefaultConstructible
|
||||
// Copyright 2018 Andrzej Krzemienski
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
//
|
||||
@ -19,8 +21,8 @@ int main()
|
||||
|
||||
class basic_multi_buffer;
|
||||
|
||||
class const_buffers_type
|
||||
{
|
||||
class const_buffers_type // a similar declaration in boost.beast had problem
|
||||
{ // with boost opitonal
|
||||
basic_multi_buffer const* b_;
|
||||
|
||||
friend class basic_multi_buffer;
|
||||
@ -29,16 +31,36 @@ class const_buffers_type
|
||||
const_buffers_type(basic_multi_buffer const& b);
|
||||
|
||||
public:
|
||||
|
||||
const_buffers_type() = delete;
|
||||
const_buffers_type(const_buffers_type const&) = default;
|
||||
const_buffers_type& operator=(const_buffers_type const&) = default;
|
||||
};
|
||||
|
||||
void test_beast_example()
|
||||
{
|
||||
// test if it even compiles
|
||||
boost::optional< std::pair<const_buffers_type, int> > opt, opt2;
|
||||
opt = opt2;
|
||||
(void)opt;
|
||||
}
|
||||
|
||||
struct NotDefaultConstructible // minimal class exposing the problem
|
||||
{
|
||||
NotDefaultConstructible() = delete;
|
||||
};
|
||||
|
||||
void test_assign_for_non_default_constructible()
|
||||
{
|
||||
// test if it even compiles
|
||||
boost::optional<NotDefaultConstructible> opt, opt2;
|
||||
opt = opt2;
|
||||
(void)opt;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::optional< std::pair<const_buffers_type, int> > opt, opt2;
|
||||
opt = opt2;
|
||||
test_beast_example();
|
||||
test_assign_for_non_default_constructible();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
26
test/optional_test_fail_const_swap.cpp
Normal file
26
test/optional_test_fail_const_swap.cpp
Normal file
@ -0,0 +1,26 @@
|
||||
// Copyright (C) 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
|
||||
|
||||
#include "boost/optional.hpp"
|
||||
|
||||
// THIS TEST SHOULD FAIL TO COMPILE
|
||||
|
||||
void test_converitng_assignment_of_different_enums()
|
||||
{
|
||||
const boost::optional<int> o1(1);
|
||||
const boost::optional<int> o2(2);
|
||||
swap(o1, o2); // no swap on const objects should compile
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test_converitng_assignment_of_different_enums();
|
||||
}
|
@ -58,10 +58,20 @@ struct W
|
||||
|
||||
void test_value_init()
|
||||
{
|
||||
#ifndef BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX
|
||||
{
|
||||
S s;
|
||||
W<S> w{s};
|
||||
}
|
||||
#endif
|
||||
{
|
||||
S s;
|
||||
W<S> w(s);
|
||||
}
|
||||
}
|
||||
|
||||
void test_optoinal_reference_wrapper()
|
||||
{
|
||||
boost::optional<W<S&> > o;
|
||||
BOOST_TEST(boost::none == o);
|
||||
}
|
||||
@ -70,6 +80,7 @@ int main()
|
||||
{
|
||||
test_tc_base();
|
||||
test_value_init();
|
||||
test_optoinal_reference_wrapper();
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user