mirror of
https://github.com/boostorg/optional.git
synced 2025-07-15 05:16:36 +02:00
Compare commits
40 Commits
pr/remove-
...
optional-2
Author | SHA1 | Date | |
---|---|---|---|
c486bb724c | |||
19b94c01f3 | |||
404f40bcc1 | |||
9b1f8033eb | |||
e52d7d4a9e | |||
ed9edd54e4 | |||
d2479d6f52 | |||
d4a4a5b6ad | |||
9581804efa | |||
d07ae78901 | |||
683dbe2412 | |||
010ee00604 | |||
13bc27698e | |||
0481b05d1f | |||
4c863f5bf8 | |||
9ed20cb085 | |||
4fbb7582e1 | |||
29dfc173c6 | |||
f4d1107e86 | |||
324272fc0e | |||
ee575b34c5 | |||
a192204b41 | |||
545fd9a72f | |||
29b2dae630 | |||
2f3cf1ca84 | |||
24d29e5865 | |||
eea107d9b5 | |||
69e239530e | |||
65bb040db8 | |||
fae2791f45 | |||
0f8e356bca | |||
59277bc31f | |||
bebc606a4c | |||
106f9aee5e | |||
350ebab88a | |||
a3916b46a9 | |||
155ad5911e | |||
2854383cf7 | |||
8f992acb94 | |||
c3abf83426 |
@ -151,6 +151,7 @@ matrix:
|
||||
- llvm-toolchain-precise-3.9
|
||||
|
||||
- os: linux
|
||||
dist: trusty
|
||||
compiler: clang++-4.0
|
||||
env: TOOLSET=clang COMPILER=clang++-4.0 CXXSTD=03,11,14,1z
|
||||
addons:
|
||||
@ -162,6 +163,7 @@ matrix:
|
||||
- llvm-toolchain-trusty-4.0
|
||||
|
||||
- os: linux
|
||||
dist: trusty
|
||||
compiler: clang++-5.0
|
||||
env: TOOLSET=clang COMPILER=clang++-5.0 CXXSTD=03,11,14,1z
|
||||
addons:
|
||||
|
28
CMakeLists.txt
Normal file
28
CMakeLists.txt
Normal file
@ -0,0 +1,28 @@
|
||||
# Copyright 2019 Mike Dev
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt
|
||||
#
|
||||
# NOTE: CMake support for Boost.Optional is currently experimental at best
|
||||
# and the interface is likely to change in the future
|
||||
|
||||
cmake_minimum_required( VERSION 3.5 )
|
||||
project( BoostOptional )
|
||||
|
||||
add_library( boost_optional INTERFACE )
|
||||
add_library( Boost::optional ALIAS boost_optional )
|
||||
|
||||
target_include_directories( boost_optional INTERFACE include )
|
||||
|
||||
target_link_libraries( boost_optional
|
||||
INTERFACE
|
||||
Boost::assert
|
||||
Boost::config
|
||||
Boost::core
|
||||
Boost::detail
|
||||
Boost::move
|
||||
Boost::predef
|
||||
Boost::static_assert
|
||||
Boost::throw_exception
|
||||
Boost::type_traits
|
||||
Boost::utility
|
||||
)
|
@ -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,19 @@
|
||||
|
||||
[section:relnotes Release Notes]
|
||||
|
||||
[heading Boost Release 1.73]
|
||||
|
||||
* Fixed [@https://github.com/boostorg/optional/issues/78 issue #78].
|
||||
* `boost::none` is now declared as an inline variable (on compilers taht support it): there is only one instance of `boost::none` across all translation units.
|
||||
* Fixed a number of compilation errors in GCC 4.4.7 in `optional<T>` for trivial `T`s. Thanks to Robert Leahy for the fix. For details see [@https://github.com/boostorg/optional/pull/80 pr #78].
|
||||
* Now surpressing warning `-Wweak-vtables`.
|
||||
|
||||
[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,47 @@
|
||||
</h2></div></div></div>
|
||||
<h4>
|
||||
<a name="boost_optional.relnotes.h0"></a>
|
||||
<span class="phrase"><a name="boost_optional.relnotes.boost_release_1_73"></a></span><a class="link" href="relnotes.html#boost_optional.relnotes.boost_release_1_73">Boost
|
||||
Release 1.73</a>
|
||||
</h4>
|
||||
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
|
||||
<li class="listitem">
|
||||
Fixed <a href="https://github.com/boostorg/optional/issues/78" target="_top">issue
|
||||
#78</a>.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
<code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">none</span></code> is now declared as an inline variable
|
||||
(on compilers taht support it): there is only one instance of <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">none</span></code> across all translation units.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
Fixed a number of compilation errors in GCC 4.4.7 in <code class="computeroutput"><span class="identifier">optional</span><span class="special"><</span><span class="identifier">T</span><span class="special">></span></code> for trivial <code class="computeroutput"><span class="identifier">T</span></code>s.
|
||||
Thanks to Robert Leahy for the fix. For details see <a href="https://github.com/boostorg/optional/pull/80" target="_top">pr
|
||||
#78</a>.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
Now surpressing warning <code class="computeroutput"><span class="special">-</span><span class="identifier">Wweak</span><span class="special">-</span><span class="identifier">vtables</span></code>.
|
||||
</li>
|
||||
</ul></div>
|
||||
<h4>
|
||||
<a name="boost_optional.relnotes.h1"></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.h2"></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 +85,7 @@
|
||||
</li>
|
||||
</ul></div>
|
||||
<h4>
|
||||
<a name="boost_optional.relnotes.h1"></a>
|
||||
<a name="boost_optional.relnotes.h3"></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 +99,7 @@
|
||||
</li>
|
||||
</ul></div>
|
||||
<h4>
|
||||
<a name="boost_optional.relnotes.h2"></a>
|
||||
<a name="boost_optional.relnotes.h4"></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 +117,7 @@
|
||||
</li>
|
||||
</ul></div>
|
||||
<h4>
|
||||
<a name="boost_optional.relnotes.h3"></a>
|
||||
<a name="boost_optional.relnotes.h5"></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 +141,7 @@
|
||||
</li>
|
||||
</ul></div>
|
||||
<h4>
|
||||
<a name="boost_optional.relnotes.h4"></a>
|
||||
<a name="boost_optional.relnotes.h6"></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 +149,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.h7"></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 +192,7 @@
|
||||
</li>
|
||||
</ul></div>
|
||||
<h4>
|
||||
<a name="boost_optional.relnotes.h6"></a>
|
||||
<a name="boost_optional.relnotes.h8"></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 +203,7 @@
|
||||
#11203</a>.
|
||||
</li></ul></div>
|
||||
<h4>
|
||||
<a name="boost_optional.relnotes.h7"></a>
|
||||
<a name="boost_optional.relnotes.h9"></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 +217,7 @@
|
||||
</li>
|
||||
</ul></div>
|
||||
<h4>
|
||||
<a name="boost_optional.relnotes.h8"></a>
|
||||
<a name="boost_optional.relnotes.h10"></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 +253,7 @@
|
||||
</li>
|
||||
</ul></div>
|
||||
<h4>
|
||||
<a name="boost_optional.relnotes.h9"></a>
|
||||
<a name="boost_optional.relnotes.h11"></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 +263,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.h12"></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: April 08, 2020 at 23:09:18 GMT</small></p></td>
|
||||
<td align="right"><div class="copyright-footer"></div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
|
@ -13,6 +13,7 @@
|
||||
#ifndef BOOST_NONE_17SEP2003_HPP
|
||||
#define BOOST_NONE_17SEP2003_HPP
|
||||
|
||||
#include "boost/config.hpp"
|
||||
#include "boost/none_t.hpp"
|
||||
|
||||
// NOTE: Borland users have to include this header outside any precompiled headers
|
||||
@ -23,7 +24,7 @@ namespace boost {
|
||||
|
||||
#ifdef BOOST_OPTIONAL_USE_OLD_DEFINITION_OF_NONE
|
||||
|
||||
none_t const none = (static_cast<none_t>(0)) ;
|
||||
BOOST_INLINE_VARIABLE none_t const none = (static_cast<none_t>(0)) ;
|
||||
|
||||
#elif defined BOOST_OPTIONAL_USE_SINGLETON_DEFINITION_OF_NONE
|
||||
|
||||
@ -35,7 +36,7 @@ namespace detail { namespace optional_detail {
|
||||
{
|
||||
static const T instance;
|
||||
};
|
||||
|
||||
|
||||
template <typename T>
|
||||
const T none_instance<T>::instance = T(); // global, but because 'tis a template, no cpp file required
|
||||
|
||||
@ -49,7 +50,7 @@ namespace {
|
||||
|
||||
#else
|
||||
|
||||
const none_t none ((none_t::init_tag()));
|
||||
BOOST_INLINE_VARIABLE const none_t none ((none_t::init_tag()));
|
||||
|
||||
#endif // older definitions
|
||||
|
||||
|
@ -19,6 +19,11 @@
|
||||
|
||||
namespace boost {
|
||||
|
||||
#if defined(__clang__)
|
||||
# pragma clang diagnostic push
|
||||
# pragma clang diagnostic ignored "-Wweak-vtables"
|
||||
#endif
|
||||
|
||||
class bad_optional_access : public std::logic_error
|
||||
{
|
||||
public:
|
||||
@ -27,6 +32,10 @@ public:
|
||||
{}
|
||||
};
|
||||
|
||||
#if defined(__clang__)
|
||||
# pragma clang diagnostic pop
|
||||
#endif
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif
|
||||
|
@ -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(); }
|
||||
|
||||
@ -359,7 +359,7 @@ class tc_optional_base : public optional_tag
|
||||
template<class Expr>
|
||||
void construct ( Expr const& factory, in_place_factory_base const* )
|
||||
{
|
||||
boost_optional_detail::construct<value_type>(factory, m_storage.address());
|
||||
boost_optional_detail::construct<value_type>(factory, boost::addressof(m_storage));
|
||||
m_initialized = true ;
|
||||
}
|
||||
|
||||
|
@ -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(); }
|
||||
|
||||
@ -775,7 +777,7 @@ class optional_base : public optional_tag
|
||||
|
||||
#include <boost/optional/detail/optional_trivially_copyable_base.hpp>
|
||||
|
||||
// definition of metafunciton is_optional_val_init_candidate
|
||||
// definition of metafunction is_optional_val_init_candidate
|
||||
template <typename U>
|
||||
struct is_optional_related
|
||||
: boost::conditional< boost::is_base_of<optional_detail::optional_tag, BOOST_DEDUCED_TYPENAME boost::decay<U>::type>::value
|
||||
@ -811,9 +813,14 @@ struct is_optional_constructible : boost::true_type
|
||||
|
||||
#endif // is_convertible condition
|
||||
|
||||
template <typename T, typename U>
|
||||
template <typename T, typename U, bool = is_optional_related<U>::value>
|
||||
struct is_optional_val_init_candidate
|
||||
: boost::conditional< !is_optional_related<U>::value && is_convertible_to_T_or_factory<T, U>::value
|
||||
: boost::false_type
|
||||
{};
|
||||
|
||||
template <typename T, typename U>
|
||||
struct is_optional_val_init_candidate<T, U, false>
|
||||
: boost::conditional< is_convertible_to_T_or_factory<T, U>::value
|
||||
, boost::true_type, boost::false_type>::type
|
||||
{};
|
||||
|
||||
@ -870,12 +877,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
|
||||
|
||||
@ -965,7 +972,7 @@ class optional
|
||||
// Can throw if T::T(T&&) does
|
||||
|
||||
#ifndef BOOST_OPTIONAL_DETAIL_NO_DEFAULTED_MOVE_FUNCTIONS
|
||||
optional ( optional && rhs ) = default;
|
||||
optional ( optional && ) = default;
|
||||
#else
|
||||
optional ( optional && rhs )
|
||||
BOOST_NOEXCEPT_IF(::boost::is_nothrow_move_constructible<T>::value)
|
||||
|
@ -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,8 @@ import testing ;
|
||||
[ run optional_test_member_T.cpp ]
|
||||
[ run optional_test_tc_base.cpp ]
|
||||
[ compile optional_test_sfinae_friendly_ctor.cpp ]
|
||||
[ compile optional_test_path_assignment.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 +77,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();
|
||||
}
|
59
test/optional_test_constructible_from_other.cpp
Normal file
59
test/optional_test_constructible_from_other.cpp
Normal file
@ -0,0 +1,59 @@
|
||||
// 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
|
||||
{
|
||||
static U& get();
|
||||
|
||||
template< typename T1 >
|
||||
static yes_type check_helper(size_tag< sizeof(static_cast< T1 >(get())) >*);
|
||||
template< typename T1 >
|
||||
static no_type check_helper(...);
|
||||
|
||||
static const bool value = sizeof(check_helper< T >(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();
|
||||
}
|
@ -31,10 +31,10 @@ struct Guard
|
||||
std::string str;
|
||||
Guard() : num() {}
|
||||
Guard(double num_, std::string str_) : num(num_), str(str_) {}
|
||||
|
||||
|
||||
friend bool operator==(const Guard& lhs, const Guard& rhs) { return lhs.num == rhs.num && lhs.str == rhs.str; }
|
||||
friend bool operator!=(const Guard& lhs, const Guard& rhs) { return !(lhs == rhs); }
|
||||
|
||||
|
||||
private:
|
||||
Guard(const Guard&);
|
||||
Guard& operator=(const Guard&);
|
||||
@ -44,26 +44,30 @@ void test_ctor()
|
||||
{
|
||||
#ifndef BOOST_OPTIONAL_NO_INPLACE_FACTORY_SUPPORT
|
||||
Guard g0, g1(1.0, "one"), g2(2.0, "two");
|
||||
|
||||
|
||||
boost::optional<Guard> og0 ( boost::in_place() );
|
||||
boost::optional<Guard> og1 ( boost::in_place(1.0, "one") );
|
||||
boost::optional<Guard> og1_( boost::in_place(1.0, "one") );
|
||||
boost::optional<Guard> og2 ( boost::in_place<Guard>(2.0, "two") );
|
||||
|
||||
|
||||
BOOST_TEST(og0);
|
||||
BOOST_TEST(og1);
|
||||
BOOST_TEST(og1_);
|
||||
BOOST_TEST(og2);
|
||||
|
||||
|
||||
BOOST_TEST(*og0 == g0);
|
||||
BOOST_TEST(*og1 == g1);
|
||||
BOOST_TEST(*og1_ == g1);
|
||||
BOOST_TEST(*og2 == g2);
|
||||
|
||||
|
||||
BOOST_TEST(og1_ == og1);
|
||||
BOOST_TEST(og1_ != og2);
|
||||
BOOST_TEST(og1_ != og0);
|
||||
#endif
|
||||
|
||||
boost::optional<unsigned int> o( boost::in_place(5) );
|
||||
BOOST_TEST(o);
|
||||
BOOST_TEST(*o == 5);
|
||||
#endif
|
||||
}
|
||||
|
||||
void test_assign()
|
||||
@ -71,27 +75,32 @@ void test_assign()
|
||||
#ifndef BOOST_OPTIONAL_NO_INPLACE_FACTORY_SUPPORT
|
||||
#ifndef BOOST_OPTIONAL_WEAK_OVERLOAD_RESOLUTION
|
||||
Guard g0, g1(1.0, "one"), g2(2.0, "two");
|
||||
|
||||
|
||||
boost::optional<Guard> og0, og1, og1_, og2;
|
||||
|
||||
|
||||
og0 = boost::in_place();
|
||||
og1 = boost::in_place(1.0, "one");
|
||||
og1_ = boost::in_place(1.0, "one");
|
||||
og2 = boost::in_place<Guard>(2.0, "two");
|
||||
|
||||
|
||||
BOOST_TEST(og0);
|
||||
BOOST_TEST(og1);
|
||||
BOOST_TEST(og1_);
|
||||
BOOST_TEST(og2);
|
||||
|
||||
|
||||
BOOST_TEST(*og0 == g0);
|
||||
BOOST_TEST(*og1 == g1);
|
||||
BOOST_TEST(*og1_ == g1);
|
||||
BOOST_TEST(*og2 == g2);
|
||||
|
||||
|
||||
BOOST_TEST(og1_ == og1);
|
||||
BOOST_TEST(og1_ != og2);
|
||||
BOOST_TEST(og1_ != og0);
|
||||
|
||||
boost::optional<unsigned int> o;
|
||||
o = boost::in_place(5);
|
||||
BOOST_TEST(o);
|
||||
BOOST_TEST(*o == 5);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
@ -101,4 +110,4 @@ int main()
|
||||
test_ctor();
|
||||
test_assign();
|
||||
return boost::report_errors();
|
||||
}
|
||||
}
|
||||
|
73
test/optional_test_path_assignment.cpp
Normal file
73
test/optional_test_path_assignment.cpp
Normal file
@ -0,0 +1,73 @@
|
||||
// Copyright (C) 2019 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
|
||||
|
||||
#ifndef BOOST_OPTIONAL_DETAIL_NO_IS_CONSTRUCTIBLE_TRAIT
|
||||
#ifndef BOOST_OPTIONAL_DETAIL_NO_SFINAE_FRIENDLY_CONSTRUCTORS
|
||||
template <typename, typename>
|
||||
struct void_t
|
||||
{
|
||||
typedef void type;
|
||||
};
|
||||
|
||||
|
||||
template <typename T, typename = void>
|
||||
struct trait
|
||||
{
|
||||
};
|
||||
|
||||
// the following trait emulates properties std::iterator_traits
|
||||
template <typename T>
|
||||
struct trait<T, BOOST_DEDUCED_TYPENAME void_t<BOOST_DEDUCED_TYPENAME T::value_type,
|
||||
BOOST_DEDUCED_TYPENAME boost::enable_if<boost::is_constructible<T, T&> >::type
|
||||
>::type>
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME T::value_type value_type;
|
||||
};
|
||||
|
||||
// This class emulates the properties of std::filesystem::path
|
||||
struct Path
|
||||
{
|
||||
|
||||
#if __cplusplus >= 201103
|
||||
template <typename T, typename = BOOST_DEDUCED_TYPENAME trait<T>::value_type>
|
||||
Path(T const&);
|
||||
#else
|
||||
template <typename T>
|
||||
Path(T const&, BOOST_DEDUCED_TYPENAME trait<T>::value_type* = 0);
|
||||
#endif
|
||||
|
||||
};
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
#ifndef BOOST_OPTIONAL_DETAIL_NO_IS_CONSTRUCTIBLE_TRAIT
|
||||
#ifndef BOOST_OPTIONAL_DETAIL_NO_SFINAE_FRIENDLY_CONSTRUCTORS
|
||||
|
||||
boost::optional<Path> optFs1;
|
||||
boost::optional<Path> optFs2;
|
||||
|
||||
optFs1 = optFs2;
|
||||
|
||||
// the following still fails although it shouldn't
|
||||
//BOOST_STATIC_ASSERT((std::is_copy_constructible<boost::optional<Path>>::value));
|
||||
|
||||
#endif
|
||||
#endif
|
||||
}
|
@ -93,7 +93,9 @@ template <typename T>
|
||||
void test_all_const_cases()
|
||||
{
|
||||
test_converting_ctor<T>();
|
||||
#ifndef BOOST_OPTIONAL_CONFIG_NO_PROPER_CONVERT_FROM_CONST_INT
|
||||
test_converting_ctor<const T>();
|
||||
#endif
|
||||
test_converting_ctor_for_noconst_const<T>();
|
||||
}
|
||||
|
||||
|
@ -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