mirror of
https://github.com/boostorg/optional.git
synced 2025-07-14 12:56:35 +02:00
Compare commits
50 Commits
boost-1.80
...
boost-1.86
Author | SHA1 | Date | |
---|---|---|---|
c60db27762 | |||
5064a9a28d | |||
fe0384baa6 | |||
76c82e83ae | |||
e59b1bce1d | |||
f95fb5dff2 | |||
7878dec842 | |||
a3abf04548 | |||
9c43ae3612 | |||
def2db7c45 | |||
6266c39b8e | |||
e300c4bc60 | |||
302f39e545 | |||
d4f84a868d | |||
46ad495a60 | |||
246f1663e1 | |||
668c8d924b | |||
653ebefbac | |||
ce500ee436 | |||
b4c8f493c6 | |||
7e395f4520 | |||
630cf7f7b5 | |||
cdc2bd8482 | |||
db472e7ed6 | |||
8ffb7e3f57 | |||
deda20af89 | |||
4b63acfc10 | |||
599c72f23b | |||
a4479bf8cd | |||
ba1846abd3 | |||
168552e021 | |||
581c43f25c | |||
c76b73c48b | |||
e26c2d7489 | |||
969930959c | |||
56156dcc87 | |||
802e73477a | |||
9944804c5c | |||
2121a9fa59 | |||
cc416b8989 | |||
74a684232f | |||
6f85014c00 | |||
29dd9187ec | |||
bcc83a662a | |||
c4291fa461 | |||
de27c0f853 | |||
9c44e402f6 | |||
5ab4701192 | |||
ab7e5275c0 | |||
416c89e165 |
49
.github/workflows/ci.yml
vendored
49
.github/workflows/ci.yml
vendored
@ -11,6 +11,13 @@ on:
|
||||
- fix/**
|
||||
- pr/**
|
||||
|
||||
concurrency:
|
||||
group: ${{format('{0}:{1}', github.repository, github.ref)}}
|
||||
cancel-in-progress: true
|
||||
|
||||
env:
|
||||
NET_RETRY_COUNT: 5
|
||||
|
||||
jobs:
|
||||
posix:
|
||||
strategy:
|
||||
@ -110,9 +117,10 @@ jobs:
|
||||
cxxstd: "03,11,14,17"
|
||||
- name: "TOOLSET=clang COMPILER=clang++ CXXSTD=03,11 Job 7"
|
||||
buildtype: "boost"
|
||||
packages: ""
|
||||
packages: "clang"
|
||||
packages_to_remove: ""
|
||||
os: "ubuntu-18.04"
|
||||
os: "ubuntu-22.04"
|
||||
container: "ubuntu:18.04"
|
||||
cxx: "clang++"
|
||||
sources: ""
|
||||
llvm_os: ""
|
||||
@ -202,12 +210,12 @@ jobs:
|
||||
buildtype: "boost"
|
||||
packages: "clang-5.0"
|
||||
packages_to_remove: ""
|
||||
os: "ubuntu-20.04"
|
||||
container: "ubuntu:14.04"
|
||||
os: "ubuntu-22.04"
|
||||
container: "ubuntu:18.04"
|
||||
cxx: "clang++-5.0"
|
||||
sources: ""
|
||||
llvm_os: "trusty"
|
||||
llvm_ver: "5.0"
|
||||
llvm_os: ""
|
||||
llvm_ver: ""
|
||||
toolset: "clang"
|
||||
compiler: "clang++-5.0"
|
||||
cxxstd: "03,11,14,1z"
|
||||
@ -222,13 +230,17 @@ jobs:
|
||||
- name: If running in container, upgrade packages
|
||||
if: matrix.container != ''
|
||||
run: |
|
||||
apt-get -o Acquire::Retries=3 update && DEBIAN_FRONTEND=noninteractive apt-get -y install tzdata && apt-get -o Acquire::Retries=3 install -y sudo software-properties-common wget curl apt-transport-https make apt-file sudo unzip libssl-dev build-essential autotools-dev autoconf automake g++ libc++-helpers python ruby cpio gcc-multilib g++-multilib pkgconf python3 ccache libpython-dev
|
||||
sudo apt-add-repository ppa:git-core/ppa
|
||||
sudo apt-get -o Acquire::Retries=3 update && apt-get -o Acquire::Retries=3 -y install git
|
||||
python_version=$(python3 -c 'import sys; print("{0.major}.{0.minor}".format(sys.version_info))')
|
||||
sudo wget https://bootstrap.pypa.io/pip/$python_version/get-pip.py
|
||||
sudo python3 get-pip.py
|
||||
sudo /usr/local/bin/pip install cmake
|
||||
if [ -f "/etc/debian_version" ]; then
|
||||
echo "DEBIAN_FRONTEND=noninteractive" >> $GITHUB_ENV
|
||||
export DEBIAN_FRONTEND=noninteractive
|
||||
apt-get -o Acquire::Retries=$NET_RETRY_COUNT update
|
||||
apt-get -o Acquire::Retries=$NET_RETRY_COUNT install -y sudo software-properties-common curl wget apt-transport-https ca-certificates
|
||||
# Need (newer) git, and the older Ubuntu container may require requesting the key manually using port 80
|
||||
curl -sSL --retry ${NET_RETRY_COUNT:-5} 'http://keyserver.ubuntu.com/pks/lookup?op=get&search=0xE1DD270288B4E6030699E45FA1715D88E1DF1F24' | sudo gpg --dearmor > /etc/apt/trusted.gpg.d/git-core_ubuntu_ppa.gpg
|
||||
for i in {1..${NET_RETRY_COUNT:-3}}; do sudo -E add-apt-repository -y ppa:git-core/ppa && break || sleep 10; done
|
||||
apt-get -o Acquire::Retries=$NET_RETRY_COUNT update
|
||||
apt-get -o Acquire::Retries=$NET_RETRY_COUNT install -y g++ python libpython-dev git unzip libssl-dev build-essential libc++-helpers gcc-multilib g++-multilib pkgconf ccache
|
||||
fi
|
||||
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
@ -316,27 +328,20 @@ jobs:
|
||||
- name: "TOOLSET=clang COMPILER=clang++ CXXSTD=03,11,1 Job 15"
|
||||
buildtype: "boost"
|
||||
packages: ""
|
||||
os: "macos-10.15"
|
||||
os: "macos-11"
|
||||
cxx: "clang++"
|
||||
sources: ""
|
||||
llvm_os: ""
|
||||
llvm_ver: ""
|
||||
xcode_version: 11.7
|
||||
toolset: "clang"
|
||||
compiler: "clang++"
|
||||
cxxstd: "03,11,14,1z"
|
||||
cxxstd: "03,11,14,17,2a"
|
||||
|
||||
runs-on: ${{ matrix.os }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: Set DEVELOPER_DIR
|
||||
if: matrix.xcode_version != ''
|
||||
run: echo "DEVELOPER_DIR=/Applications/Xcode_${{ matrix.xcode_version }}.app/Contents/Developer" >> $GITHUB_ENV
|
||||
- name: Test DEVELOPER_DIR
|
||||
run: echo $DEVELOPER_DIR
|
||||
|
||||
- name: "osx"
|
||||
shell: bash
|
||||
env:
|
||||
|
@ -2,7 +2,7 @@
|
||||
[quickbook 1.4]
|
||||
[authors [Cacciola Carballal, Fernando Luis]]
|
||||
[copyright 2003-2007 Fernando Luis Cacciola Carballal]
|
||||
[copyright 2014-2022 Andrzej Krzemieński]
|
||||
[copyright 2014-2023 Andrzej Krzemieński]
|
||||
[category miscellaneous]
|
||||
[id optional]
|
||||
[dirname optional]
|
||||
@ -80,13 +80,14 @@ This is how you solve it with `boost::optional`:
|
||||
[include 11_development.qbk]
|
||||
[include 12_when_to_use.qbk]
|
||||
[include 13_relational_operators.qbk]
|
||||
[include 14_io.qbk]
|
||||
[include 15_optional_references.qbk]
|
||||
[include 16_in_place_factories.qbk]
|
||||
[include 17_gotchas.qbk]
|
||||
[include 18_exception_safety.qbk]
|
||||
[include 19_type_requirements.qbk]
|
||||
[include 1A_on_performance.qbk]
|
||||
[include 14_monadic_interface.qbk]
|
||||
[include 15_io.qbk]
|
||||
[include 16_optional_references.qbk]
|
||||
[include 17_in_place_factories.qbk]
|
||||
[include 18_gotchas.qbk]
|
||||
[include 19_exception_safety.qbk]
|
||||
[include 1A_type_requirements.qbk]
|
||||
[include 1B_on_performance.qbk]
|
||||
[endsect]
|
||||
[section:reference Reference]
|
||||
[include 21_ref_none.qbk]
|
||||
|
@ -44,7 +44,7 @@ This is because we know that string value `"100"` converts to a valid value of `
|
||||
// deal with it
|
||||
}
|
||||
|
||||
This version throws an exception upon an attempt to access a non-existent contained value. If your way of dealing with the missing value is to use some default, like `0`, there exists a yet another alternative:
|
||||
This version throws an exception upon an attempt to access a nonexistent contained value. If your way of dealing with the missing value is to use some default, like `0`, there exists a yet another alternative:
|
||||
|
||||
int k = convert(text).value_or(0);
|
||||
|
||||
@ -91,7 +91,7 @@ We could write function `convert` in a slightly different manner, so that it has
|
||||
return ans;
|
||||
}
|
||||
|
||||
The default constructor of `optional` creates an unitialized optional object. Unlike with `int`s you cannot have an `optional<int>` in an indeterminate state. Its state is always well defined. Instruction `ans = i` initializes the optional object. It uses the 'mixed' assignment from `int`. In general, for `optional<T>`, when an assignment from `T` is invoked, it can do two things. If the optional object is not initialized (our case here), it initializes the contained value using `T`'s copy constructor. If the optional object is already initialized, it assigns the new value to it using `T`'s copy assignment.
|
||||
The default constructor of `optional` creates an uninitialized optional object. Unlike with `int`s you cannot have an `optional<int>` in an indeterminate state. Its state is always well defined. Instruction `ans = i` initializes the optional object. It uses the 'mixed' assignment from `int`. In general, for `optional<T>`, when an assignment from `T` is invoked, it can do two things. If the optional object is not initialized (our case here), it initializes the contained value using `T`'s copy constructor. If the optional object is already initialized, it assigns the new value to it using `T`'s copy assignment.
|
||||
[endsect]
|
||||
|
||||
[section Optional data members]
|
||||
|
@ -13,7 +13,7 @@ Type `optional<T>` is __STD_EQUALITY_COMPARABLE__ whenever `T` is __STD_EQUALITY
|
||||
assert(oN == oN);
|
||||
assert(o0 == o0);
|
||||
|
||||
The converting constructor from `T` as well as from `boost::none` implies the existence and semantics of the mixed comparison between `T` and `optional<T>` as well as between `none_t` and `optionl<T>`:
|
||||
The converting constructor from `T` as well as from `boost::none` implies the existence and semantics of the mixed comparison between `T` and `optional<T>` as well as between `none_t` and `optional<T>`:
|
||||
|
||||
assert(oN != 0);
|
||||
assert(o1 != boost::none);
|
||||
|
45
doc/14_monadic_interface.qbk
Normal file
45
doc/14_monadic_interface.qbk
Normal file
@ -0,0 +1,45 @@
|
||||
[section Monadic interface]
|
||||
|
||||
The monadic interface of `optional` allows the application of functions
|
||||
to optional values without resorting to the usage of explicit `if`-statements.
|
||||
|
||||
Function `map` takes a function mapping type `T` onto type `U` and maps an `optional<T>`
|
||||
onto an `optional<U>` using the provided function.
|
||||
|
||||
int length(const string& s){ return s.size(); };
|
||||
|
||||
optional<string> null{}, thin{""}, word{"word"};
|
||||
assert (null.map(length) == none);
|
||||
assert (thin.map(length) == 0);
|
||||
assert (word.map(length) == 4);
|
||||
|
||||
Function `flat_map` is similar, but it requires the function to return an
|
||||
`optional<V>` for some type `V`. This `optional<V>` becomes the return type of
|
||||
`flat_map`.
|
||||
|
||||
optional<char> first_char(const string& s) {
|
||||
if (s.empty()) return none;
|
||||
else return s[0];
|
||||
};
|
||||
|
||||
optional<string> null{}, thin{""}, word{"word"};
|
||||
assert (null.flat_map(first_char) == none);
|
||||
assert (thin.flat_map(first_char) == none);
|
||||
assert (word.flat_map(first_char) == 'w');
|
||||
|
||||
These functions can be combined in one expression reflecting a chain of computations:
|
||||
|
||||
auto get_contents(path p) -> optional<string>;
|
||||
auto trim(string) -> string;
|
||||
auto length(string) -> int;
|
||||
|
||||
auto trimmed_size_of(optional<path> p) -> int
|
||||
{
|
||||
return p.flat_map(get_contents)
|
||||
.map(trim)
|
||||
.map(length)
|
||||
.value_or(0);
|
||||
}
|
||||
|
||||
|
||||
[endsect]
|
@ -16,7 +16,7 @@ some operations are not available in this case:
|
||||
* Value-access via pointer
|
||||
|
||||
Also, even though `optional<T&>` treats it wrapped pseudo-object much as
|
||||
a real value, a true real reference is stored so aliasing will ocurr:
|
||||
a real value, a true real reference is stored so aliasing will occur:
|
||||
|
||||
* Copies of `optional<T&>` will copy the references but all these references
|
||||
will nonetheless refer to the same object.
|
@ -80,7 +80,7 @@ you can sometimes get an unexpected runtime result where you would rather expect
|
||||
|
||||
[section False positive with -Wmaybe-uninitialized]
|
||||
|
||||
Sometimes on GCC compilers below version 5.1 you may get an -Wmaybe-uninitialized warning when copiling with option -02 on a perfectly valid `boost::optional` usage. For instance in this program:
|
||||
Sometimes on GCC compilers below version 5.1 you may get an -Wmaybe-uninitialized warning when compiling with option -02 on a perfectly valid `boost::optional` usage. For instance in this program:
|
||||
|
||||
#include <boost/optional.hpp>
|
||||
|
@ -51,7 +51,7 @@ Operation `emplace` provides basic exception safety guarantee. If it throws, the
|
||||
|
||||
Unless `swap` on optional is customized, its primary implementation forwards calls to `T`'s `swap` or move constructor (depending on the initialization state of the optional objects). Thus, if both `T`'s `swap` and move constructor never throw, `swap` on `optional<T>` never throws. similarly, if both `T`'s `swap` and move constructor offer strong guarantee, `swap` on `optional<T>` also offers a strong guarantee.
|
||||
|
||||
In case `swap` on optional is customized, the call to `T`'s move constructor are replaced with the calls to `T`'s default constructor followed by `swap`. (This is more useful on older compilers that do not support move semantics, when one wants to acheive stronger exception safety guarantees.) In this case the exception safety guarantees for `swap` are reliant on the guarantees of `T`'s `swap` and default constructor
|
||||
In case `swap` on optional is customized, the call to `T`'s move constructor are replaced with the calls to `T`'s default constructor followed by `swap`. (This is more useful on older compilers that do not support move semantics, when one wants to achieve stronger exception safety guarantees.) In this case the exception safety guarantees for `swap` are reliant on the guarantees of `T`'s `swap` and default constructor
|
||||
[endsect]
|
||||
|
||||
|
@ -19,7 +19,7 @@ Lifetime of the `T` inside `_storage` is manually controlled with placement-`new
|
||||
T _storage;
|
||||
};
|
||||
|
||||
We call it a ['direct] storage. This makes `optional<T>` a trivially-copyable type for scalar `T`s. This only works for compilers that support defaulted functions (including defaulted move assignment and constructor). On compilers without defaulted functions we still use the direct storage, but `optional<T>` is no longer recognized as trivially-copyable. Apart from scalar types, we leave the programmer a way of customizing her type, so that it is reconized by `optional` as candidate for optimized storage, by specializing type trait `boost::opitonal_config::optional_uses_direct_storage_for`:
|
||||
We call it a ['direct] storage. This makes `optional<T>` a trivially-copyable type for scalar `T`s. This only works for compilers that support defaulted functions (including defaulted move assignment and constructor). On compilers without defaulted functions we still use the direct storage, but `optional<T>` is no longer recognized as trivially-copyable. Apart from scalar types, we leave the programmer a way of customizing her type, so that it is recognized by `optional` as candidate for optimized storage, by specializing type trait `boost::optional_config::optional_uses_direct_storage_for`:
|
||||
|
||||
struct X // not trivial
|
||||
{
|
||||
@ -86,7 +86,7 @@ Which gives us the following layout (and smaller total size):
|
||||
|
||||
[$images/opt_align3.png]
|
||||
|
||||
Sometimes it requires detailed consideration what data we make optional. In our case above, if we determine that both minimum and maximum value can be provided or not provided together, but one is never provided without the other, we can make only one optional memebr:
|
||||
Sometimes it requires detailed consideration what data we make optional. In our case above, if we determine that both minimum and maximum value can be provided or not provided together, but one is never provided without the other, we can make only one optional member:
|
||||
|
||||
struct Limits
|
||||
{
|
@ -102,7 +102,7 @@
|
||||
|
||||
}
|
||||
|
||||
Classes `in_place_init_t` and `in_place_init_if_t` are empty clsses. Their purpose is to control overload resolution in the initialization of optional objects.
|
||||
Classes `in_place_init_t` and `in_place_init_if_t` are empty classes. Their purpose is to control overload resolution in the initialization of optional objects.
|
||||
They are empty, trivially copyable classes with disabled default constructor.
|
||||
|
||||
[endsect]
|
||||
@ -228,7 +228,7 @@ They are empty, trivially copyable classes with disabled default constructor.
|
||||
|
||||
[#reference_operator_template_spec]
|
||||
template <class T>
|
||||
class optional<T&> // specilization for lvalue references
|
||||
class optional<T&> // specialization for lvalue references
|
||||
{
|
||||
public :
|
||||
|
||||
|
@ -163,7 +163,7 @@ assert (!uninit);
|
||||
optional<std::unique_ptr<T>> uinit2 ( std::move(uninit) ) ;
|
||||
assert ( uninit2 == uninit );
|
||||
|
||||
optional<std::unique_ptr<T>> init( std::uniqye_ptr<T>(new T(2)) );
|
||||
optional<std::unique_ptr<T>> init( std::unique_ptr<T>(new T(2)) );
|
||||
assert ( **init == T(2) ) ;
|
||||
|
||||
optional<std::unique_ptr<T>> init2 ( std::move(init) ) ;
|
||||
@ -233,7 +233,7 @@ __SPACE__
|
||||
arguments `std::forward<Args>(args)...`.
|
||||
* [*Postconditions:] `*this` is initialized.
|
||||
* [*Throws:] Any exception thrown by the selected constructor of `T`.
|
||||
* [*Notes: ] `T` need not be __MOVE_CONSTRUCTIBLE__. On compilers that do not suppor variadic templates or rvalue references, this constuctor is available in limited functionality. For details [link optional_emplace_workaround see here].
|
||||
* [*Notes: ] `T` need not be __MOVE_CONSTRUCTIBLE__. On compilers that do not support variadic templates or rvalue references, this constuctor is available in limited functionality. For details [link optional_emplace_workaround see here].
|
||||
|
||||
* [*Example:]
|
||||
``
|
||||
@ -257,7 +257,7 @@ __SPACE__
|
||||
* [*Effect:] If `condition` is `true`, initializes the contained value as if direct-non-list-initializing an object of type `T` with the arguments `std::forward<Args>(args)...`.
|
||||
* [*Postconditions:] `bool(*this) == condition`.
|
||||
* [*Throws:] Any exception thrown by the selected constructor of `T`.
|
||||
* [*Notes: ] `T` need not be __MOVE_CONSTRUCTIBLE__. On compilers that do not suppor variadic templates or rvalue references, this constuctor is available in limited functionality. For details [link optional_emplace_workaround see here].
|
||||
* [*Notes: ] `T` need not be __MOVE_CONSTRUCTIBLE__. On compilers that do not support variadic templates or rvalue references, this constuctor is available in limited functionality. For details [link optional_emplace_workaround see here].
|
||||
|
||||
* [*Example:]
|
||||
``
|
||||
@ -502,7 +502,7 @@ __SPACE__
|
||||
* [*Postconditions: ] `*this` is [_initialized].
|
||||
* [*Throws:] Whatever the selected `T`'s constructor throws.
|
||||
* [*Exception Safety:] If an exception is thrown during the initialization of `T`, `*this` is ['uninitialized].
|
||||
* [*Notes:] `T` need not be __MOVE_CONSTRUCTIBLE__ or `MoveAssignable`. On compilers that do not suppor variadic templates or rvalue references, this function is available in limited functionality. For details [link optional_emplace_workaround see here].
|
||||
* [*Notes:] `T` need not be __MOVE_CONSTRUCTIBLE__ or `MoveAssignable`. On compilers that do not support variadic templates or rvalue references, this function is available in limited functionality. For details [link optional_emplace_workaround see here].
|
||||
* [*Example:]
|
||||
``
|
||||
T v;
|
||||
@ -875,7 +875,7 @@ __SPACE__
|
||||
[: `template<class R> optional<T&>::optional(R&& r) noexcept;`]
|
||||
* [*Postconditions:] `bool(*this) == true`; `addressof(**this) == addressof(r)`.
|
||||
* [*Remarks:] Unless `R` is an lvalue reference, the program is ill-formed. This constructor does not participate in overload resolution if `decay<R>` is an instance of `boost::optional`.
|
||||
* [*Notes:] This constructor is declared `explicit` on compilers that do not correctly suport binding to const lvalues of integral types. For more details [link optional_reference_binding see here].
|
||||
* [*Notes:] This constructor is declared `explicit` on compilers that do not correctly support binding to const lvalues of integral types. For more details [link optional_reference_binding see here].
|
||||
* [*Example:]
|
||||
``
|
||||
T v;
|
||||
@ -1136,21 +1136,21 @@ __SPACE__
|
||||
[#reference_optional_ref_reset_value]
|
||||
[: `template<class R> void optional<T&>::reset ( R&& r) noexcept;`]
|
||||
* [*Effects:] Equivalent to `*this = std::forward<R>(r)`.
|
||||
* [*Remarks:] This function is depprecated.
|
||||
* [*Remarks:] This function is deprecated.
|
||||
|
||||
__SPACE__
|
||||
|
||||
[#reference_optional_ref_is_initialized]
|
||||
[: `bool optional<T&>::is_initialized() const noexcept;`]
|
||||
* [*Effects:] Equivalent to `return bool(*this)`.
|
||||
* [*Remarks:] This function is depprecated.
|
||||
* [*Remarks:] This function is deprecated.
|
||||
|
||||
__SPACE__
|
||||
|
||||
[#reference_optional_ref_get_value_or_value]
|
||||
[: `template<class R> T& optional<T&>::get_value_or( R&& r ) const noexcept;`]
|
||||
* [*Effects:] Equivalent to `return value_or(std::forward<R>(r);`.
|
||||
* [*Remarks:] This function is depprecated.
|
||||
* [*Remarks:] This function is deprecated.
|
||||
|
||||
[endsect]
|
||||
|
||||
@ -1249,7 +1249,7 @@ __SPACE__
|
||||
* [*Returns:] `(!y) ? false : (!x) ? true : *x < *y`.
|
||||
* [*Notes:] This definition guarantees that `optional<T>` not containing a value is ordered as less than any `optional<T>` containing any value, and equivalent to any other `optional<T>` not containing a value.
|
||||
Pointers have shallow relational operators while `optional` has deep relational operators. Do not use `operator<` directly in generic code
|
||||
which expect to be given either an `optional<T>` or a pointer; use __FUNCTION_LESS_POINTEES__ instead. `T` need not be __STD_LESS_THAN_COMPARABLE__. Only single `operator<` is required. Other relational operations are defined in terms of this one. If `T`'s `operator<` satisfies the axioms of __STD_LESS_THAN_COMPARABLE__ (transitivity, antisymmetry and irreflexivity), `optinal<T>` is __STD_LESS_THAN_COMPARABLE__.
|
||||
which expect to be given either an `optional<T>` or a pointer; use __FUNCTION_LESS_POINTEES__ instead. `T` need not be __STD_LESS_THAN_COMPARABLE__. Only single `operator<` is required. Other relational operations are defined in terms of this one. If `T`'s `operator<` satisfies the axioms of __STD_LESS_THAN_COMPARABLE__ (transitivity, antisymmetry and irreflexivity), `optional<T>` is __STD_LESS_THAN_COMPARABLE__.
|
||||
* [*Example:]
|
||||
``
|
||||
optional<T> oN, oN_;
|
||||
@ -1386,7 +1386,7 @@ __SPACE__
|
||||
[#reference_swap_optional_reference]
|
||||
[: `void swap ( optional<T&>& x, optional<T&>& y ) noexcept ;`]
|
||||
|
||||
* [*Postconditions:] `x` refers to what `y` refererred to before the swap (if anything). `y` refers to whatever `x` referred to before the swap.
|
||||
* [*Postconditions:] `x` refers to what `y` referred to before the swap (if anything). `y` refers to whatever `x` referred to before the swap.
|
||||
|
||||
* [*Example:]
|
||||
``
|
||||
|
@ -46,7 +46,7 @@ On compilers that do not support variadic templates, each of these functions is
|
||||
template<class Arg> void emplace(Arg&& arg);
|
||||
void emplace();
|
||||
|
||||
On compilers that do not support rvalue references, each of these functions is substituted with three overloadss: taking `const` and non-`const` lvalue reference, and third forwarding zero arguments. This forms the following set:
|
||||
On compilers that do not support rvalue references, each of these functions is substituted with three overloads: taking `const` and non-`const` lvalue reference, and third forwarding zero arguments. This forms the following set:
|
||||
|
||||
template<class Arg> optional(in_place_init_t, const Arg& arg);
|
||||
template<class Arg> optional(in_place_init_t, Arg& arg);
|
||||
@ -60,12 +60,12 @@ On compilers that do not support rvalue references, each of these functions is s
|
||||
template<class Arg> void emplace(Arg& arg);
|
||||
void emplace();
|
||||
|
||||
This workaround addressess about 40% of all use cases. If this is insufficient, you need to resort to using [link boost_optional.tutorial.in_place_factories In-Place Factories].
|
||||
This workaround addresses about 40% of all use cases. If this is insufficient, you need to resort to using [link boost_optional.tutorial.in_place_factories In-Place Factories].
|
||||
[endsect]
|
||||
|
||||
[section Optional Reference Binding][#optional_reference_binding]
|
||||
|
||||
A number of compilers incorrectly treat const lvalues of integral type as rvalues, and create an illegal temporary when binding to an lvalue reference to const in some expressions. This could result in creating an optional lvalue reference that is in fact bound to an unexpected temporary rather than to the intended object. In order to prevent hard to find run-time bugs, this library performs compile-time checks to prevent expressions that would otherwise bind an optional reference to an unexpected temporary. As a consequence, on certain compilers certain pieces of functionality in optional references are missing. In order to maintain a portability of your code across diferent compilers, it is recommended that you only stick to the minimum portable interface of optional references: prefer direct-initialization and copy assignment of optional references to copy-initialization and assignment from `T&`:
|
||||
A number of compilers incorrectly treat const lvalues of integral type as rvalues, and create an illegal temporary when binding to an lvalue reference to const in some expressions. This could result in creating an optional lvalue reference that is in fact bound to an unexpected temporary rather than to the intended object. In order to prevent hard to find run-time bugs, this library performs compile-time checks to prevent expressions that would otherwise bind an optional reference to an unexpected temporary. As a consequence, on certain compilers certain pieces of functionality in optional references are missing. In order to maintain a portability of your code across different compilers, it is recommended that you only stick to the minimum portable interface of optional references: prefer direct-initialization and copy assignment of optional references to copy-initialization and assignment from `T&`:
|
||||
|
||||
const int i = 0;
|
||||
optional<const int&> or1;
|
||||
|
@ -11,9 +11,13 @@
|
||||
|
||||
[section:relnotes Release Notes]
|
||||
|
||||
[heading Boost Release 1.83]
|
||||
|
||||
* Deprecated support for C++03 and earlier, C++11 will be required in release 1.86.
|
||||
|
||||
[heading Boost Release 1.80]
|
||||
|
||||
* [*Breaking change:] Added specializations for `std::hash<boost::opitonal<T>>`. This fixes [@https://github.com/boostorg/optional/issues/55 issue #55]. You may get compiler errors when your program provides specializations for `std::hash<boost::optional<T>>`. If this happens, define macro `BOOST_OPTIONAL_CONFIG_DO_NOT_SPECIALIZE_STD_HASH` to suppress the specializations of `std::hash` in this library.
|
||||
* [*Breaking change:] Added specializations for `std::hash<boost::optional<T>>`. This fixes [@https://github.com/boostorg/optional/issues/55 issue #55]. You may get compiler errors when your program provides specializations for `std::hash<boost::optional<T>>`. If this happens, define macro `BOOST_OPTIONAL_CONFIG_DO_NOT_SPECIALIZE_STD_HASH` to suppress the specializations of `std::hash` in this library.
|
||||
|
||||
[heading Boost Release 1.79]
|
||||
|
||||
@ -38,7 +42,7 @@
|
||||
* Fixed [@https://github.com/boostorg/optional/issues/78 issue #78].
|
||||
* `boost::none` is now declared as an inline variable (on compilers that 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`.
|
||||
* Now suppressing warning `-Wweak-vtables`.
|
||||
|
||||
[heading Boost Release 1.69]
|
||||
|
||||
@ -50,7 +54,7 @@
|
||||
|
||||
* Added member function `has_value()` for compatibility with `std::optional` ([@https://github.com/boostorg/optional/issues/52 issue #52]).
|
||||
* Added member function `map()` for transforming `optional<T>` into `optional<U>` using a function of type `T -> U`.
|
||||
* Added member function `flat_map()` for transforming `optional<T>` into `optional<U>` using a function of type `T -> optonal<U>`.
|
||||
* Added member function `flat_map()` for transforming `optional<T>` into `optional<U>` using a function of type `T -> optional<U>`.
|
||||
|
||||
|
||||
[heading Boost Release 1.67]
|
||||
@ -82,7 +86,7 @@
|
||||
* the `sizeof` of optional reference is that of a pointer,
|
||||
* some bugs connected to copying optional references are gone,
|
||||
* all run-time bugs caused by incorrect reference binding on some compilers are now turned into compile-time errors,
|
||||
* you can swap optional references: it is like swapping pointers: shalow, underlying objects are not affected,
|
||||
* you can swap optional references: it is like swapping pointers: shallow, underlying objects are not affected,
|
||||
* optional references to abstract types work.
|
||||
* Documented nested typedefs ([@https://svn.boost.org/trac/boost/ticket/5193 Trac #5193]).
|
||||
* Made the perfect-forwarding constructor SFINAE-friendly, which fixes [@https://svn.boost.org/trac/boost/ticket/12002 Trac #12002]. However, this only works in the newer platforms that correctly implement C++11 `<type_traits>`.
|
||||
|
@ -52,7 +52,7 @@
|
||||
</pre>
|
||||
<p>
|
||||
On compilers that do not support rvalue references, each of these functions
|
||||
is substituted with three overloadss: taking <code class="computeroutput"><span class="keyword">const</span></code>
|
||||
is substituted with three overloads: taking <code class="computeroutput"><span class="keyword">const</span></code>
|
||||
and non-<code class="computeroutput"><span class="keyword">const</span></code> lvalue reference,
|
||||
and third forwarding zero arguments. This forms the following set:
|
||||
</p>
|
||||
@ -69,7 +69,7 @@
|
||||
<span class="keyword">void</span> <span class="identifier">emplace</span><span class="special">();</span>
|
||||
</pre>
|
||||
<p>
|
||||
This workaround addressess about 40% of all use cases. If this is insufficient,
|
||||
This workaround addresses about 40% of all use cases. If this is insufficient,
|
||||
you need to resort to using <a class="link" href="../tutorial/in_place_factories.html" title="In-Place Factories">In-Place
|
||||
Factories</a>.
|
||||
</p>
|
||||
|
@ -37,7 +37,7 @@
|
||||
prevent expressions that would otherwise bind an optional reference to an
|
||||
unexpected temporary. As a consequence, on certain compilers certain pieces
|
||||
of functionality in optional references are missing. In order to maintain
|
||||
a portability of your code across diferent compilers, it is recommended that
|
||||
a portability of your code across different compilers, it is recommended that
|
||||
you only stick to the minimum portable interface of optional references:
|
||||
prefer direct-initialization and copy assignment of optional references to
|
||||
copy-initialization and assignment from <code class="computeroutput"><span class="identifier">T</span><span class="special">&</span></code>:
|
||||
|
@ -422,7 +422,7 @@
|
||||
<span class="identifier">optional</span><span class="special"><</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">unique_ptr</span><span class="special"><</span><span class="identifier">T</span><span class="special">>></span> <span class="identifier">uinit2</span> <span class="special">(</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">move</span><span class="special">(</span><span class="identifier">uninit</span><span class="special">)</span> <span class="special">)</span> <span class="special">;</span>
|
||||
<span class="identifier">assert</span> <span class="special">(</span> <span class="identifier">uninit2</span> <span class="special">==</span> <span class="identifier">uninit</span> <span class="special">);</span>
|
||||
|
||||
<span class="identifier">optional</span><span class="special"><</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">unique_ptr</span><span class="special"><</span><span class="identifier">T</span><span class="special">>></span> <span class="identifier">init</span><span class="special">(</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">uniqye_ptr</span><span class="special"><</span><span class="identifier">T</span><span class="special">>(</span><span class="keyword">new</span> <span class="identifier">T</span><span class="special">(</span><span class="number">2</span><span class="special">))</span> <span class="special">);</span>
|
||||
<span class="identifier">optional</span><span class="special"><</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">unique_ptr</span><span class="special"><</span><span class="identifier">T</span><span class="special">>></span> <span class="identifier">init</span><span class="special">(</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">unique_ptr</span><span class="special"><</span><span class="identifier">T</span><span class="special">>(</span><span class="keyword">new</span> <span class="identifier">T</span><span class="special">(</span><span class="number">2</span><span class="special">))</span> <span class="special">);</span>
|
||||
<span class="identifier">assert</span> <span class="special">(</span> <span class="special">**</span><span class="identifier">init</span> <span class="special">==</span> <span class="identifier">T</span><span class="special">(</span><span class="number">2</span><span class="special">)</span> <span class="special">)</span> <span class="special">;</span>
|
||||
|
||||
<span class="identifier">optional</span><span class="special"><</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">unique_ptr</span><span class="special"><</span><span class="identifier">T</span><span class="special">>></span> <span class="identifier">init2</span> <span class="special">(</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">move</span><span class="special">(</span><span class="identifier">init</span><span class="special">)</span> <span class="special">)</span> <span class="special">;</span>
|
||||
|
@ -293,8 +293,8 @@
|
||||
</p>
|
||||
<h5>
|
||||
<a name="boost_optional.development.the_interface.h0"></a>
|
||||
<span class="phrase"><a name="boost_optional.development.the_interface.lexically_hinted_value_access_in_the_presence_of_possibly_untitialized_optional_objects__the_operators___and___gt_"></a></span><a class="link" href="development.html#boost_optional.development.the_interface.lexically_hinted_value_access_in_the_presence_of_possibly_untitialized_optional_objects__the_operators___and___gt_">Lexically-hinted
|
||||
Value Access in the presence of possibly untitialized optional objects: The
|
||||
<span class="phrase"><a name="boost_optional.development.the_interface.lexically_hinted_value_access_in_the_presence_of_possibly_uninitialized_optional_objects__the_operators___and___gt_"></a></span><a class="link" href="development.html#boost_optional.development.the_interface.lexically_hinted_value_access_in_the_presence_of_possibly_uninitialized_optional_objects__the_operators___and___gt_">Lexically-hinted
|
||||
Value Access in the presence of possibly uninitialized optional objects: The
|
||||
operators * and -></a>
|
||||
</h5>
|
||||
<p>
|
||||
|
@ -148,7 +148,7 @@
|
||||
move constructor are replaced with the calls to <code class="computeroutput"><span class="identifier">T</span></code>'s
|
||||
default constructor followed by <code class="computeroutput"><span class="identifier">swap</span></code>.
|
||||
(This is more useful on older compilers that do not support move semantics,
|
||||
when one wants to acheive stronger exception safety guarantees.) In this case
|
||||
when one wants to achieve stronger exception safety guarantees.) In this case
|
||||
the exception safety guarantees for <code class="computeroutput"><span class="identifier">swap</span></code>
|
||||
are reliant on the guarantees of <code class="computeroutput"><span class="identifier">T</span></code>'s
|
||||
<code class="computeroutput"><span class="identifier">swap</span></code> and default constructor
|
||||
|
@ -55,7 +55,7 @@
|
||||
<p>
|
||||
Also, even though <code class="computeroutput"><span class="identifier">optional</span><span class="special"><</span><span class="identifier">T</span><span class="special">&></span></code>
|
||||
treats it wrapped pseudo-object much as a real value, a true real reference
|
||||
is stored so aliasing will ocurr:
|
||||
is stored so aliasing will occur:
|
||||
</p>
|
||||
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
|
||||
<li class="listitem">
|
||||
|
@ -100,7 +100,7 @@
|
||||
<span class="special">}</span>
|
||||
</pre>
|
||||
<p>
|
||||
This version throws an exception upon an attempt to access a non-existent
|
||||
This version throws an exception upon an attempt to access a nonexistent
|
||||
contained value. If your way of dealing with the missing value is to use
|
||||
some default, like <code class="computeroutput"><span class="number">0</span></code>, there exists
|
||||
a yet another alternative:
|
||||
|
@ -44,7 +44,7 @@
|
||||
</pre>
|
||||
<p>
|
||||
The default constructor of <code class="computeroutput"><span class="identifier">optional</span></code>
|
||||
creates an unitialized optional object. Unlike with <code class="computeroutput"><span class="keyword">int</span></code>s
|
||||
creates an uninitialized optional object. Unlike with <code class="computeroutput"><span class="keyword">int</span></code>s
|
||||
you cannot have an <code class="computeroutput"><span class="identifier">optional</span><span class="special"><</span><span class="keyword">int</span><span class="special">></span></code>
|
||||
in an indeterminate state. Its state is always well defined. Instruction
|
||||
<code class="computeroutput"><span class="identifier">ans</span> <span class="special">=</span>
|
||||
|
@ -37,7 +37,7 @@
|
||||
is possible. A natural signature for this function can be:
|
||||
</p>
|
||||
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">optional</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
|
||||
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">optionl</span><span class="special"><</span><span class="keyword">int</span><span class="special">></span> <span class="identifier">convert</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">&</span> <span class="identifier">text</span><span class="special">);</span>
|
||||
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">optional</span><span class="special"><</span><span class="keyword">int</span><span class="special">></span> <span class="identifier">convert</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">&</span> <span class="identifier">text</span><span class="special">);</span>
|
||||
</pre>
|
||||
<p>
|
||||
All necessary functionality can be included with one header <code class="computeroutput"><span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">optional</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code>.
|
||||
@ -49,7 +49,7 @@
|
||||
can use our function:
|
||||
</p>
|
||||
<pre class="programlisting"><span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">&</span> <span class="identifier">text</span> <span class="special">=</span> <span class="comment">/*... */</span><span class="special">;</span>
|
||||
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">optionl</span><span class="special"><</span><span class="keyword">int</span><span class="special">></span> <span class="identifier">oi</span> <span class="special">=</span> <span class="identifier">convert</span><span class="special">(</span><span class="identifier">text</span><span class="special">);</span> <span class="comment">// move-construct</span>
|
||||
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">optional</span><span class="special"><</span><span class="keyword">int</span><span class="special">></span> <span class="identifier">oi</span> <span class="special">=</span> <span class="identifier">convert</span><span class="special">(</span><span class="identifier">text</span><span class="special">);</span> <span class="comment">// move-construct</span>
|
||||
<span class="keyword">if</span> <span class="special">(</span><span class="identifier">oi</span><span class="special">)</span> <span class="comment">// contextual conversion to bool</span>
|
||||
<span class="keyword">int</span> <span class="identifier">i</span> <span class="special">=</span> <span class="special">*</span><span class="identifier">oi</span><span class="special">;</span> <span class="comment">// operator*</span>
|
||||
</pre>
|
||||
@ -58,7 +58,7 @@
|
||||
contains a value, we use the contextual conversion to type <code class="computeroutput"><span class="keyword">bool</span></code>. Because of this we can combine the initialization
|
||||
of the optional object and the test into one instruction:
|
||||
</p>
|
||||
<pre class="programlisting"><span class="keyword">if</span> <span class="special">(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">optionl</span><span class="special"><</span><span class="keyword">int</span><span class="special">></span> <span class="identifier">oi</span> <span class="special">=</span> <span class="identifier">convert</span><span class="special">(</span><span class="identifier">text</span><span class="special">))</span>
|
||||
<pre class="programlisting"><span class="keyword">if</span> <span class="special">(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">optional</span><span class="special"><</span><span class="keyword">int</span><span class="special">></span> <span class="identifier">oi</span> <span class="special">=</span> <span class="identifier">convert</span><span class="special">(</span><span class="identifier">text</span><span class="special">))</span>
|
||||
<span class="keyword">int</span> <span class="identifier">i</span> <span class="special">=</span> <span class="special">*</span><span class="identifier">oi</span><span class="special">;</span>
|
||||
</pre>
|
||||
<p>
|
||||
@ -84,7 +84,7 @@
|
||||
<span class="special">}</span>
|
||||
</pre>
|
||||
<p>
|
||||
This version throws an exception upon an attempt to access a non-existent
|
||||
This version throws an exception upon an attempt to access a nonexistent
|
||||
contained value. If your way of dealing with the missing value is to use
|
||||
some default, like <code class="computeroutput"><span class="number">0</span></code>, there exists
|
||||
a yet another alternative:
|
||||
@ -98,7 +98,7 @@
|
||||
Now, let's consider how function <code class="computeroutput"><span class="identifier">convert</span></code>
|
||||
can be implemented.
|
||||
</p>
|
||||
<pre class="programlisting"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">optionl</span><span class="special"><</span><span class="keyword">int</span><span class="special">></span> <span class="identifier">convert</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">&</span> <span class="identifier">text</span><span class="special">)</span>
|
||||
<pre class="programlisting"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">optional</span><span class="special"><</span><span class="keyword">int</span><span class="special">></span> <span class="identifier">convert</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">&</span> <span class="identifier">text</span><span class="special">)</span>
|
||||
<span class="special">{</span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">stringstream</span> <span class="identifier">s</span><span class="special">(</span><span class="identifier">text</span><span class="special">);</span>
|
||||
<span class="keyword">int</span> <span class="identifier">i</span><span class="special">;</span>
|
||||
|
@ -433,7 +433,7 @@
|
||||
<span class="identifier">optional</span><span class="special"><</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">unique_ptr</span><span class="special"><</span><span class="identifier">T</span><span class="special">>></span> <span class="identifier">uinit2</span> <span class="special">(</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">move</span><span class="special">(</span><span class="identifier">uninit</span><span class="special">)</span> <span class="special">)</span> <span class="special">;</span>
|
||||
<span class="identifier">assert</span> <span class="special">(</span> <span class="identifier">uninit2</span> <span class="special">==</span> <span class="identifier">uninit</span> <span class="special">);</span>
|
||||
|
||||
<span class="identifier">optional</span><span class="special"><</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">unique_ptr</span><span class="special"><</span><span class="identifier">T</span><span class="special">>></span> <span class="identifier">init</span><span class="special">(</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">uniqye_ptr</span><span class="special"><</span><span class="identifier">T</span><span class="special">>(</span><span class="keyword">new</span> <span class="identifier">T</span><span class="special">(</span><span class="number">2</span><span class="special">))</span> <span class="special">);</span>
|
||||
<span class="identifier">optional</span><span class="special"><</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">unique_ptr</span><span class="special"><</span><span class="identifier">T</span><span class="special">>></span> <span class="identifier">init</span><span class="special">(</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">unique_ptr</span><span class="special"><</span><span class="identifier">T</span><span class="special">>(</span><span class="keyword">new</span> <span class="identifier">T</span><span class="special">(</span><span class="number">2</span><span class="special">))</span> <span class="special">);</span>
|
||||
<span class="identifier">assert</span> <span class="special">(</span> <span class="special">**</span><span class="identifier">init</span> <span class="special">==</span> <span class="identifier">T</span><span class="special">(</span><span class="number">2</span><span class="special">)</span> <span class="special">)</span> <span class="special">;</span>
|
||||
|
||||
<span class="identifier">optional</span><span class="special"><</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">unique_ptr</span><span class="special"><</span><span class="identifier">T</span><span class="special">>></span> <span class="identifier">init2</span> <span class="special">(</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">move</span><span class="special">(</span><span class="identifier">init</span><span class="special">)</span> <span class="special">)</span> <span class="special">;</span>
|
||||
@ -2129,7 +2129,7 @@
|
||||
is required. Other relational operations are defined in terms of this
|
||||
one. If <code class="computeroutput"><span class="identifier">T</span></code>'s <code class="computeroutput"><span class="keyword">operator</span><span class="special"><</span></code>
|
||||
satisfies the axioms of <a href="http://www.sgi.com/tech/stl/LessThanComparable.html" target="_top"><code class="computeroutput"><span class="identifier">LessThanComparable</span></code></a> (transitivity,
|
||||
antisymmetry and irreflexivity), <code class="computeroutput"><span class="identifier">optinal</span><span class="special"><</span><span class="identifier">T</span><span class="special">></span></code> is <a href="http://www.sgi.com/tech/stl/LessThanComparable.html" target="_top"><code class="computeroutput"><span class="identifier">LessThanComparable</span></code></a>.
|
||||
antisymmetry and irreflexivity), <code class="computeroutput"><span class="identifier">optional</span><span class="special"><</span><span class="identifier">T</span><span class="special">></span></code> is <a href="http://www.sgi.com/tech/stl/LessThanComparable.html" target="_top"><code class="computeroutput"><span class="identifier">LessThanComparable</span></code></a>.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
<span class="bold"><strong>Example:</strong></span>
|
||||
@ -2380,7 +2380,7 @@
|
||||
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
|
||||
<li class="listitem">
|
||||
<span class="bold"><strong>Postconditions:</strong></span> <code class="computeroutput"><span class="identifier">x</span></code>
|
||||
refers to what <code class="computeroutput"><span class="identifier">y</span></code> refererred
|
||||
refers to what <code class="computeroutput"><span class="identifier">y</span></code> referred
|
||||
to before the swap (if anything). <code class="computeroutput"><span class="identifier">y</span></code>
|
||||
refers to whatever <code class="computeroutput"><span class="identifier">x</span></code>
|
||||
referred to before the swap.
|
||||
|
@ -153,7 +153,7 @@
|
||||
is required. Other relational operations are defined in terms of this
|
||||
one. If <code class="computeroutput"><span class="identifier">T</span></code>'s <code class="computeroutput"><span class="keyword">operator</span><span class="special"><</span></code>
|
||||
satisfies the axioms of <a href="http://www.sgi.com/tech/stl/LessThanComparable.html" target="_top"><code class="computeroutput"><span class="identifier">LessThanComparable</span></code></a> (transitivity,
|
||||
antisymmetry and irreflexivity), <code class="computeroutput"><span class="identifier">optinal</span><span class="special"><</span><span class="identifier">T</span><span class="special">></span></code> is <a href="http://www.sgi.com/tech/stl/LessThanComparable.html" target="_top"><code class="computeroutput"><span class="identifier">LessThanComparable</span></code></a>.
|
||||
antisymmetry and irreflexivity), <code class="computeroutput"><span class="identifier">optional</span><span class="special"><</span><span class="identifier">T</span><span class="special">></span></code> is <a href="http://www.sgi.com/tech/stl/LessThanComparable.html" target="_top"><code class="computeroutput"><span class="identifier">LessThanComparable</span></code></a>.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
<span class="bold"><strong>Example:</strong></span>
|
||||
@ -404,7 +404,7 @@
|
||||
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
|
||||
<li class="listitem">
|
||||
<span class="bold"><strong>Postconditions:</strong></span> <code class="computeroutput"><span class="identifier">x</span></code>
|
||||
refers to what <code class="computeroutput"><span class="identifier">y</span></code> refererred
|
||||
refers to what <code class="computeroutput"><span class="identifier">y</span></code> referred
|
||||
to before the swap (if anything). <code class="computeroutput"><span class="identifier">y</span></code>
|
||||
refers to whatever <code class="computeroutput"><span class="identifier">x</span></code>
|
||||
referred to before the swap.
|
||||
|
@ -403,7 +403,7 @@
|
||||
<span class="identifier">optional</span><span class="special"><</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">unique_ptr</span><span class="special"><</span><span class="identifier">T</span><span class="special">>></span> <span class="identifier">uinit2</span> <span class="special">(</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">move</span><span class="special">(</span><span class="identifier">uninit</span><span class="special">)</span> <span class="special">)</span> <span class="special">;</span>
|
||||
<span class="identifier">assert</span> <span class="special">(</span> <span class="identifier">uninit2</span> <span class="special">==</span> <span class="identifier">uninit</span> <span class="special">);</span>
|
||||
|
||||
<span class="identifier">optional</span><span class="special"><</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">unique_ptr</span><span class="special"><</span><span class="identifier">T</span><span class="special">>></span> <span class="identifier">init</span><span class="special">(</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">uniqye_ptr</span><span class="special"><</span><span class="identifier">T</span><span class="special">>(</span><span class="keyword">new</span> <span class="identifier">T</span><span class="special">(</span><span class="number">2</span><span class="special">))</span> <span class="special">);</span>
|
||||
<span class="identifier">optional</span><span class="special"><</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">unique_ptr</span><span class="special"><</span><span class="identifier">T</span><span class="special">>></span> <span class="identifier">init</span><span class="special">(</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">unique_ptr</span><span class="special"><</span><span class="identifier">T</span><span class="special">>(</span><span class="keyword">new</span> <span class="identifier">T</span><span class="special">(</span><span class="number">2</span><span class="special">))</span> <span class="special">);</span>
|
||||
<span class="identifier">assert</span> <span class="special">(</span> <span class="special">**</span><span class="identifier">init</span> <span class="special">==</span> <span class="identifier">T</span><span class="special">(</span><span class="number">2</span><span class="special">)</span> <span class="special">)</span> <span class="special">;</span>
|
||||
|
||||
<span class="identifier">optional</span><span class="special"><</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">unique_ptr</span><span class="special"><</span><span class="identifier">T</span><span class="special">>></span> <span class="identifier">init2</span> <span class="special">(</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">move</span><span class="special">(</span><span class="identifier">init</span><span class="special">)</span> <span class="special">)</span> <span class="special">;</span>
|
||||
|
@ -179,7 +179,7 @@
|
||||
is required. Other relational operations are defined in terms of this
|
||||
one. If <code class="computeroutput"><span class="identifier">T</span></code>'s <code class="computeroutput"><span class="keyword">operator</span><span class="special"><</span></code>
|
||||
satisfies the axioms of <a href="http://www.sgi.com/tech/stl/LessThanComparable.html" target="_top"><code class="computeroutput"><span class="identifier">LessThanComparable</span></code></a> (transitivity,
|
||||
antisymmetry and irreflexivity), <code class="computeroutput"><span class="identifier">optinal</span><span class="special"><</span><span class="identifier">T</span><span class="special">></span></code> is <a href="http://www.sgi.com/tech/stl/LessThanComparable.html" target="_top"><code class="computeroutput"><span class="identifier">LessThanComparable</span></code></a>.
|
||||
antisymmetry and irreflexivity), <code class="computeroutput"><span class="identifier">optional</span><span class="special"><</span><span class="identifier">T</span><span class="special">></span></code> is <a href="http://www.sgi.com/tech/stl/LessThanComparable.html" target="_top"><code class="computeroutput"><span class="identifier">LessThanComparable</span></code></a>.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
<span class="bold"><strong>Example:</strong></span>
|
||||
@ -479,7 +479,7 @@
|
||||
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
|
||||
<li class="listitem">
|
||||
<span class="bold"><strong>Postconditions:</strong></span> <code class="computeroutput"><span class="identifier">x</span></code>
|
||||
refers to what <code class="computeroutput"><span class="identifier">y</span></code> refererred
|
||||
refers to what <code class="computeroutput"><span class="identifier">y</span></code> referred
|
||||
to before the swap (if anything). <code class="computeroutput"><span class="identifier">y</span></code>
|
||||
refers to whatever <code class="computeroutput"><span class="identifier">x</span></code>
|
||||
referred to before the swap.
|
||||
|
@ -58,7 +58,7 @@
|
||||
<li class="listitem">
|
||||
<span class="bold"><strong>Notes:</strong></span> This constructor is declared
|
||||
<code class="computeroutput"><span class="keyword">explicit</span></code> on compilers
|
||||
that do not correctly suport binding to const lvalues of integral types.
|
||||
that do not correctly support binding to const lvalues of integral types.
|
||||
For more details <a class="link" href="../../dependencies_and_portability/optional_reference_binding.html#optional_reference_binding">see here</a>.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
@ -502,7 +502,7 @@
|
||||
<span class="bold"><strong>Effects:</strong></span> Equivalent to <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span> <span class="special">=</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">forward</span><span class="special"><</span><span class="identifier">R</span><span class="special">>(</span><span class="identifier">r</span><span class="special">)</span></code>.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
<span class="bold"><strong>Remarks:</strong></span> This function is depprecated.
|
||||
<span class="bold"><strong>Remarks:</strong></span> This function is deprecated.
|
||||
</li>
|
||||
</ul></div>
|
||||
<p>
|
||||
@ -516,7 +516,7 @@
|
||||
<span class="bold"><strong>Effects:</strong></span> Equivalent to <code class="computeroutput"><span class="keyword">return</span> <span class="keyword">bool</span><span class="special">(*</span><span class="keyword">this</span><span class="special">)</span></code>.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
<span class="bold"><strong>Remarks:</strong></span> This function is depprecated.
|
||||
<span class="bold"><strong>Remarks:</strong></span> This function is deprecated.
|
||||
</li>
|
||||
</ul></div>
|
||||
<p>
|
||||
@ -532,7 +532,7 @@
|
||||
<span class="bold"><strong>Effects:</strong></span> Equivalent to <code class="computeroutput"><span class="keyword">return</span> <span class="identifier">value_or</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">forward</span><span class="special"><</span><span class="identifier">R</span><span class="special">>(</span><span class="identifier">r</span><span class="special">);</span></code>.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
<span class="bold"><strong>Remarks:</strong></span> This function is depprecated.
|
||||
<span class="bold"><strong>Remarks:</strong></span> This function is deprecated.
|
||||
</li>
|
||||
</ul></div>
|
||||
</div>
|
||||
|
@ -301,7 +301,7 @@
|
||||
<span class="identifier">optional</span><span class="special"><</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">unique_ptr</span><span class="special"><</span><span class="identifier">T</span><span class="special">>></span> <span class="identifier">uinit2</span> <span class="special">(</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">move</span><span class="special">(</span><span class="identifier">uninit</span><span class="special">)</span> <span class="special">)</span> <span class="special">;</span>
|
||||
<span class="identifier">assert</span> <span class="special">(</span> <span class="identifier">uninit2</span> <span class="special">==</span> <span class="identifier">uninit</span> <span class="special">);</span>
|
||||
|
||||
<span class="identifier">optional</span><span class="special"><</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">unique_ptr</span><span class="special"><</span><span class="identifier">T</span><span class="special">>></span> <span class="identifier">init</span><span class="special">(</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">uniqye_ptr</span><span class="special"><</span><span class="identifier">T</span><span class="special">>(</span><span class="keyword">new</span> <span class="identifier">T</span><span class="special">(</span><span class="number">2</span><span class="special">))</span> <span class="special">);</span>
|
||||
<span class="identifier">optional</span><span class="special"><</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">unique_ptr</span><span class="special"><</span><span class="identifier">T</span><span class="special">>></span> <span class="identifier">init</span><span class="special">(</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">unique_ptr</span><span class="special"><</span><span class="identifier">T</span><span class="special">>(</span><span class="keyword">new</span> <span class="identifier">T</span><span class="special">(</span><span class="number">2</span><span class="special">))</span> <span class="special">);</span>
|
||||
<span class="identifier">assert</span> <span class="special">(</span> <span class="special">**</span><span class="identifier">init</span> <span class="special">==</span> <span class="identifier">T</span><span class="special">(</span><span class="number">2</span><span class="special">)</span> <span class="special">)</span> <span class="special">;</span>
|
||||
|
||||
<span class="identifier">optional</span><span class="special"><</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">unique_ptr</span><span class="special"><</span><span class="identifier">T</span><span class="special">>></span> <span class="identifier">init2</span> <span class="special">(</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">move</span><span class="special">(</span><span class="identifier">init</span><span class="special">)</span> <span class="special">)</span> <span class="special">;</span>
|
||||
@ -429,7 +429,7 @@
|
||||
<li class="listitem">
|
||||
<span class="bold"><strong>Notes: </strong></span> <code class="computeroutput"><span class="identifier">T</span></code>
|
||||
need not be <code class="computeroutput"><span class="identifier">MoveConstructible</span></code>.
|
||||
On compilers that do not suppor variadic templates or rvalue references,
|
||||
On compilers that do not support variadic templates or rvalue references,
|
||||
this constuctor is available in limited functionality. For details
|
||||
<a class="link" href="../../dependencies_and_portability/emplace_operations_in_older_compilers.html#optional_emplace_workaround">see here</a>.
|
||||
</li>
|
||||
@ -476,7 +476,7 @@
|
||||
<li class="listitem">
|
||||
<span class="bold"><strong>Notes: </strong></span> <code class="computeroutput"><span class="identifier">T</span></code>
|
||||
need not be <code class="computeroutput"><span class="identifier">MoveConstructible</span></code>.
|
||||
On compilers that do not suppor variadic templates or rvalue references,
|
||||
On compilers that do not support variadic templates or rvalue references,
|
||||
this constuctor is available in limited functionality. For details
|
||||
<a class="link" href="../../dependencies_and_portability/emplace_operations_in_older_compilers.html#optional_emplace_workaround">see here</a>.
|
||||
</li>
|
||||
@ -1125,7 +1125,7 @@
|
||||
<span class="bold"><strong>Notes:</strong></span> <code class="computeroutput"><span class="identifier">T</span></code>
|
||||
need not be <code class="computeroutput"><span class="identifier">MoveConstructible</span></code>
|
||||
or <code class="computeroutput"><span class="identifier">MoveAssignable</span></code>.
|
||||
On compilers that do not suppor variadic templates or rvalue references,
|
||||
On compilers that do not support variadic templates or rvalue references,
|
||||
this function is available in limited functionality. For details <a class="link" href="../../dependencies_and_portability/emplace_operations_in_older_compilers.html#optional_emplace_workaround">see here</a>.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
|
@ -40,7 +40,7 @@
|
||||
<p>
|
||||
Classes <code class="computeroutput"><span class="identifier">in_place_init_t</span></code>
|
||||
and <code class="computeroutput"><span class="identifier">in_place_init_if_t</span></code>
|
||||
are empty clsses. Their purpose is to control overload resolution in the
|
||||
are empty classes. Their purpose is to control overload resolution in the
|
||||
initialization of optional objects. They are empty, trivially copyable
|
||||
classes with disabled default constructor.
|
||||
</p>
|
||||
|
@ -28,7 +28,7 @@
|
||||
References</a>
|
||||
</h4></div></div></div>
|
||||
<a name="reference_operator_template_spec"></a><pre class="programlisting"><span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">></span>
|
||||
<span class="keyword">class</span> <span class="identifier">optional</span><span class="special"><</span><span class="identifier">T</span><span class="special">&></span> <span class="comment">// specilization for lvalue references</span>
|
||||
<span class="keyword">class</span> <span class="identifier">optional</span><span class="special"><</span><span class="identifier">T</span><span class="special">&></span> <span class="comment">// specialization for lvalue references</span>
|
||||
<span class="special">{</span>
|
||||
<span class="keyword">public</span> <span class="special">:</span>
|
||||
|
||||
|
@ -96,7 +96,7 @@
|
||||
#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>.
|
||||
Now suppressing 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>
|
||||
@ -131,7 +131,7 @@
|
||||
Added member function <code class="computeroutput"><span class="identifier">map</span><span class="special">()</span></code> for transforming <code class="computeroutput"><span class="identifier">optional</span><span class="special"><</span><span class="identifier">T</span><span class="special">></span></code> into <code class="computeroutput"><span class="identifier">optional</span><span class="special"><</span><span class="identifier">U</span><span class="special">></span></code> using a function of type <code class="computeroutput"><span class="identifier">T</span> <span class="special">-></span> <span class="identifier">U</span></code>.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
Added member function <code class="computeroutput"><span class="identifier">flat_map</span><span class="special">()</span></code> for transforming <code class="computeroutput"><span class="identifier">optional</span><span class="special"><</span><span class="identifier">T</span><span class="special">></span></code> into <code class="computeroutput"><span class="identifier">optional</span><span class="special"><</span><span class="identifier">U</span><span class="special">></span></code> using a function of type <code class="computeroutput"><span class="identifier">T</span> <span class="special">-></span> <span class="identifier">optonal</span><span class="special"><</span><span class="identifier">U</span><span class="special">></span></code>.
|
||||
Added member function <code class="computeroutput"><span class="identifier">flat_map</span><span class="special">()</span></code> for transforming <code class="computeroutput"><span class="identifier">optional</span><span class="special"><</span><span class="identifier">T</span><span class="special">></span></code> into <code class="computeroutput"><span class="identifier">optional</span><span class="special"><</span><span class="identifier">U</span><span class="special">></span></code> using a function of type <code class="computeroutput"><span class="identifier">T</span> <span class="special">-></span> <span class="identifier">optional</span><span class="special"><</span><span class="identifier">U</span><span class="special">></span></code>.
|
||||
</li>
|
||||
</ul></div>
|
||||
<h4>
|
||||
@ -220,7 +220,7 @@
|
||||
are now turned into compile-time errors,
|
||||
</li>
|
||||
<li class="listitem">
|
||||
you can swap optional references: it is like swapping pointers: shalow,
|
||||
you can swap optional references: it is like swapping pointers: shallow,
|
||||
underlying objects are not affected,
|
||||
</li>
|
||||
<li class="listitem">
|
||||
|
@ -398,8 +398,8 @@
|
||||
</p>
|
||||
<h6>
|
||||
<a name="boost_optional.tutorial.design_overview.the_interface.h0"></a>
|
||||
<span class="phrase"><a name="boost_optional.tutorial.design_overview.the_interface.lexically_hinted_value_access_in_the_presence_of_possibly_untitialized_optional_objects__the_operators___and___gt_"></a></span><a class="link" href="tutorial.html#boost_optional.tutorial.design_overview.the_interface.lexically_hinted_value_access_in_the_presence_of_possibly_untitialized_optional_objects__the_operators___and___gt_">Lexically-hinted
|
||||
Value Access in the presence of possibly untitialized optional objects:
|
||||
<span class="phrase"><a name="boost_optional.tutorial.design_overview.the_interface.lexically_hinted_value_access_in_the_presence_of_possibly_uninitialized_optional_objects__the_operators___and___gt_"></a></span><a class="link" href="tutorial.html#boost_optional.tutorial.design_overview.the_interface.lexically_hinted_value_access_in_the_presence_of_possibly_uninitialized_optional_objects__the_operators___and___gt_">Lexically-hinted
|
||||
Value Access in the presence of possibly uninitialized optional objects:
|
||||
The operators * and -></a>
|
||||
</h6>
|
||||
<p>
|
||||
|
@ -153,7 +153,7 @@
|
||||
move constructor are replaced with the calls to <code class="computeroutput"><span class="identifier">T</span></code>'s
|
||||
default constructor followed by <code class="computeroutput"><span class="identifier">swap</span></code>.
|
||||
(This is more useful on older compilers that do not support move semantics,
|
||||
when one wants to acheive stronger exception safety guarantees.) In this
|
||||
when one wants to achieve stronger exception safety guarantees.) In this
|
||||
case the exception safety guarantees for <code class="computeroutput"><span class="identifier">swap</span></code>
|
||||
are reliant on the guarantees of <code class="computeroutput"><span class="identifier">T</span></code>'s
|
||||
<code class="computeroutput"><span class="identifier">swap</span></code> and default constructor
|
||||
|
@ -29,7 +29,7 @@
|
||||
</h4></div></div></div>
|
||||
<p>
|
||||
Sometimes on GCC compilers below version 5.1 you may get an -Wmaybe-uninitialized
|
||||
warning when copiling with option -02 on a perfectly valid <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">optional</span></code> usage. For instance in this
|
||||
warning when compiling with option -02 on a perfectly valid <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">optional</span></code> usage. For instance in this
|
||||
program:
|
||||
</p>
|
||||
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">optional</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
|
||||
|
@ -59,7 +59,7 @@
|
||||
<p>
|
||||
Also, even though <code class="computeroutput"><span class="identifier">optional</span><span class="special"><</span><span class="identifier">T</span><span class="special">&></span></code> treats it wrapped pseudo-object
|
||||
much as a real value, a true real reference is stored so aliasing will
|
||||
ocurr:
|
||||
occur:
|
||||
</p>
|
||||
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
|
||||
<li class="listitem">
|
||||
|
@ -60,9 +60,9 @@
|
||||
defaulted move assignment and constructor). On compilers without defaulted
|
||||
functions we still use the direct storage, but <code class="computeroutput"><span class="identifier">optional</span><span class="special"><</span><span class="identifier">T</span><span class="special">></span></code>
|
||||
is no longer recognized as trivially-copyable. Apart from scalar types, we
|
||||
leave the programmer a way of customizing her type, so that it is reconized
|
||||
leave the programmer a way of customizing her type, so that it is recognized
|
||||
by <code class="computeroutput"><span class="identifier">optional</span></code> as candidate
|
||||
for optimized storage, by specializing type trait <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">opitonal_config</span><span class="special">::</span><span class="identifier">optional_uses_direct_storage_for</span></code>:
|
||||
for optimized storage, by specializing type trait <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">optional_config</span><span class="special">::</span><span class="identifier">optional_uses_direct_storage_for</span></code>:
|
||||
</p>
|
||||
<pre class="programlisting"><span class="keyword">struct</span> <span class="identifier">X</span> <span class="comment">// not trivial</span>
|
||||
<span class="special">{</span>
|
||||
@ -165,7 +165,7 @@
|
||||
Sometimes it requires detailed consideration what data we make optional.
|
||||
In our case above, if we determine that both minimum and maximum value can
|
||||
be provided or not provided together, but one is never provided without the
|
||||
other, we can make only one optional memebr:
|
||||
other, we can make only one optional member:
|
||||
</p>
|
||||
<pre class="programlisting"><span class="keyword">struct</span> <span class="identifier">Limits</span>
|
||||
<span class="special">{</span>
|
||||
|
@ -51,7 +51,7 @@
|
||||
of the mixed comparison between <code class="computeroutput"><span class="identifier">T</span></code>
|
||||
and <code class="computeroutput"><span class="identifier">optional</span><span class="special"><</span><span class="identifier">T</span><span class="special">></span></code> as
|
||||
well as between <code class="computeroutput"><span class="identifier">none_t</span></code> and
|
||||
<code class="computeroutput"><span class="identifier">optionl</span><span class="special"><</span><span class="identifier">T</span><span class="special">></span></code>:
|
||||
<code class="computeroutput"><span class="identifier">optional</span><span class="special"><</span><span class="identifier">T</span><span class="special">></span></code>:
|
||||
</p>
|
||||
<pre class="programlisting"><span class="identifier">assert</span><span class="special">(</span><span class="identifier">oN</span> <span class="special">!=</span> <span class="number">0</span><span class="special">);</span>
|
||||
<span class="identifier">assert</span><span class="special">(</span><span class="identifier">o1</span> <span class="special">!=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">none</span><span class="special">);</span>
|
||||
|
@ -114,7 +114,7 @@
|
||||
<span class="phrase"><a name="optional.introduction.problem"></a></span><a class="link" href="index.html#optional.introduction.problem">Problem</a>
|
||||
</h4>
|
||||
<p>
|
||||
Suppose we want to read a parameter form a config file which represents some
|
||||
Suppose we want to read a parameter from a config file which represents some
|
||||
integral value, let's call it <code class="computeroutput"><span class="string">"MaxValue"</span></code>.
|
||||
It is possible that this parameter is not specified; such situation is no error.
|
||||
It is valid to not specify the parameter and in that case the program is supposed
|
||||
|
@ -14,6 +14,14 @@
|
||||
#define BOOST_NONE_T_17SEP2003_HPP
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
|
||||
#if defined (BOOST_NO_CXX11_RVALUE_REFERENCES) || defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_NO_CXX11_REF_QUALIFIERS) \
|
||||
|| defined(BOOST_NO_CXX11_LAMBDAS) || defined(BOOST_NO_CXX11_DECLTYPE_N3276) || defined(BOOST_NO_CXX11_NOEXCEPT) || defined(BOOST_NO_CXX11_DELETED_FUNCTIONS) || defined(BOOST_NO_CXX11_DEFAULTED_FUNCTIONS) || defined(BOOST_NO_CXX11_DEFAULTED_MOVES) || defined(BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS)
|
||||
|
||||
BOOST_PRAGMA_MESSAGE("C++03 support is deprecated in Boost.Optional 1.83 and will be removed in Boost.Optional 1.86.")
|
||||
|
||||
#endif
|
||||
|
||||
namespace boost {
|
||||
|
||||
|
@ -17,6 +17,7 @@
|
||||
#include <boost/type_traits/is_reference.hpp>
|
||||
#include <boost/type_traits/integral_constant.hpp>
|
||||
#include <boost/type_traits/conditional.hpp>
|
||||
#include <boost/core/invoke_swap.hpp>
|
||||
|
||||
namespace boost {
|
||||
|
||||
@ -336,7 +337,7 @@ class optional_base : public optional_tag
|
||||
// No-throw (assuming T::~T() doesn't)
|
||||
void reset() BOOST_NOEXCEPT { destroy(); }
|
||||
|
||||
// **DEPPRECATED** Replaces the current value -if any- with 'val'
|
||||
// **DEPRECATED** Replaces the current value -if any- with 'val'
|
||||
void reset ( argument_type val ) { assign(val); }
|
||||
|
||||
// Returns a pointer to the value if this is initialized, otherwise,
|
||||
@ -542,7 +543,7 @@ class optional_base : public optional_tag
|
||||
// Thus, the following overload is needed to properly handle the case when the 'lhs'
|
||||
// is another optional.
|
||||
//
|
||||
// For VC<=70 compilers this workaround dosen't work becasue the comnpiler issues and error
|
||||
// For VC<=70 compilers this workaround doesn't work because the compiler issues and error
|
||||
// instead of choosing the wrong overload
|
||||
//
|
||||
#ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES
|
||||
@ -629,7 +630,7 @@ class optional_base : public optional_tag
|
||||
|
||||
// If T is of reference type, trying to get a pointer to the held value must result in a compile-time error.
|
||||
// Decent compilers should disallow conversions from reference_content<T>* to T*, but just in case,
|
||||
// the following olverloads are used to filter out the case and guarantee an error in case of T being a reference.
|
||||
// the following overloads are used to filter out the case and guarantee an error in case of T being a reference.
|
||||
pointer_const_type cast_ptr( internal_type const* p, is_not_reference_tag ) const { return p ; }
|
||||
pointer_type cast_ptr( internal_type * p, is_not_reference_tag ) { return p ; }
|
||||
pointer_const_type cast_ptr( internal_type const* p, is_reference_tag ) const { return &p->get() ; }
|
||||
@ -894,7 +895,7 @@ class optional : public optional_detail::optional_base<T>
|
||||
BOOST_NOEXCEPT_IF(::boost::is_nothrow_move_constructible<T>::value && ::boost::is_nothrow_move_assignable<T>::value)
|
||||
{
|
||||
// allow for Koenig lookup
|
||||
boost::swap(*this, arg);
|
||||
boost::core::invoke_swap(*this, arg);
|
||||
}
|
||||
|
||||
|
||||
|
@ -53,7 +53,7 @@
|
||||
#endif
|
||||
|
||||
#if (defined(_MSC_VER) && _MSC_VER <= 1800)
|
||||
// on MSCV 2013 and earlier an unwanted temporary is created when you assign from
|
||||
// on MSVC 2013 and earlier an unwanted temporary is created when you assign from
|
||||
// a const lvalue of integral type. Thus we bind not to the original address but
|
||||
// to a temporary.
|
||||
# define BOOST_OPTIONAL_CONFIG_NO_PROPER_ASSIGN_FROM_CONST_INT
|
||||
@ -114,9 +114,9 @@
|
||||
#endif
|
||||
|
||||
|
||||
// Detect suport for defaulting move operations
|
||||
// Detect support for defaulting move operations
|
||||
// (some older compilers implement rvalue references,
|
||||
// defaulted funcitons but move operations are not special members and cannot be defaulted)
|
||||
// defaulted functions but move operations are not special members and cannot be defaulted)
|
||||
|
||||
#ifdef BOOST_NO_CXX11_DEFAULTED_FUNCTIONS
|
||||
# define BOOST_OPTIONAL_DETAIL_NO_DEFAULTED_MOVE_FUNCTIONS
|
||||
|
@ -66,7 +66,7 @@ void prevent_assignment_from_false_const_integral()
|
||||
{
|
||||
#ifndef BOOST_OPTIONAL_CONFIG_ALLOW_BINDING_TO_RVALUES
|
||||
#ifdef BOOST_OPTIONAL_CONFIG_NO_PROPER_ASSIGN_FROM_CONST_INT
|
||||
// MSVC compiler without rvalue refernces: we need to disable the asignment from
|
||||
// MSVC compiler without rvalue references: we need to disable the assignment from
|
||||
// const integral lvalue reference, as it may be an invalid temporary
|
||||
BOOST_STATIC_ASSERT_MSG(!is_const_integral<From>::value,
|
||||
"binding const lvalue references to integral types is disabled in this compiler");
|
||||
@ -130,7 +130,7 @@ public:
|
||||
explicit optional(const optional<U&>& rhs) BOOST_NOEXCEPT : ptr_(rhs.get_ptr()) {}
|
||||
optional(const optional& rhs) BOOST_NOEXCEPT : ptr_(rhs.get_ptr()) {}
|
||||
|
||||
// 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 screwed conversion construction from const int
|
||||
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, bool>::type = true) BOOST_NOEXCEPT
|
||||
: ptr_(boost::addressof(rhs)) {}
|
||||
|
@ -16,7 +16,7 @@
|
||||
namespace boost {
|
||||
|
||||
// optional's relational operators ( ==, !=, <, >, <=, >= ) have deep-semantics (compare values).
|
||||
// WARNING: This is UNLIKE pointers. Use equal_pointees()/less_pointess() in generic code instead.
|
||||
// WARNING: This is UNLIKE pointers. Use equal_pointees()/less_pointees() in generic code instead.
|
||||
|
||||
|
||||
//
|
||||
|
@ -13,7 +13,7 @@
|
||||
#ifndef BOOST_OPTIONAL_DETAIL_OPTIONAL_SWAP_AJK_28JAN2015_HPP
|
||||
#define BOOST_OPTIONAL_DETAIL_OPTIONAL_SWAP_AJK_28JAN2015_HPP
|
||||
|
||||
#include <boost/core/swap.hpp>
|
||||
#include <boost/core/invoke_swap.hpp>
|
||||
#include <boost/optional/optional_fwd.hpp>
|
||||
|
||||
namespace boost {
|
||||
@ -39,8 +39,8 @@ struct swap_selector<true>
|
||||
else if ( !hasY )
|
||||
y.emplace();
|
||||
|
||||
// Boost.Utility.Swap will take care of ADL and workarounds for broken compilers
|
||||
boost::swap(x.get(), y.get());
|
||||
// Boost.Core.Swap will take care of ADL and workarounds for broken compilers
|
||||
boost::core::invoke_swap(x.get(), y.get());
|
||||
|
||||
if( !hasX )
|
||||
y = boost::none ;
|
||||
@ -64,13 +64,13 @@ struct swap_selector<false>
|
||||
{
|
||||
template <class T>
|
||||
static void optional_swap ( optional<T>& x, optional<T>& y )
|
||||
//BOOST_NOEXCEPT_IF(::boost::is_nothrow_move_constructible<T>::value && BOOST_NOEXCEPT_EXPR(boost::swap(*x, *y)))
|
||||
//BOOST_NOEXCEPT_IF(::boost::is_nothrow_move_constructible<T>::value && BOOST_NOEXCEPT_EXPR(boost::core::invoke_swap(*x, *y)))
|
||||
{
|
||||
if (x)
|
||||
{
|
||||
if (y)
|
||||
{
|
||||
boost::swap(*x, *y);
|
||||
boost::core::invoke_swap(*x, *y);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -105,7 +105,7 @@ struct optional_swap_should_use_default_constructor : has_nothrow_default_constr
|
||||
|
||||
template <class T>
|
||||
inline void swap ( optional<T>& x, optional<T>& y )
|
||||
//BOOST_NOEXCEPT_IF(::boost::is_nothrow_move_constructible<T>::value && BOOST_NOEXCEPT_EXPR(boost::swap(*x, *y)))
|
||||
//BOOST_NOEXCEPT_IF(::boost::is_nothrow_move_constructible<T>::value && BOOST_NOEXCEPT_EXPR(boost::core::invoke_swap(*x, *y)))
|
||||
{
|
||||
optional_detail::swap_selector<optional_swap_should_use_default_constructor<T>::value>::optional_swap(x, y);
|
||||
}
|
||||
|
@ -9,7 +9,7 @@
|
||||
// You are welcome to contact the author at:
|
||||
// akrzemi1@gmail.com
|
||||
|
||||
// trivilally-copyable version of the storage
|
||||
// trivially-copyable version of the storage
|
||||
|
||||
template<class T>
|
||||
class tc_optional_base : public optional_tag
|
||||
@ -142,7 +142,7 @@ class tc_optional_base : public optional_tag
|
||||
// No-throw (assuming T::~T() doesn't)
|
||||
void reset() BOOST_NOEXCEPT { destroy(); }
|
||||
|
||||
// **DEPPRECATED** Replaces the current value -if any- with 'val'
|
||||
// **DEPRECATED** Replaces the current value -if any- with 'val'
|
||||
void reset ( argument_type val ) BOOST_NOEXCEPT { assign(val); }
|
||||
|
||||
// Returns a pointer to the value if this is initialized, otherwise,
|
||||
@ -455,7 +455,7 @@ class tc_optional_base : public optional_tag
|
||||
// Thus, the following overload is needed to properly handle the case when the 'lhs'
|
||||
// is another optional.
|
||||
//
|
||||
// For VC<=70 compilers this workaround dosen't work becasue the comnpiler issues and error
|
||||
// For VC<=70 compilers this workaround doesn't work because the compiler issues and error
|
||||
// instead of choosing the wrong overload
|
||||
//
|
||||
#ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES
|
||||
|
@ -30,7 +30,7 @@
|
||||
#include <boost/core/addressof.hpp>
|
||||
#include <boost/core/enable_if.hpp>
|
||||
#include <boost/core/explicit_operator_bool.hpp>
|
||||
#include <boost/core/swap.hpp>
|
||||
#include <boost/core/invoke_swap.hpp>
|
||||
#include <boost/optional/bad_optional_access.hpp>
|
||||
#include <boost/static_assert.hpp>
|
||||
#include <boost/throw_exception.hpp>
|
||||
@ -392,7 +392,7 @@ class optional_base : public optional_tag
|
||||
// No-throw (assuming T::~T() doesn't)
|
||||
void reset() BOOST_NOEXCEPT { destroy(); }
|
||||
|
||||
// **DEPPRECATED** Replaces the current value -if any- with 'val'
|
||||
// **DEPRECATED** Replaces the current value -if any- with 'val'
|
||||
void reset ( argument_type val ) { assign(val); }
|
||||
|
||||
// Returns a pointer to the value if this is initialized, otherwise,
|
||||
@ -722,7 +722,7 @@ class optional_base : public optional_tag
|
||||
// Thus, the following overload is needed to properly handle the case when the 'lhs'
|
||||
// is another optional.
|
||||
//
|
||||
// For VC<=70 compilers this workaround dosen't work becasue the comnpiler issues and error
|
||||
// For VC<=70 compilers this workaround doesn't work because the compiler issues and error
|
||||
// instead of choosing the wrong overload
|
||||
//
|
||||
#ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES
|
||||
@ -1260,7 +1260,7 @@ class optional
|
||||
BOOST_NOEXCEPT_IF(::boost::is_nothrow_move_constructible<T>::value && ::boost::is_nothrow_move_assignable<T>::value)
|
||||
{
|
||||
// allow for Koenig lookup
|
||||
boost::swap(*this, arg);
|
||||
boost::core::invoke_swap(*this, arg);
|
||||
}
|
||||
|
||||
|
||||
|
@ -77,7 +77,7 @@ void test_basics( T const* )
|
||||
check_uninitialized(def);
|
||||
|
||||
// Implicit construction
|
||||
// The first parameter is implicitely converted to optional<T>(a);
|
||||
// The first parameter is implicitly converted to optional<T>(a);
|
||||
test_implicit_construction(a,a,z);
|
||||
|
||||
// Direct initialization.
|
||||
@ -164,7 +164,7 @@ void test_basics( T const* )
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void test_conditional_ctor_and_get_valur_or ( T const* )
|
||||
void test_conditional_ctor_and_get_value_or ( T const* )
|
||||
{
|
||||
TRACE( std::endl << BOOST_CURRENT_FUNCTION );
|
||||
|
||||
@ -450,8 +450,8 @@ void test_throwing_val_assign_on_initialized( T const* )
|
||||
{
|
||||
// This should:
|
||||
// Attempt to assign 'a' and throw.
|
||||
// opt is kept initialized but its value not neccesarily fully assigned
|
||||
// (in this test, incompletely assigned is flaged with the value -1 being set)
|
||||
// opt is kept initialized but its value not necessarily fully assigned
|
||||
// (in this test, incompletely assigned is flagged with the value -1 being set)
|
||||
set_pending_assign( ARG(T) ) ;
|
||||
opt.reset ( a ) ;
|
||||
passed = true ;
|
||||
@ -575,8 +575,8 @@ void test_throwing_assign_to_initialized( T const* )
|
||||
{
|
||||
// This should:
|
||||
// Attempt to copy construct 'opt1.value()' into opt0 and throw.
|
||||
// opt0 is kept initialized but its value not neccesarily fully assigned
|
||||
// (in this test, incompletely assigned is flaged with the value -1 being set)
|
||||
// opt0 is kept initialized but its value not necessarily fully assigned
|
||||
// (in this test, incompletely assigned is flagged with the value -1 being set)
|
||||
set_pending_assign( ARG(T) ) ;
|
||||
opt0 = opt1 ;
|
||||
passed = true ;
|
||||
@ -687,7 +687,7 @@ void test_throwing_swap( T const* )
|
||||
try
|
||||
{
|
||||
// This should attempt to swap optionals and fail at opt0.reset(*opt1)
|
||||
// Both opt0 and op1 are left unchanged (unswaped)
|
||||
// Both opt0 and op1 are left unchanged (unswapped)
|
||||
swap(opt0,opt1);
|
||||
|
||||
passed = true ;
|
||||
@ -727,7 +727,7 @@ void test_relops( T const* )
|
||||
BOOST_TEST ( !(def0 != def0) ) ;
|
||||
BOOST_TEST ( !(opt0 != opt0) ) ;
|
||||
|
||||
// Check when both are uininitalized.
|
||||
// Check when both are uninitialized.
|
||||
BOOST_TEST ( def0 == def1 ) ; // both uninitialized compare equal
|
||||
BOOST_TEST ( !(def0 < def1) ) ; // uninitialized is never less than uninitialized
|
||||
BOOST_TEST ( !(def0 > def1) ) ; // uninitialized is never greater than uninitialized
|
||||
@ -835,7 +835,7 @@ void test_with_builtin_types()
|
||||
TRACE( std::endl << BOOST_CURRENT_FUNCTION );
|
||||
|
||||
test_basics( ARG(double) );
|
||||
test_conditional_ctor_and_get_valur_or( ARG(double) );
|
||||
test_conditional_ctor_and_get_value_or( ARG(double) );
|
||||
test_uninitialized_access( ARG(double) );
|
||||
test_no_throwing_swap( ARG(double) );
|
||||
test_relops( ARG(double) ) ;
|
||||
@ -857,7 +857,7 @@ void test_with_class_type()
|
||||
|
||||
test_basics( ARG(X) );
|
||||
test_basics( ARG(VBase) );
|
||||
test_conditional_ctor_and_get_valur_or( ARG(X) );
|
||||
test_conditional_ctor_and_get_value_or( ARG(X) );
|
||||
test_direct_value_manip( ARG(X) );
|
||||
test_uninitialized_access( ARG(X) );
|
||||
test_throwing_direct_init( ARG(X) );
|
||||
|
@ -58,7 +58,7 @@ using boost::get_pointer ;
|
||||
#define ARG(T) (static_cast< T const* >(0))
|
||||
|
||||
//
|
||||
// Helper class used to verify the lifetime managment of the values held by optional
|
||||
// Helper class used to verify the lifetime management of the values held by optional
|
||||
//
|
||||
class X
|
||||
{
|
||||
|
@ -22,7 +22,7 @@ int main()
|
||||
class basic_multi_buffer;
|
||||
|
||||
class const_buffers_type // a similar declaration in boost.beast had problem
|
||||
{ // with boost opitonal
|
||||
{ // with boost optional
|
||||
basic_multi_buffer const* b_;
|
||||
|
||||
friend class basic_multi_buffer;
|
||||
|
@ -15,7 +15,7 @@
|
||||
// THIS TEST SHOULD FAIL TO COMPILE
|
||||
//
|
||||
#if BOOST_WORKAROUND( BOOST_INTEL_CXX_VERSION, <= 700) // Intel C++ 7.0
|
||||
// Interl C++ 7.0 incorrectly accepts the initialization "boost::optional<int> opt = 3"
|
||||
// Intel C++ 7.0 incorrectly accepts the initialization "boost::optional<int> opt = 3"
|
||||
// even though the ctor is explicit (c.f. 12.3.1.2), so the test uses another form of
|
||||
// copy-initialization: argument-passing (8.5.12)
|
||||
void helper ( boost::optional<int> ) ;
|
||||
|
@ -13,7 +13,7 @@
|
||||
|
||||
// THIS TEST SHOULD FAIL TO COMPILE
|
||||
|
||||
void test_converitng_assignment_of_different_enums()
|
||||
void test_converting_assignment_of_different_enums()
|
||||
{
|
||||
const boost::optional<int> o1(1);
|
||||
const boost::optional<int> o2(2);
|
||||
@ -22,5 +22,5 @@ void test_converitng_assignment_of_different_enums()
|
||||
|
||||
int main()
|
||||
{
|
||||
test_converitng_assignment_of_different_enums();
|
||||
test_converting_assignment_of_different_enums();
|
||||
}
|
||||
|
@ -16,7 +16,7 @@
|
||||
enum E1 {e1};
|
||||
enum E2 {e2};
|
||||
|
||||
void test_converitng_assignment_of_different_enums()
|
||||
void test_converting_assignment_of_different_enums()
|
||||
{
|
||||
boost::optional<E2> o2(e2);
|
||||
boost::optional<E1> o1;
|
||||
|
@ -16,14 +16,14 @@
|
||||
#endif
|
||||
|
||||
#include "boost/core/ignore_unused.hpp"
|
||||
#include "boost/core/is_same.hpp"
|
||||
#include "boost/core/lightweight_test.hpp"
|
||||
#include "boost/core/lightweight_test_trait.hpp"
|
||||
#include "boost/type_traits/is_same.hpp"
|
||||
|
||||
|
||||
using boost::optional;
|
||||
using boost::make_optional;
|
||||
using boost::core::is_same;
|
||||
using boost::is_same;
|
||||
|
||||
template <typename Expected, typename Deduced>
|
||||
void verify_type(Deduced)
|
||||
|
@ -16,21 +16,21 @@
|
||||
#endif
|
||||
|
||||
#include "boost/core/ignore_unused.hpp"
|
||||
#include "boost/core/is_same.hpp"
|
||||
#include "boost/core/lightweight_test.hpp"
|
||||
#include "boost/core/lightweight_test_trait.hpp"
|
||||
#include "boost/type_traits/is_same.hpp"
|
||||
|
||||
|
||||
using boost::optional;
|
||||
using boost::make_optional;
|
||||
using boost::core::is_same;
|
||||
using boost::is_same;
|
||||
|
||||
template <typename Expected, typename Deduced>
|
||||
void verify_type(Deduced)
|
||||
{
|
||||
BOOST_TEST_TRAIT_TRUE(( is_same<Expected, Deduced> ));
|
||||
}
|
||||
|
||||
|
||||
#if (!defined BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES)
|
||||
struct MoveOnly
|
||||
{
|
||||
@ -38,7 +38,7 @@ struct MoveOnly
|
||||
explicit MoveOnly(int i) : value(i) {}
|
||||
MoveOnly(MoveOnly && r) : value(r.value) { r.value = 0; }
|
||||
MoveOnly& operator=(MoveOnly && r) { value = r.value; r.value = 0; return *this; }
|
||||
|
||||
|
||||
private:
|
||||
MoveOnly(MoveOnly const&);
|
||||
void operator=(MoveOnly const&);
|
||||
@ -53,15 +53,15 @@ void test_make_optional_for_move_only_type()
|
||||
{
|
||||
verify_type< optional<MoveOnly> >(make_optional(makeMoveOnly(2)));
|
||||
verify_type< optional<MoveOnly> >(make_optional(true, makeMoveOnly(2)));
|
||||
|
||||
|
||||
optional<MoveOnly> o1 = make_optional(makeMoveOnly(1));
|
||||
BOOST_TEST (o1);
|
||||
BOOST_TEST_EQ (1, o1->value);
|
||||
|
||||
|
||||
optional<MoveOnly> o2 = make_optional(true, makeMoveOnly(2));
|
||||
BOOST_TEST (o2);
|
||||
BOOST_TEST_EQ (2, o2->value);
|
||||
|
||||
|
||||
optional<MoveOnly> oN = make_optional(false, makeMoveOnly(2));
|
||||
BOOST_TEST (!oN);
|
||||
}
|
||||
@ -73,15 +73,15 @@ void test_make_optional_for_optional()
|
||||
optional<int> oi;
|
||||
verify_type< optional< optional<int> > >(make_optional(oi));
|
||||
verify_type< optional< optional<int> > >(make_optional(true, oi));
|
||||
|
||||
|
||||
optional< optional<int> > ooi = make_optional(oi);
|
||||
BOOST_TEST (ooi);
|
||||
BOOST_TEST (!*ooi);
|
||||
|
||||
|
||||
optional< optional<int> > ooT = make_optional(true, oi);
|
||||
BOOST_TEST (ooT);
|
||||
BOOST_TEST (!*ooT);
|
||||
|
||||
|
||||
optional< optional<int> > ooF = make_optional(false, oi);
|
||||
BOOST_TEST (!ooF);
|
||||
}
|
||||
@ -90,21 +90,21 @@ void test_nested_make_optional()
|
||||
{
|
||||
verify_type< optional< optional<int> > >(make_optional(make_optional(1)));
|
||||
verify_type< optional< optional<int> > >(make_optional(true, make_optional(true, 2)));
|
||||
|
||||
|
||||
optional< optional<int> > oo1 = make_optional(make_optional(1));
|
||||
BOOST_TEST (oo1);
|
||||
BOOST_TEST (*oo1);
|
||||
BOOST_TEST_EQ (1, **oo1);
|
||||
|
||||
|
||||
optional< optional<int> > oo2 = make_optional(true, make_optional(true, 2));
|
||||
BOOST_TEST (oo2);
|
||||
BOOST_TEST (*oo2);
|
||||
BOOST_TEST_EQ (2, **oo2);
|
||||
|
||||
|
||||
optional< optional<int> > oo3 = make_optional(true, make_optional(false, 3));
|
||||
BOOST_TEST (oo3);
|
||||
BOOST_TEST (!*oo3);
|
||||
|
||||
|
||||
optional< optional<int> > oo4 = make_optional(false, make_optional(true, 4));
|
||||
BOOST_TEST (!oo4);
|
||||
}
|
||||
|
@ -16,29 +16,29 @@
|
||||
#endif
|
||||
|
||||
#include "boost/core/ignore_unused.hpp"
|
||||
#include "boost/core/is_same.hpp"
|
||||
#include "boost/core/lightweight_test.hpp"
|
||||
#include "boost/core/lightweight_test_trait.hpp"
|
||||
#include "boost/type_traits/is_same.hpp"
|
||||
|
||||
|
||||
using boost::optional;
|
||||
using boost::make_optional;
|
||||
using boost::core::is_same;
|
||||
using boost::is_same;
|
||||
|
||||
template <typename Expected, typename Deduced>
|
||||
void verify_type(Deduced)
|
||||
{
|
||||
BOOST_TEST_TRAIT_TRUE(( is_same<Expected, Deduced> ));
|
||||
}
|
||||
|
||||
#if (!defined BOOST_NO_CXX11_REF_QUALIFIERS) && (!defined BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES)
|
||||
|
||||
#if (!defined BOOST_NO_CXX11_REF_QUALIFIERS) && (!defined BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES)
|
||||
struct MoveOnly
|
||||
{
|
||||
int value;
|
||||
explicit MoveOnly(int i) : value(i) {}
|
||||
MoveOnly(MoveOnly && r) : value(r.value) { r.value = 0; }
|
||||
MoveOnly& operator=(MoveOnly && r) { value = r.value; r.value = 0; return *this; }
|
||||
|
||||
|
||||
private:
|
||||
MoveOnly(MoveOnly const&);
|
||||
void operator=(MoveOnly const&);
|
||||
@ -70,7 +70,7 @@ void test_map_move_only()
|
||||
optional<int> oj = makeOptMoveOnly(4).map(get_val);
|
||||
BOOST_TEST(bool(oj));
|
||||
BOOST_TEST_EQ(4, *oj);
|
||||
|
||||
|
||||
optional<MoveOnly> o_;
|
||||
optional<int> oi_ = boost::move(o_).map(get_val);
|
||||
BOOST_TEST(!oi_);
|
||||
@ -126,16 +126,16 @@ void test_map_optional()
|
||||
optional<int> o9 (9), o0 (0), o_;
|
||||
verify_type<optional<optional<Int> > >(o9.map(make_opt_int));
|
||||
optional<optional<Int> > oo9 = o9.map(make_opt_int);
|
||||
BOOST_TEST(bool(oo9));
|
||||
BOOST_TEST(bool(*oo9));
|
||||
BOOST_TEST(bool(oo9));
|
||||
BOOST_TEST(bool(*oo9));
|
||||
BOOST_TEST_EQ(9, (**oo9).i);
|
||||
|
||||
optional<optional<Int> > oo0 = o0.map(make_opt_int);
|
||||
BOOST_TEST(bool(oo0));
|
||||
BOOST_TEST(!*oo0);
|
||||
|
||||
BOOST_TEST(bool(oo0));
|
||||
BOOST_TEST(!*oo0);
|
||||
|
||||
optional<optional<Int> > oo_ = o_.map(make_opt_int);
|
||||
BOOST_TEST(!oo_);
|
||||
BOOST_TEST(!oo_);
|
||||
}
|
||||
|
||||
void test_map_with_lambda()
|
||||
@ -178,7 +178,7 @@ void test_map_optional_ref()
|
||||
|
||||
int main()
|
||||
{
|
||||
#if (!defined BOOST_NO_CXX11_REF_QUALIFIERS) && (!defined BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES)
|
||||
#if (!defined BOOST_NO_CXX11_REF_QUALIFIERS) && (!defined BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES)
|
||||
test_map_move_only();
|
||||
#endif
|
||||
test_map_with_lambda();
|
||||
|
@ -105,7 +105,7 @@ void test_noexcept_optional_with_operator() // compile-time test
|
||||
BOOST_STATIC_ASSERT(!BOOST_NOEXCEPT_EXPR( onx0 = ONx0() ));
|
||||
}
|
||||
|
||||
#endif // !defned BOOST_NO_CXX11_NOEXCEPT
|
||||
#endif // !defined BOOST_NO_CXX11_NOEXCEPT
|
||||
#endif // !defined BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES
|
||||
|
||||
int main()
|
||||
|
@ -431,7 +431,7 @@ void test_swap()
|
||||
}
|
||||
|
||||
template <typename T, typename U>
|
||||
void test_convertability_of_compatible_reference_types()
|
||||
void test_convertibility_of_compatible_reference_types()
|
||||
{
|
||||
typename concrete_type_of<T>::type v1(1);
|
||||
optional<T&> oN, o1(v1);
|
||||
@ -489,11 +489,11 @@ int main()
|
||||
test_optional_const_ref<Abstract>();
|
||||
test_optional_const_ref< optional<int> >();
|
||||
|
||||
test_convertability_of_compatible_reference_types<int, const int>();
|
||||
test_convertability_of_compatible_reference_types<Impl, Abstract>();
|
||||
test_convertability_of_compatible_reference_types<Impl, const Abstract>();
|
||||
test_convertability_of_compatible_reference_types<const Impl, const Abstract>();
|
||||
test_convertability_of_compatible_reference_types<optional<int>, const optional<int> >();
|
||||
test_convertibility_of_compatible_reference_types<int, const int>();
|
||||
test_convertibility_of_compatible_reference_types<Impl, Abstract>();
|
||||
test_convertibility_of_compatible_reference_types<Impl, const Abstract>();
|
||||
test_convertibility_of_compatible_reference_types<const Impl, const Abstract>();
|
||||
test_convertibility_of_compatible_reference_types<optional<int>, const optional<int> >();
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ void test_value_init()
|
||||
}
|
||||
}
|
||||
|
||||
void test_optoinal_reference_wrapper()
|
||||
void test_optional_reference_wrapper()
|
||||
{
|
||||
boost::optional<W<S&> > o;
|
||||
BOOST_TEST(boost::none == o);
|
||||
@ -80,7 +80,7 @@ int main()
|
||||
{
|
||||
test_tc_base();
|
||||
test_value_init();
|
||||
test_optoinal_reference_wrapper();
|
||||
test_optional_reference_wrapper();
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user