From 59266a26301e6add265601841687b44306ba8c82 Mon Sep 17 00:00:00 2001 From: Andrzej Krzemienski Date: Fri, 6 Mar 2015 19:20:45 +0100 Subject: [PATCH 1/5] More restrictive assignment from optional --- doc/20_reference.qbk | 79 ++- doc/91_relnotes.qbk | 1 + .../reference/detailed_semantics.html | 492 +++++++++++++----- doc/html/boost_optional/relnotes.html | 4 + doc/html/index.html | 2 +- include/boost/optional/optional.hpp | 13 +- test/Jamfile.v2 | 1 + ...onal_test_fail_convert_assign_of_enums.cpp | 27 + 8 files changed, 444 insertions(+), 175 deletions(-) create mode 100644 test/optional_test_fail_convert_assign_of_enums.cpp diff --git a/doc/20_reference.qbk b/doc/20_reference.qbk index cba3bac..8afc43b 100644 --- a/doc/20_reference.qbk +++ b/doc/20_reference.qbk @@ -602,10 +602,11 @@ __SPACE__ * [*Requires:] `T` is __COPY_CONSTRUCTIBLE__ and `CopyAssignable`. * [*Effects:] - * If `!*this && !rhs` no effect, otherwise - * if `bool(*this) && !rhs`, destroys the contained value by calling `val->T::~T()`, otherwise - * if `!*this && bool(rhs)`, initializes the contained value as if direct-initializing an object of type `T` with `*rhs`, otherwise - * (if `bool(*this) && bool(rhs)`) assigns `*rhs` to the contained value. +[table + [[][`*this` contains a value][`*this` does not contain a value]] + [[`rhs` contains a value][assigns `*rhs` to the contained value][initializes the contained value as if direct-initializing an object of type `T` with `*rhs`]] + [[`rhs` does not contain a value][destroys the contained value by calling `val->T::~T()`][no effect]] +] * [*Returns:] `*this`; * [*Postconditions:] `bool(rhs) == bool(*this)`. * [*Exception Safety:] If any exception is thrown, the initialization state of `*this` and `rhs` remains unchanged. @@ -662,10 +663,11 @@ __SPACE__ * [*Requires:] `T` is __MOVE_CONSTRUCTIBLE__ and `MoveAssignable`. * [*Effects:] - * If `!*this && !rhs` no effect, otherwise - * if `bool(*this) && !rhs`, destroys the contained value by calling `val->T::~T()`, otherwise - * if `!*this && bool(rhs)`, initializes the contained value as if direct-initializing an object of type `T` with `std::move(*rhs)`, otherwise - * (if `bool(*this) && bool(rhs)`) assigns `std::move(*rhs)` to the contained value. +[table + [[][`*this` contains a value][`*this` does not contain a value]] + [[`rhs` contains a value][assigns `std::move(*rhs)` to the contained value][initializes the contained value as if direct-initializing an object of type `T` with `std::move(*rhs)`]] + [[`rhs` does not contain a value][destroys the contained value by calling `val->T::~T()`][no effect]] +] * [*Returns:] `*this`; * [*Postconditions:] `bool(rhs) == bool(*this)`. * [*Remarks:] The expression inside `noexcept` is equivalent to `is_nothrow_move_constructible::value && is_nothrow_move_assignable::value`. @@ -696,21 +698,17 @@ __SPACE__ [: `template optional& optional::operator= ( optional const& rhs ) ;`] -* [*Effect:] Assigns another convertible optional to an optional. -* [*Postconditions:] If `rhs` is initialized, `*this` is initialized and -its value is a ['copy] of the value of `rhs` ['converted] to type `T`; else -`*this` is uninitialized. -* [*Throws:] Whatever `T::operator=( U const& )` or `T::T( U const& )` throws. -* [*Notes:] If both `*this` and rhs are initially initialized, `T`'s -['assignment operator] (from `U`) is used. If `*this` is initially initialized -but `rhs` is uninitialized, `T`'s ['destructor] is called. If `*this` is -initially uninitialized but rhs is initialized, `T`'s ['converting constructor] -(from `U`) is called. -* [*Exception Safety:] In the event of an exception, the initialization state -of `*this` is unchanged and its value unspecified as far as optional is -concerned (it is up to `T`'s `operator=()`). If `*this` is initially -uninitialized and `T`'s converting constructor fails, `*this` is left properly -uninitialized. +* [*Effect:] +[table + [[][`*this` contains a value][`*this` does not contain a value]] + [[`rhs` contains a value][assigns `*rhs` to the contained value][initializes the contained value as if direct-initializing an object of type `T` with `*rhs`]] + [[`rhs` does not contain a value][destroys the contained value by calling `val->T::~T()`][no effect]] +] +* [*Returns:] `*this`. +* [*Postconditions:] `bool(rhs) == bool(*this)`. +* [*Exception Safety:] If any exception is thrown, the result of the expression `bool(*this)` remains unchanged. +If an exception is thrown during the call to `T`'s constructor, no effect. +If an exception is thrown during the call to `T`'s assignment, the state of its contained value is as defined by the exception safety guarantee of `T`'s copy assignment. * [*Example:] `` T v; @@ -727,21 +725,17 @@ __SPACE__ [: `template optional& optional::operator= ( optional&& rhs ) ;`] -* [*Effect:] Move-assigns another convertible optional to an optional. -* [*Postconditions:] If `rhs` is initialized, `*this` is initialized and -its value is moved from the value of `rhs`; else -`*this` is uninitialized. -* [*Throws:] Whatever `T::operator=( U&& )` or `T::T( U&& )` throws. -* [*Notes:] If both `*this` and `rhs` are initially initialized, `T`'s -[' assignment operator] (from `U&&`) is used. If `*this` is initially initialized -but `rhs` is uninitialized, `T`'s ['destructor] is called. If `*this` is -initially uninitialized but `rhs` is initialized, `T`'s ['converting constructor] -(from `U&&`) is called. -* [*Exception Safety:] In the event of an exception, the initialization state -of `*this` is unchanged and its value unspecified as far as optional is -concerned (it is up to `T`'s `operator=()`). If `*this` is initially -uninitialized and `T`'s converting constructor fails, `*this` is left properly -uninitialized. +* [*Effect:] +[table + [[][`*this` contains a value][`*this` does not contain a value]] + [[`rhs` contains a value][assigns `std::move(*rhs)` to the contained value][initializes the contained value as if direct-initializing an object of type `T` with `std::move(*rhs)`]] + [[`rhs` does not contain a value][destroys the contained value by calling `val->T::~T()`][no effect]] +] +* [*Returns:] `*this`. +* [*Postconditions:] `bool(rhs) == bool(*this)`. +* [*Exception Safety:] If any exception is thrown, the result of the expression `bool(*this)` remains unchanged. +If an exception is thrown during the call to `T`'s constructor, no effect. +If an exception is thrown during the call to `T`'s assignment, the state of its contained value is as defined by the exception safety guarantee of `T`'s copy assignment. * [*Example:] `` T v; @@ -1256,10 +1250,11 @@ __SPACE__ * [*Requires:] Lvalues of type `T` shall be swappable and `T` shall be __MOVE_CONSTRUCTIBLE__. * [*Effects:] - * If `!*this && !rhs`, no effect, otherwise - * if `bool(*this) && !rhs`, initializes the contained value of `rhs` as if direct-initializing an object of type `T` with the expression `std::move(*(*this))`, followed by `val->T::~T()`, `*this` does not contain a value and `rhs` contains a value, otherwise - * if `!*this && bool(rhs)`, initializes the contained value of `*this` as if direct-initializing an object of type `T` with the expression `std::move(*rhs)`, followed by `rhs.val->T::~T()`, `*this` contains a value and `rhs` does not contain a value, otherwise - * (if `bool(*this) && bool(rhs)`) calls `swap(*(*this), *rhs)`. +[table + [[][`*this` contains a value][`*this` does not contain a value]] + [[`rhs` contains a value][calls `swap(*(*this), *rhs)`][initializes the contained value of `*this` as if direct-initializing an object of type `T` with the expression `std::move(*rhs)`, followed by `rhs.val->T::~T()`, `*this` contains a value and `rhs` does not contain a value]] + [[`rhs` does not contain a value][initializes the contained value of `rhs` as if direct-initializing an object of type `T` with the expression `std::move(*(*this))`, followed by `val->T::~T()`, `*this` does not contain a value and `rhs` contains a value][no effect]] +] * [*Postconditions:] The states of `x` and `y` interchanged. * [*Throws:] If both are initialized, whatever `swap(T&,T&)` throws. If only one is initialized, whatever `T::T ( T&& )` throws. diff --git a/doc/91_relnotes.qbk b/doc/91_relnotes.qbk index 3cffa97..ea400c7 100644 --- a/doc/91_relnotes.qbk +++ b/doc/91_relnotes.qbk @@ -17,6 +17,7 @@ * Improved the trick that prevents streaming out `optional` without header `optional_io.hpp` by using safe-bool idiom. This addresses [@https://svn.boost.org/trac/boost/ticket/10825 Trac #10825] * IOStream operators are now mentioned in documentation. * Added a way to manually disable move semantics: just define macro `BOOST_OPTIONAL_CONFIG_NO_RVALUE_REFERENCES`. This can be used to work around [@https://svn.boost.org/trac/boost/ticket/10399 Trac #10399] +* It is no longer possible to assign `optional` to `optional` when `U` is not assignable or convertible to `T`. [heading Boost Release 1.57] diff --git a/doc/html/boost_optional/reference/detailed_semantics.html b/doc/html/boost_optional/reference/detailed_semantics.html index 2e017d2..8bff973 100644 --- a/doc/html/boost_optional/reference/detailed_semantics.html +++ b/doc/html/boost_optional/reference/detailed_semantics.html @@ -808,30 +808,74 @@ is CopyConstructible and CopyAssignable.
  • +

    Effects: -

      -
    • - If !*this - && !rhs no effect, otherwise -
    • -
    • - if bool(*this) - && !rhs, destroys the contained value - by calling val->T::~T(), otherwise -
    • -
    • - if !*this - && bool(rhs), initializes the contained value - as if direct-initializing an object of type T - with *rhs, - otherwise -
    • -
    • - (if bool(*this) - && bool(rhs)) assigns *rhs to the contained value. -
    • -
    -
  • +

    +
    +++++ + + + + + + + + + + + + + + + + + +
    + +

    + *this + contains a value +

    +
    +

    + *this + does not contain a value +

    +
    +

    + rhs contains + a value +

    +
    +

    + assigns *rhs + to the contained value +

    +
    +

    + initializes the contained value as if direct-initializing an + object of type T + with *rhs +

    +
    +

    + rhs does not + contain a value +

    +
    +

    + destroys the contained value by calling val->T::~T() +

    +
    +

    + no effect +

    +
    +
  • Returns: *this;
  • @@ -919,30 +963,73 @@ and MoveAssignable.
  • +

    Effects: -

      -
    • - If !*this - && !rhs no effect, otherwise -
    • -
    • - if bool(*this) - && !rhs, destroys the contained value - by calling val->T::~T(), otherwise -
    • -
    • - if !*this - && bool(rhs), initializes the contained value - as if direct-initializing an object of type T - with std::move(*rhs), - otherwise -
    • -
    • - (if bool(*this) - && bool(rhs)) assigns std::move(*rhs) to the contained value. -
    • -
    -
  • +

    +
    +++++ + + + + + + + + + + + + + + + + + +
    + +

    + *this + contains a value +

    +
    +

    + *this + does not contain a value +

    +
    +

    + rhs contains + a value +

    +
    +

    + assigns std::move(*rhs) to the contained value +

    +
    +

    + initializes the contained value as if direct-initializing an + object of type T + with std::move(*rhs) +

    +
    +

    + rhs does not + contain a value +

    +
    +

    + destroys the contained value by calling val->T::~T() +

    +
    +

    + no effect +

    +
    +
  • Returns: *this;
  • @@ -997,40 +1084,88 @@

    • - Effect: Assigns another convertible - optional to an optional. +

      + Effect: +

      +
      +++++ + + + + + + + + + + + + + + + + + +
      + +

      + *this + contains a value +

      +
      +

      + *this + does not contain a value +

      +
      +

      + rhs contains + a value +

      +
      +

      + assigns *rhs + to the contained value +

      +
      +

      + initializes the contained value as if direct-initializing an + object of type T + with *rhs +

      +
      +

      + rhs does not + contain a value +

      +
      +

      + destroys the contained value by calling val->T::~T() +

      +
      +

      + no effect +

      +
      +
    • +
    • + Returns: *this.
    • - Postconditions: If rhs - is initialized, *this - is initialized and its value is a copy of the value - of rhs converted - to type T; else *this - is uninitialized. + Postconditions: bool(rhs) == bool(*this).
    • - Throws: Whatever T::operator=( U const& ) or T::T( U const& ) throws. -
    • -
    • - Notes: If both *this and rhs are initially initialized, - T's assignment - operator (from U) - is used. If *this - is initially initialized but rhs - is uninitialized, T's - destructor is called. If *this is initially uninitialized but rhs - is initialized, T's - converting constructor (from U) - is called. -
    • -
    • - Exception Safety: In the event of an - exception, the initialization state of *this is unchanged and its value unspecified - as far as optional is concerned (it is up to T's - operator=()). - If *this - is initially uninitialized and T's - converting constructor fails, *this is left properly uninitialized. + Exception Safety: If any exception is + thrown, the result of the expression bool(*this) remains unchanged. If an exception is + thrown during the call to T's + constructor, no effect. If an exception is thrown during the call to + T's assignment, the state + of its contained value is as defined by the exception safety guarantee + of T's copy assignment.
    • Example: @@ -1053,36 +1188,87 @@

    • - Effect: Move-assigns another convertible - optional to an optional. +

      + Effect: +

      +
      +++++ + + + + + + + + + + + + + + + + + +
      + +

      + *this + contains a value +

      +
      +

      + *this + does not contain a value +

      +
      +

      + rhs contains + a value +

      +
      +

      + assigns std::move(*rhs) to the contained value +

      +
      +

      + initializes the contained value as if direct-initializing an + object of type T + with std::move(*rhs) +

      +
      +

      + rhs does not + contain a value +

      +
      +

      + destroys the contained value by calling val->T::~T() +

      +
      +

      + no effect +

      +
      +
    • +
    • + Returns: *this.
    • - Postconditions: If rhs - is initialized, *this - is initialized and its value is moved from the value of rhs; else *this is uninitialized. + Postconditions: bool(rhs) == bool(*this).
    • - Throws: Whatever T::operator=( U&& ) - or T::T( U&& - ) throws. -
    • -
    • - Notes: If both *this and rhs - are initially initialized, T's - assignment operator (from U&&) is used. If *this - is initially initialized but rhs - is uninitialized, T's - destructor is called. If *this is initially uninitialized but rhs is initialized, T's - converting constructor (from U&&) is called. -
    • -
    • - Exception Safety: In the event of an - exception, the initialization state of *this is unchanged and its value unspecified - as far as optional is concerned (it is up to T's - operator=()). - If *this - is initially uninitialized and T's - converting constructor fails, *this is left properly uninitialized. + Exception Safety: If any exception is + thrown, the result of the expression bool(*this) remains unchanged. If an exception is + thrown during the call to T's + constructor, no effect. If an exception is thrown during the call to + T's assignment, the state + of its contained value is as defined by the exception safety guarantee + of T's copy assignment.
    • Example: @@ -2019,35 +2205,81 @@ Requires: Lvalues of type T shall be swappable and T shall be MoveConstructible.
    • +

      Effects: -

        -
      • - If !*this - && !rhs, no effect, otherwise -
      • -
      • - if bool(*this) - && !rhs, initializes the contained - value of rhs as - if direct-initializing an object of type T - with the expression std::move(*(*this)), followed by val->T::~T(), *this does not contain a value and - rhs contains a - value, otherwise -
      • -
      • - if !*this - && bool(rhs), initializes the contained value - of *this - as if direct-initializing an object of type T - with the expression std::move(*rhs), followed by rhs.val->T::~T(), *this contains a value and rhs does not contain a value, - otherwise -
      • -
      • - (if bool(*this) - && bool(rhs)) calls swap(*(*this), *rhs). -
      • -
      -
    • +

      +
      +++++ + + + + + + + + + + + + + + + + + +
      + +

      + *this + contains a value +

      +
      +

      + *this + does not contain a value +

      +
      +

      + rhs contains + a value +

      +
      +

      + calls swap(*(*this), *rhs) +

      +
      +

      + initializes the contained value of *this as if direct-initializing + an object of type T + with the expression std::move(*rhs), followed by rhs.val->T::~T(), + *this + contains a value and rhs + does not contain a value +

      +
      +

      + rhs does not + contain a value +

      +
      +

      + initializes the contained value of rhs + as if direct-initializing an object of type T + with the expression std::move(*(*this)), followed by val->T::~T(), + *this + does not contain a value and rhs + contains a value +

      +
      +

      + no effect +

      +
      +
    • Postconditions: The states of x and y interchanged. diff --git a/doc/html/boost_optional/relnotes.html b/doc/html/boost_optional/relnotes.html index 02fcd41..1d476e3 100644 --- a/doc/html/boost_optional/relnotes.html +++ b/doc/html/boost_optional/relnotes.html @@ -52,6 +52,10 @@ This can be used to work around Trac #10399
    • +
    • + It is no longer possible to assign optional<U> to optional<T> when U + is not assignable or convertible to T. +

    diff --git a/doc/html/index.html b/doc/html/index.html index 3abdc22..0c30992 100644 --- a/doc/html/index.html +++ b/doc/html/index.html @@ -138,7 +138,7 @@ - +

    Last revised: January 21, 2015 at 13:59:23 GMT

    Last revised: March 06, 2015 at 18:13:34 GMT


    diff --git a/include/boost/optional/optional.hpp b/include/boost/optional/optional.hpp index f8d631d..56f5096 100644 --- a/include/boost/optional/optional.hpp +++ b/include/boost/optional/optional.hpp @@ -188,7 +188,7 @@ struct types_when_is_ref template void prevent_binding_rvalue_ref_to_optional_lvalue_ref() { -#ifndef BOOST_OPTIONAL_ALLOW_BINDING_TO_RVALUES +#ifndef BOOST_OPTIONAL_CONFIG_ALLOW_BINDING_TO_RVALUES BOOST_STATIC_ASSERT_MSG( !boost::is_lvalue_reference::value || !boost::is_rvalue_reference::value, "binding rvalue references to optional lvalue references is disallowed"); @@ -371,13 +371,22 @@ class optional_base : public optional_tag if (is_initialized()) { if ( rhs.is_initialized() ) - assign_value(static_cast(rhs.get()), is_reference_predicate() ); +#ifndef BOOST_OPTIONAL_CONFIG_RESTORE_ASSIGNMENT_OF_NONCONVERTIBLE_TYPES + assign_value(rhs.get(), is_reference_predicate() ); +#else + assign_value(static_cast(rhs.get()), is_reference_predicate() ); +#endif + else destroy(); } else { if ( rhs.is_initialized() ) +#ifndef BOOST_OPTIONAL_CONFIG_RESTORE_ASSIGNMENT_OF_NONCONVERTIBLE_TYPES + construct(rhs.get()); +#else construct(static_cast(rhs.get())); +#endif } } diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 9db0c01..54535b7 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -56,5 +56,6 @@ import testing ; [ compile-fail optional_test_fail_explicit_convert_in_value_or.cpp ] [ compile-fail optional_test_fail_explicit_convert_in_value_or_call.cpp ] [ compile-fail optional_test_fail_io_without_io.cpp ] + [ compile-fail optional_test_fail_convert_assign_of_enums.cpp ] ; } diff --git a/test/optional_test_fail_convert_assign_of_enums.cpp b/test/optional_test_fail_convert_assign_of_enums.cpp new file mode 100644 index 0000000..184e282 --- /dev/null +++ b/test/optional_test_fail_convert_assign_of_enums.cpp @@ -0,0 +1,27 @@ +// Copyright (C) 2015, Andrzej Krzemienski. +// +// Use, modification, and distribution is subject to the Boost Software +// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +// +// See http://www.boost.org/lib/optional for documentation. +// +// You are welcome to contact the author at: +// akrzemi1@gmail.com + +#include +#include "boost/optional.hpp" + +// THIS TEST SHOULD FAIL TO COMPILE + +enum E1 {e1}; +enum E2 {e2}; + +void test_converitng_assignment_of_different_enums() +{ + boost::optional o2(e2); + boost::optional o1; + o1 = o2; +} + +int main() {} From 0a8a798c3a57ab608b6e88fd9f2aa97e4bc3af8a Mon Sep 17 00:00:00 2001 From: Andrzej Krzemienski Date: Mon, 9 Mar 2015 11:50:10 +0100 Subject: [PATCH 2/5] Fixed Trac #10839 --- doc/20_reference.qbk | 15 ++-- doc/91_relnotes.qbk | 3 +- .../reference/detailed_semantics.html | 17 +++-- doc/html/boost_optional/relnotes.html | 7 +- doc/html/index.html | 2 +- doc/html/optional/reference.html | 6 +- include/boost/optional/optional.hpp | 8 +-- test/Jamfile.v2 | 1 + ...onal_test_fail_convert_assign_of_enums.cpp | 1 - test/optional_test_ref_move.cpp | 69 +++++++++++++++++++ 10 files changed, 107 insertions(+), 22 deletions(-) create mode 100644 test/optional_test_ref_move.cpp diff --git a/doc/20_reference.qbk b/doc/20_reference.qbk index 8afc43b..8ca21b8 100644 --- a/doc/20_reference.qbk +++ b/doc/20_reference.qbk @@ -15,11 +15,13 @@ namespace boost { - template + template class optional { - public : + public : + typedef T value_type; + // (If T is of reference type, the parameters and results by reference are by value) optional () noexcept ; ``[link reference_optional_constructor __GO_TO__]`` @@ -1137,9 +1139,8 @@ __SPACE__ * [*Requires:] `T` shall meet requirements of __SGI_EQUALITY_COMPARABLE__. * [*Returns:] If both `x` and `y` are initialized, `(*x == *y)`. If only `x` or `y` is initialized, `false`. If both are uninitialized, `true`. -* [*Notes:] 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` or a pointer; use +* [*Notes:] This definition guarantees that `optional` not containing a value is compared unequal to any `optional` containing any value, and equal to any other `optional` 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` or a pointer; use __FUNCTION_EQUAL_POINTEES__ instead * [*Example:] `` @@ -1166,8 +1167,8 @@ __SPACE__ * [*Requires:] Expression `*x < *y` shall be well-formed and its result shall be convertible to `bool`. * [*Returns:] `(!y) ? false : (!x) ? true : *x < *y`. -* [*Notes:] Pointers have shallow relational operators while `optional` has -deep relational operators. Do not use `operator<` directly in generic code +* [*Notes:] This definition guarantees that `optional` not containing a value is ordered as less than any `optional` containing any value, and equivalent to any other `optional` 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` or a pointer; use __FUNCTION_LESS_POINTEES__ instead. `T` need not be __SGI_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 __SGI_LESS_THAN_COMPARABLE__ (transitivity, antisymmetry and irreflexivity), `optinal` is __SGI_LESS_THAN_COMPARABLE__. * [*Example:] `` diff --git a/doc/91_relnotes.qbk b/doc/91_relnotes.qbk index ea400c7..e75fef7 100644 --- a/doc/91_relnotes.qbk +++ b/doc/91_relnotes.qbk @@ -17,7 +17,8 @@ * Improved the trick that prevents streaming out `optional` without header `optional_io.hpp` by using safe-bool idiom. This addresses [@https://svn.boost.org/trac/boost/ticket/10825 Trac #10825] * IOStream operators are now mentioned in documentation. * Added a way to manually disable move semantics: just define macro `BOOST_OPTIONAL_CONFIG_NO_RVALUE_REFERENCES`. This can be used to work around [@https://svn.boost.org/trac/boost/ticket/10399 Trac #10399] -* It is no longer possible to assign `optional` to `optional` when `U` is not assignable or convertible to `T`. +* It is no longer possible to assign `optional` to `optional` when `U` is not assignable or convertible to `T` ([@https://svn.boost.org/trac/boost/ticket/11087 Trac #11087]). +* Value accessors now work correctly on rvalues of `optional` ([@https://svn.boost.org/trac/boost/ticket/10839 Trac #10839]). [heading Boost Release 1.57] diff --git a/doc/html/boost_optional/reference/detailed_semantics.html b/doc/html/boost_optional/reference/detailed_semantics.html index 8bff973..3f4bd8d 100644 --- a/doc/html/boost_optional/reference/detailed_semantics.html +++ b/doc/html/boost_optional/reference/detailed_semantics.html @@ -2028,9 +2028,13 @@ If both are uninitialized, true.
  • - Notes: Pointers have shallow relational - operators while optional - has deep relational operators. Do not use operator== directly in generic code which expect + Notes: This definition guarantees that + optional<T> + not containing a value is compared unequal to any optional<T> containing any value, and equal 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 equal_pointees() instead
  • @@ -2070,8 +2074,11 @@ : *x < *y.
  • - Notes: Pointers have shallow relational - operators while optional + 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 less_pointees() instead. T need not be diff --git a/doc/html/boost_optional/relnotes.html b/doc/html/boost_optional/relnotes.html index 1d476e3..3fb495b 100644 --- a/doc/html/boost_optional/relnotes.html +++ b/doc/html/boost_optional/relnotes.html @@ -54,7 +54,12 @@
  • It is no longer possible to assign optional<U> to optional<T> when U - is not assignable or convertible to T. + is not assignable or convertible to T + (Trac #11087). +
  • +
  • + Value accessors now work correctly on rvalues of optional<T&> (Trac + #10839).
  • diff --git a/doc/html/index.html b/doc/html/index.html index 0c30992..0e063f2 100644 --- a/doc/html/index.html +++ b/doc/html/index.html @@ -138,7 +138,7 @@ - +

    Last revised: March 06, 2015 at 18:13:34 GMT

    Last revised: March 09, 2015 at 09:53:44 GMT


    diff --git a/doc/html/optional/reference.html b/doc/html/optional/reference.html index 0b6db6c..21e9ebb 100644 --- a/doc/html/optional/reference.html +++ b/doc/html/optional/reference.html @@ -39,10 +39,12 @@ namespace boost { -template<class T> +template <class T> class optional { - public : +public : + + typedef T value_type; // (If T is of reference type, the parameters and results by reference are by value) diff --git a/include/boost/optional/optional.hpp b/include/boost/optional/optional.hpp index 56f5096..126cf02 100644 --- a/include/boost/optional/optional.hpp +++ b/include/boost/optional/optional.hpp @@ -1020,7 +1020,7 @@ class optional : public optional_detail::optional_base #if (!defined BOOST_NO_CXX11_REF_QUALIFIERS) && (!defined BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES) reference_const_type operator *() const& { return this->get() ; } reference_type operator *() & { return this->get() ; } - reference_type_of_temporary_wrapper operator *() && { return boost::move(this->get()) ; } + reference_type_of_temporary_wrapper operator *() && { return base::types::move(this->get()) ; } #else reference_const_type operator *() const { return this->get() ; } reference_type operator *() { return this->get() ; } @@ -1046,7 +1046,7 @@ class optional : public optional_detail::optional_base reference_type_of_temporary_wrapper value() && { if (this->is_initialized()) - return boost::move(this->get()) ; + return base::types::move(this->get()) ; else throw_exception(bad_optional_access()); } @@ -1084,7 +1084,7 @@ class optional : public optional_detail::optional_base value_type value_or ( U&& v ) && { if (this->is_initialized()) - return boost::move(get()); + return base::types::move(get()); else return boost::forward(v); } @@ -1123,7 +1123,7 @@ class optional : public optional_detail::optional_base value_type value_or_eval ( F f ) && { if (this->is_initialized()) - return boost::move(get()); + return base::types::move(get()); else return f(); } diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 54535b7..d654545 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -28,6 +28,7 @@ import testing ; [ run optional_test_ref_convert_assign_mutable_int.cpp ] [ run optional_test_ref_convert_assign_const_int.cpp ] [ run optional_test_ref_portable_minimum.cpp ] + [ run optional_test_ref_move.cpp ] [ run optional_test_inplace_factory.cpp ] [ run optional_test_io.cpp ] [ run optional_test_move.cpp ] diff --git a/test/optional_test_fail_convert_assign_of_enums.cpp b/test/optional_test_fail_convert_assign_of_enums.cpp index 184e282..5953850 100644 --- a/test/optional_test_fail_convert_assign_of_enums.cpp +++ b/test/optional_test_fail_convert_assign_of_enums.cpp @@ -9,7 +9,6 @@ // You are welcome to contact the author at: // akrzemi1@gmail.com -#include #include "boost/optional.hpp" // THIS TEST SHOULD FAIL TO COMPILE diff --git a/test/optional_test_ref_move.cpp b/test/optional_test_ref_move.cpp new file mode 100644 index 0000000..78b7bf2 --- /dev/null +++ b/test/optional_test_ref_move.cpp @@ -0,0 +1,69 @@ +// Copyright (C) 2014 Andrzej Krzemienski. +// +// Use, modification, and distribution is subject to the Boost Software +// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +// +// See http://www.boost.org/lib/optional for documentation. +// +// You are welcome to contact the author at: akrzemi1@gmail.com + + +#include "boost/optional/optional.hpp" + +#ifdef __BORLANDC__ +#pragma hdrstop +#endif + +#include +#include "boost/core/addressof.hpp" +#include "boost/core/lightweight_test.hpp" + +using boost::optional; + +std::string global("text"); + +optional make_optional_string_ref() +{ + return optional(global); +} + +std::string& return_global() +{ + return global; +} + +int main() +{ + optional opt; + opt = make_optional_string_ref(); + BOOST_TEST(bool(opt)); + BOOST_TEST(*opt == global); + BOOST_TEST(boost::addressof(*opt) == boost::addressof(global)); + + { + std::string& str = *make_optional_string_ref(); + BOOST_TEST(str == global); + BOOST_TEST(boost::addressof(str) == boost::addressof(global)); + } + + { + std::string& str = make_optional_string_ref().value(); + BOOST_TEST(str == global); + BOOST_TEST(boost::addressof(str) == boost::addressof(global)); + } + + { + std::string& str = make_optional_string_ref().value_or(global); + BOOST_TEST(str == global); + BOOST_TEST(boost::addressof(str) == boost::addressof(global)); + } + + { + std::string& str = make_optional_string_ref().value_or_eval(&return_global); + BOOST_TEST(str == global); + BOOST_TEST(boost::addressof(str) == boost::addressof(global)); + } + + return boost::report_errors(); +} From 6e4082509878c7fcfa63b9cc772d15a6442ffeb3 Mon Sep 17 00:00:00 2001 From: Andrzej Krzemienski Date: Mon, 9 Mar 2015 21:56:25 +0100 Subject: [PATCH 3/5] described headers in docs; added move in operator>> --- doc/00_optional.qbk | 12 +- doc/21_ref_none.qbk | 29 + doc/22_ref_bad_optional_access.qbk | 40 + doc/23_ref_optional_io.qbk | 74 + doc/24_ref_optional_fwd.qbk | 32 + doc/27_ref_optional_synopsis.qbk | 151 ++ ...ence.qbk => 28_ref_optional_semantics.qbk} | 141 - doc/29_ref_optional_convenience.qbk | 17 + .../dependencies_and_portability.html | 6 +- .../reference/detailed_semantics.html | 2337 ---------------- ...ost_optional_bad_optional_access_hpp_.html | 63 + .../detailed_semantics.html | 60 + .../header__boost_optional_hpp_.html | 47 + ...der__boost_optional_optional_fwd_hpp_.html | 66 + .../detailed_semantics.html | 2387 +++++++++++++++++ .../boost_optional/reference/io_header.html | 72 + .../reference/io_header/io_semantics.html | 112 + doc/html/index.html | 16 +- doc/html/optional/reference.html | 172 +- ...header__boost_optional_optional_hpp_.html} | 151 +- include/boost/optional/optional_io.hpp | 4 + 21 files changed, 3294 insertions(+), 2695 deletions(-) create mode 100644 doc/21_ref_none.qbk create mode 100644 doc/22_ref_bad_optional_access.qbk create mode 100644 doc/23_ref_optional_io.qbk create mode 100644 doc/24_ref_optional_fwd.qbk create mode 100644 doc/27_ref_optional_synopsis.qbk rename doc/{20_reference.qbk => 28_ref_optional_semantics.qbk} (82%) create mode 100644 doc/29_ref_optional_convenience.qbk delete mode 100644 doc/html/boost_optional/reference/detailed_semantics.html create mode 100644 doc/html/boost_optional/reference/header__boost_optional_bad_optional_access_hpp_.html create mode 100644 doc/html/boost_optional/reference/header__boost_optional_bad_optional_access_hpp_/detailed_semantics.html create mode 100644 doc/html/boost_optional/reference/header__boost_optional_hpp_.html create mode 100644 doc/html/boost_optional/reference/header__boost_optional_optional_fwd_hpp_.html create mode 100644 doc/html/boost_optional/reference/header__boost_optional_optional_hpp_/detailed_semantics.html create mode 100644 doc/html/boost_optional/reference/io_header.html create mode 100644 doc/html/boost_optional/reference/io_header/io_semantics.html rename doc/html/{boost_optional/reference/synopsis.html => optional/reference/header__boost_optional_optional_hpp_.html} (64%) diff --git a/doc/00_optional.qbk b/doc/00_optional.qbk index 28532de..d1a2275 100644 --- a/doc/00_optional.qbk +++ b/doc/00_optional.qbk @@ -88,8 +88,16 @@ This is how you solve it with `boost::optional`: [include 19_type_requirements.qbk] [include 1A_on_performance.qbk] [endsect] -[section Reference] -[include 20_reference.qbk] +[section:reference Reference] +[include 21_ref_none.qbk] +[include 22_ref_bad_optional_access.qbk] +[include 23_ref_optional_io.qbk] +[include 24_ref_optional_fwd.qbk] +[section Header ] +[include 27_ref_optional_synopsis.qbk] +[include 28_ref_optional_semantics.qbk] +[endsect] +[include 29_ref_optional_convenience.qbk] [endsect] [include 90_dependencies.qbk] [include 91_relnotes.qbk] diff --git a/doc/21_ref_none.qbk b/doc/21_ref_none.qbk new file mode 100644 index 0000000..e3b921e --- /dev/null +++ b/doc/21_ref_none.qbk @@ -0,0 +1,29 @@ +[/ + Boost.Optional + + Copyright (c) 2003-2007 Fernando Luis Cacciola Carballal + Copyright (c) 2015 Andrzej Krzemienski + + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +] + +[section Header ] + +[section Synopsis] +``` +namespace boost { + +class none_t {}; + +extern const none_t none; // see below + +} // namespace boost +``` + +Variable `none` has external linkage, however it is not required to link with any library to obtain its definition. Only by including this header file, the definition becomes available, by means of using template instantiation. + +[endsect] + +[endsect] diff --git a/doc/22_ref_bad_optional_access.qbk b/doc/22_ref_bad_optional_access.qbk new file mode 100644 index 0000000..e929134 --- /dev/null +++ b/doc/22_ref_bad_optional_access.qbk @@ -0,0 +1,40 @@ +[/ + Boost.Optional + + Copyright (c) 2003-2007 Fernando Luis Cacciola Carballal + Copyright (c) 2015 Andrzej Krzemienski + + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +] + +[section Header ] + +[section Synopsis] +``` +namespace boost { + +class bad_optional_access : public std::logic_error +{ +public: + bad_optional_access(); ``[link reference_bad_optional_access_constructor __GO_TO__]`` +}; + +} // namespace boost +``` +[endsect] + +[section Detailed semantics] + +__SPACE__ + +[#reference_bad_optional_access_constructor] + +`bad_optional_access();` + +* [*Effect:] Constructs an object of class `bad_optional_access`. +* [*Postconditions:] `what()` returns an implementation-defined NTBS. + +[endsect] +[endsect] diff --git a/doc/23_ref_optional_io.qbk b/doc/23_ref_optional_io.qbk new file mode 100644 index 0000000..a9425d4 --- /dev/null +++ b/doc/23_ref_optional_io.qbk @@ -0,0 +1,74 @@ +[/ + Boost.Optional + + Copyright (c) 2003-2007 Fernando Luis Cacciola Carballal + Copyright (c) 2015 Andrzej Krzemienski + + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +] + +[section:io_header Header ] + +[section:io_synop Synopsis] +``` +#include +#include +#include + +namespace boost { + +template + std::basic_ostream& + operator<<(std::basic_ostream& out, optional const& v); ``[link reference_operator_ostream __GO_TO__]`` + + template + std::basic_ostream& + operator<<(std::basic_ostream& out, none_t const&); ``[link reference_operator_ostream_none __GO_TO__]`` + +template + std::basic_istream& + operator>>(std::basic_istream& in, optional& v); ``[link reference_operator_istream __GO_TO__]`` + +} // namespace boost +``` + +[endsect] + +[section:io_semantics Detailed semantics] + + +[#reference_operator_ostream] + + +`template ` [br] +\u00A0\u00A0\u00A0\u00A0`std::basic_ostream&` [br] +\u00A0\u00A0\u00A0\u00A0`operator<<(std::basic_ostream& out, optional const& v);` + +* [*Effect:] Outputs an implementation-defined string. The output contains the information about whether the optional object contains a value or not. If `v` contains a value, the output contains result of calling `out << *v`. +* [*Returns:] `out`. + +__SPACE__ +[#reference_operator_ostream_none] + +`template ` [br] +\u00A0\u00A0\u00A0\u00A0`std::basic_ostream&` [br] +\u00A0\u00A0\u00A0\u00A0`operator<<(std::basic_ostream& out, none_t);` + +* [*Effect:] Outputs an implementation-defined string. +* [*Returns:] `out`. + +__SPACE__ +[#reference_operator_istream] + +`template ` [br] +\u00A0\u00A0\u00A0\u00A0`std::basic_ostream&` [br] +\u00A0\u00A0\u00A0\u00A0`operator>>(std::basic_istream& in, optional& v);` + +* [*Requires:] `T` is __SGI_DEFAULT_CONSTRUCTIBLE__ and __MOVE_CONSTRUCTIBLE__. +* [*Effect:] Reads the value of optional object from `in`. If the string representation indicates that the optional object should contain a value, `v` contains a value and its contained value is obtained as if by default-constructing an object `o` of type `T` and then calling `in >> o`; otherwise `v` does not contain a value, and the previously contained value (if any) has been destroyed. +* [*Returns:] `out`. + +[endsect] +[endsect] diff --git a/doc/24_ref_optional_fwd.qbk b/doc/24_ref_optional_fwd.qbk new file mode 100644 index 0000000..03187f9 --- /dev/null +++ b/doc/24_ref_optional_fwd.qbk @@ -0,0 +1,32 @@ +[/ + Boost.Optional + + Copyright (c) 2003-2007 Fernando Luis Cacciola Carballal + Copyright (c) 2015 Andrzej Krzemienski + + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +] + +[section Header ] + +[section Synopsis] +``` +namespace boost { + +template class optional ; + +template void swap ( optional& , optional& ); + +template struct optional_swap_should_use_default_constructor ; + +} // namespace boost +``` + +This header only contains declarations. + +[endsect] + + +[endsect] diff --git a/doc/27_ref_optional_synopsis.qbk b/doc/27_ref_optional_synopsis.qbk new file mode 100644 index 0000000..042dd3d --- /dev/null +++ b/doc/27_ref_optional_synopsis.qbk @@ -0,0 +1,151 @@ +[/ + Boost.Optional + + Copyright (c) 2003-2007 Fernando Luis Cacciola Carballal + + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +] + + +[#ref_header_optional_optional_hpp][section:header_optional_optional Synopsis] + + ```// In Header: <`[@boost:/boost/optional/optional.hpp boost/optional/optional.hpp]'''>'''`` + + namespace boost { + + template + class optional + { + public : + + typedef T value_type; + + // (If T is of reference type, the parameters and results by reference are by value) + + optional () noexcept ; ``[link reference_optional_constructor __GO_TO__]`` + + optional ( none_t ) noexcept ; ``[link reference_optional_constructor_none_t __GO_TO__]`` + + optional ( T const& v ) ; ``[link reference_optional_constructor_value __GO_TO__]`` + + optional ( T&& v ) ; ``[link reference_optional_constructor_move_value __GO_TO__]`` + + // [new in 1.34] + optional ( bool condition, T const& v ) ; ``[link reference_optional_constructor_bool_value __GO_TO__]`` + + optional ( optional const& rhs ) ; ``[link reference_optional_constructor_optional __GO_TO__]`` + + optional ( optional&& rhs ) noexcept(``['see below]``) ; ``[link reference_optional_move_constructor_optional __GO_TO__]`` + + template explicit optional ( optional const& rhs ) ; ``[link reference_optional_constructor_other_optional __GO_TO__]`` + + template explicit optional ( optional&& rhs ) ; ``[link reference_optional_move_constructor_other_optional __GO_TO__]`` + + template explicit optional ( InPlaceFactory const& f ) ; ``[link reference_optional_constructor_factory __GO_TO__]`` + + template explicit optional ( TypedInPlaceFactory const& f ) ; ``[link reference_optional_constructor_factory __GO_TO__]`` + + optional& operator = ( none_t ) noexcept ; ``[link reference_optional_operator_equal_none_t __GO_TO__]`` + + optional& operator = ( T const& v ) ; ``[link reference_optional_operator_equal_value __GO_TO__]`` + + optional& operator = ( T&& v ) ; ``[link reference_optional_operator_move_equal_value __GO_TO__]`` + + optional& operator = ( optional const& rhs ) ; ``[link reference_optional_operator_equal_optional __GO_TO__]`` + + optional& operator = ( optional&& rhs ) noexcept(``['see below]``) ; ``[link reference_optional_operator_move_equal_optional __GO_TO__]`` + + template optional& operator = ( optional const& rhs ) ; ``[link reference_optional_operator_equal_other_optional __GO_TO__]`` + + template optional& operator = ( optional&& rhs ) ; ``[link reference_optional_operator_move_equal_other_optional __GO_TO__]`` + + template void emplace ( Args...&& args ) ; ``[link reference_optional_emplace __GO_TO__]`` + + template optional& operator = ( InPlaceFactory const& f ) ; ``[link reference_optional_operator_equal_factory __GO_TO__]`` + + template optional& operator = ( TypedInPlaceFactory const& f ) ; ``[link reference_optional_operator_equal_factory __GO_TO__]`` + + T const& get() const ; ``[link reference_optional_get __GO_TO__]`` + T& get() ; ``[link reference_optional_get __GO_TO__]`` + + T const* operator ->() const ; ``[link reference_optional_operator_arrow __GO_TO__]`` + T* operator ->() ; ``[link reference_optional_operator_arrow __GO_TO__]`` + + T const& operator *() const& ; ``[link reference_optional_operator_asterisk __GO_TO__]`` + T& operator *() & ; ``[link reference_optional_operator_asterisk __GO_TO__]`` + T&& operator *() && ; ``[link reference_optional_operator_asterisk_move __GO_TO__]`` + + T const& value() const& ; ``[link reference_optional_value __GO_TO__]`` + T& value() & ; ``[link reference_optional_value __GO_TO__]`` + T&& value() && ; ``[link reference_optional_value_move __GO_TO__]`` + + template T value_or( U && v ) const& ; ``[link reference_optional_value_or __GO_TO__]`` + template T value_or( U && v ) && ; ``[link reference_optional_value_or_move __GO_TO__]`` + + template T value_or_eval( F f ) const& ; ``[link reference_optional_value_or_call __GO_TO__]`` + template T value_or_eval( F f ) && ; ``[link reference_optional_value_or_call_move __GO_TO__]`` + + T const* get_ptr() const ; ``[link reference_optional_get_ptr __GO_TO__]`` + T* get_ptr() ; ``[link reference_optional_get_ptr __GO_TO__]`` + + explicit operator bool() const noexcept ; ``[link reference_optional_operator_bool __GO_TO__]`` + + bool operator!() const noexcept ; ``[link reference_optional_operator_not __GO_TO__]`` + + // deprecated methods + + // (deprecated) + void reset() noexcept ; ``[link reference_optional_reset __GO_TO__]`` + + // (deprecated) + void reset ( T const& ) ; ``[link reference_optional_reset_value __GO_TO__]`` + + // (deprecated) + bool is_initialized() const ; ``[link reference_optional_is_initialized __GO_TO__]`` + + // (deprecated) + T const& get_value_or( T const& default ) const ; ``[link reference_optional_get_value_or_value __GO_TO__]`` + }; + + template inline bool operator == ( optional const& x, optional const& y ) ; ``[link reference_operator_compare_equal_optional_optional __GO_TO__]`` + + template inline bool operator != ( optional const& x, optional const& y ) ; ``[link reference_operator_compare_not_equal_optional_optional __GO_TO__]`` + + template inline bool operator < ( optional const& x, optional const& y ) ; ``[link reference_operator_compare_less_optional_optional __GO_TO__]`` + + template inline bool operator > ( optional const& x, optional const& y ) ; ``[link reference_operator_compare_greater_optional_optional __GO_TO__]`` + + template inline bool operator <= ( optional const& x, optional const& y ) ; ``[link reference_operator_compare_less_or_equal_optional_optional __GO_TO__]`` + + template inline bool operator >= ( optional const& x, optional const& y ) ; ``[link reference_operator_compare_greater_or_equal_optional_optional __GO_TO__]`` + + template inline bool operator == ( optional const& x, none_t ) noexcept ; ``[link reference_operator_compare_equal_optional_none __GO_TO__]`` + + template inline bool operator != ( optional const& x, none_t ) noexcept ; ``[link reference_operator_compare_not_equal_optional_none __GO_TO__]`` + + template inline optional make_optional ( T const& v ) ; ``[link reference_make_optional_value __GO_TO__]`` + + template inline optional make_optional ( bool condition, T const& v ) ; ``[link reference_make_optional_bool_value __GO_TO__]`` + + template inline T const& get_optional_value_or ( optional const& opt, T const& default ) ; ``[link reference_optional_get_value_or_value __GO_TO__]`` + + template inline T const& get ( optional const& opt ) ; ``[link reference_optional_get __GO_TO__]`` + + template inline T& get ( optional & opt ) ; ``[link reference_optional_get __GO_TO__]`` + + template inline T const* get ( optional const* opt ) ; ``[link reference_optional_get __GO_TO__]`` + + template inline T* get ( optional* opt ) ; ``[link reference_optional_get __GO_TO__]`` + + template inline T const* get_pointer ( optional const& opt ) ; ``[link reference_optional_get_ptr __GO_TO__]`` + + template inline T* get_pointer ( optional & opt ) ; ``[link reference_optional_get_ptr __GO_TO__]`` + + template inline void swap( optional& x, optional& y ) ; ``[link reference_swap_optional_optional __GO_TO__]`` + + } // namespace boost + + +[endsect] diff --git a/doc/20_reference.qbk b/doc/28_ref_optional_semantics.qbk similarity index 82% rename from doc/20_reference.qbk rename to doc/28_ref_optional_semantics.qbk index 8ca21b8..07f7a43 100644 --- a/doc/20_reference.qbk +++ b/doc/28_ref_optional_semantics.qbk @@ -9,147 +9,6 @@ ] -[section Synopsis] - - ```// In Header: <`[@boost:/boost/optional/optional.hpp boost/optional/optional.hpp]'''>'''`` - - namespace boost { - - template - class optional - { - public : - - typedef T value_type; - - // (If T is of reference type, the parameters and results by reference are by value) - - optional () noexcept ; ``[link reference_optional_constructor __GO_TO__]`` - - optional ( none_t ) noexcept ; ``[link reference_optional_constructor_none_t __GO_TO__]`` - - optional ( T const& v ) ; ``[link reference_optional_constructor_value __GO_TO__]`` - - optional ( T&& v ) ; ``[link reference_optional_constructor_move_value __GO_TO__]`` - - // [new in 1.34] - optional ( bool condition, T const& v ) ; ``[link reference_optional_constructor_bool_value __GO_TO__]`` - - optional ( optional const& rhs ) ; ``[link reference_optional_constructor_optional __GO_TO__]`` - - optional ( optional&& rhs ) noexcept(``['see below]``) ; ``[link reference_optional_move_constructor_optional __GO_TO__]`` - - template explicit optional ( optional const& rhs ) ; ``[link reference_optional_constructor_other_optional __GO_TO__]`` - - template explicit optional ( optional&& rhs ) ; ``[link reference_optional_move_constructor_other_optional __GO_TO__]`` - - template explicit optional ( InPlaceFactory const& f ) ; ``[link reference_optional_constructor_factory __GO_TO__]`` - - template explicit optional ( TypedInPlaceFactory const& f ) ; ``[link reference_optional_constructor_factory __GO_TO__]`` - - optional& operator = ( none_t ) noexcept ; ``[link reference_optional_operator_equal_none_t __GO_TO__]`` - - optional& operator = ( T const& v ) ; ``[link reference_optional_operator_equal_value __GO_TO__]`` - - optional& operator = ( T&& v ) ; ``[link reference_optional_operator_move_equal_value __GO_TO__]`` - - optional& operator = ( optional const& rhs ) ; ``[link reference_optional_operator_equal_optional __GO_TO__]`` - - optional& operator = ( optional&& rhs ) noexcept(``['see below]``) ; ``[link reference_optional_operator_move_equal_optional __GO_TO__]`` - - template optional& operator = ( optional const& rhs ) ; ``[link reference_optional_operator_equal_other_optional __GO_TO__]`` - - template optional& operator = ( optional&& rhs ) ; ``[link reference_optional_operator_move_equal_other_optional __GO_TO__]`` - - template void emplace ( Args...&& args ) ; ``[link reference_optional_emplace __GO_TO__]`` - - template optional& operator = ( InPlaceFactory const& f ) ; ``[link reference_optional_operator_equal_factory __GO_TO__]`` - - template optional& operator = ( TypedInPlaceFactory const& f ) ; ``[link reference_optional_operator_equal_factory __GO_TO__]`` - - T const& get() const ; ``[link reference_optional_get __GO_TO__]`` - T& get() ; ``[link reference_optional_get __GO_TO__]`` - - T const* operator ->() const ; ``[link reference_optional_operator_arrow __GO_TO__]`` - T* operator ->() ; ``[link reference_optional_operator_arrow __GO_TO__]`` - - T const& operator *() const& ; ``[link reference_optional_operator_asterisk __GO_TO__]`` - T& operator *() & ; ``[link reference_optional_operator_asterisk __GO_TO__]`` - T&& operator *() && ; ``[link reference_optional_operator_asterisk_move __GO_TO__]`` - - T const& value() const& ; ``[link reference_optional_value __GO_TO__]`` - T& value() & ; ``[link reference_optional_value __GO_TO__]`` - T&& value() && ; ``[link reference_optional_value_move __GO_TO__]`` - - template T value_or( U && v ) const& ; ``[link reference_optional_value_or __GO_TO__]`` - template T value_or( U && v ) && ; ``[link reference_optional_value_or_move __GO_TO__]`` - - template T value_or_eval( F f ) const& ; ``[link reference_optional_value_or_call __GO_TO__]`` - template T value_or_eval( F f ) && ; ``[link reference_optional_value_or_call_move __GO_TO__]`` - - T const* get_ptr() const ; ``[link reference_optional_get_ptr __GO_TO__]`` - T* get_ptr() ; ``[link reference_optional_get_ptr __GO_TO__]`` - - explicit operator bool() const noexcept ; ``[link reference_optional_operator_bool __GO_TO__]`` - - bool operator!() const noexcept ; ``[link reference_optional_operator_not __GO_TO__]`` - - // deprecated methods - - // (deprecated) - void reset() noexcept ; ``[link reference_optional_reset __GO_TO__]`` - - // (deprecated) - void reset ( T const& ) ; ``[link reference_optional_reset_value __GO_TO__]`` - - // (deprecated) - bool is_initialized() const ; ``[link reference_optional_is_initialized __GO_TO__]`` - - // (deprecated) - T const& get_value_or( T const& default ) const ; ``[link reference_optional_get_value_or_value __GO_TO__]`` - }; - - template inline bool operator == ( optional const& x, optional const& y ) ; ``[link reference_operator_compare_equal_optional_optional __GO_TO__]`` - - template inline bool operator != ( optional const& x, optional const& y ) ; ``[link reference_operator_compare_not_equal_optional_optional __GO_TO__]`` - - template inline bool operator < ( optional const& x, optional const& y ) ; ``[link reference_operator_compare_less_optional_optional __GO_TO__]`` - - template inline bool operator > ( optional const& x, optional const& y ) ; ``[link reference_operator_compare_greater_optional_optional __GO_TO__]`` - - template inline bool operator <= ( optional const& x, optional const& y ) ; ``[link reference_operator_compare_less_or_equal_optional_optional __GO_TO__]`` - - template inline bool operator >= ( optional const& x, optional const& y ) ; ``[link reference_operator_compare_greater_or_equal_optional_optional __GO_TO__]`` - - template inline bool operator == ( optional const& x, none_t ) noexcept ; ``[link reference_operator_compare_equal_optional_none __GO_TO__]`` - - template inline bool operator != ( optional const& x, none_t ) noexcept ; ``[link reference_operator_compare_not_equal_optional_none __GO_TO__]`` - - template inline optional make_optional ( T const& v ) ; ``[link reference_make_optional_value __GO_TO__]`` - - template inline optional make_optional ( bool condition, T const& v ) ; ``[link reference_make_optional_bool_value __GO_TO__]`` - - template inline T const& get_optional_value_or ( optional const& opt, T const& default ) ; ``[link reference_optional_get_value_or_value __GO_TO__]`` - - template inline T const& get ( optional const& opt ) ; ``[link reference_optional_get __GO_TO__]`` - - template inline T& get ( optional & opt ) ; ``[link reference_optional_get __GO_TO__]`` - - template inline T const* get ( optional const* opt ) ; ``[link reference_optional_get __GO_TO__]`` - - template inline T* get ( optional* opt ) ; ``[link reference_optional_get __GO_TO__]`` - - template inline T const* get_pointer ( optional const& opt ) ; ``[link reference_optional_get_ptr __GO_TO__]`` - - template inline T* get_pointer ( optional & opt ) ; ``[link reference_optional_get_ptr __GO_TO__]`` - - template inline void swap( optional& x, optional& y ) ; ``[link reference_swap_optional_optional __GO_TO__]`` - - } // namespace boost - - -[endsect] - [section Detailed Semantics] Because `T` might be of reference type, in the sequel, those entries whose diff --git a/doc/29_ref_optional_convenience.qbk b/doc/29_ref_optional_convenience.qbk new file mode 100644 index 0000000..63b4732 --- /dev/null +++ b/doc/29_ref_optional_convenience.qbk @@ -0,0 +1,17 @@ +[/ + Boost.Optional + + Copyright (c) 2003-2007 Fernando Luis Cacciola Carballal + Copyright (c) 2015 Andrzej Krzemienski + + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +] + +[section Header ] + +This is an alias for header [link boost_optional.reference.header__boost_optional_optional_hpp_.header_optional_optional ``]. + + +[endsect] diff --git a/doc/html/boost_optional/dependencies_and_portability.html b/doc/html/boost_optional/dependencies_and_portability.html index 06b31e5..7c30637 100644 --- a/doc/html/boost_optional/dependencies_and_portability.html +++ b/doc/html/boost_optional/dependencies_and_portability.html @@ -6,7 +6,7 @@ - + @@ -20,7 +20,7 @@
    -PrevUpHomeNext +PrevUpHomeNext

    @@ -83,7 +83,7 @@
    -PrevUpHomeNext +PrevUpHomeNext
    diff --git a/doc/html/boost_optional/reference/detailed_semantics.html b/doc/html/boost_optional/reference/detailed_semantics.html deleted file mode 100644 index 3f4bd8d..0000000 --- a/doc/html/boost_optional/reference/detailed_semantics.html +++ /dev/null @@ -1,2337 +0,0 @@ - - - -Detailed Semantics - - - - - - - - - - - - - - - -
    Boost C++ LibrariesHomeLibrariesPeopleFAQMore
    -
    -
    -PrevUpHomeNext -
    -
    - -

    - Because T might be of reference - type, in the sequel, those entries whose semantic depends on T being of reference type or not will be - distinguished using the following convention: -

    -
      -
    • - If the entry reads: optional<T(not - a ref)>, the - description corresponds only to the case where T - is not of reference type. -
    • -
    • - If the entry reads: optional<T&>, the description corresponds - only to the case where T - is of reference type. -
    • -
    • - If the entry reads: optional<T>, the description is the same for - both cases. -
    • -
    -
    - - - - - -
    [Note]Note

    - The following section contains various assert() which are used only to show the postconditions - as sample code. It is not implied that the type T - must support each particular expression but that if the expression is supported, - the implied condition holds. -

    -

    - space -

    -
    - - optional - class member functions -
    -

    - space -

    -

    - optional<T>::optional() - noexcept; -

    -
      -
    • - Effect: Default-Constructs an optional. -
    • -
    • - Postconditions: *this is uninitialized. -
    • -
    • - Notes: T's default constructor is not called. -
    • -
    • - Example: -
      optional<T> def ;
      -assert ( !def ) ;
      -
      -
    • -
    -

    - space -

    -

    - optional<T>::optional( none_t ) noexcept; -

    -
      -
    • - Effect: Constructs an optional uninitialized. -
    • -
    • - Postconditions: *this is uninitialized. -
    • -
    • - Notes: T's - default constructor is not called. - The expression boost::none - denotes an instance of boost::none_t - that can be used as the parameter. -
    • -
    • - Example: -
      #include <boost/none.hpp>
      -optional<T> n(none) ;
      -assert ( !n ) ;
      -
      -
    • -
    -

    - space -

    -

    - optional<T (not a ref)>::optional( T const& v ) -

    -
      -
    • - Requires: is_copy_constructible<T>::value - is true. -
    • -
    • - Effect: Directly-Constructs an optional. -
    • -
    • - Postconditions: *this is initialized - and its value is a copy of v. -
    • -
    • - Throws: Whatever T::T( T const& ) throws. -
    • -
    • - Notes: T::T( T const& ) is called. -
    • -
    • - Exception Safety: Exceptions can only - be thrown during T::T( T const& ); - in that case, this constructor has no effect. -
    • -
    • - Example: -
      T v;
      -optional<T> opt(v);
      -assert ( *opt == v ) ;
      -
      -
    • -
    -

    - space -

    -

    - optional<T&>::optional( T& ref ) -

    -
      -
    • - Effect: Directly-Constructs an optional. -
    • -
    • - Postconditions: *this is initialized - and its value is an instance of an internal type wrapping the reference - ref. -
    • -
    • - Throws: Nothing. -
    • -
    • - Example: -
      T v;
      -T& vref = v ;
      -optional<T&> opt(vref);
      -assert ( *opt == v ) ;
      -++ v ; // mutate referee
      -assert (*opt == v);
      -
      -
    • -
    -

    - space -

    -

    - optional<T (not a ref)>::optional( T&& - v ) -

    -
      -
    • - Requires: is_move_constructible<T>::value - is true. -
    • -
    • - Effect: Directly-Move-Constructs an - optional. -
    • -
    • - Postconditions: *this is initialized - and its value is move-constructed from v. -
    • -
    • - Throws: Whatever T::T( T&& ) - throws. -
    • -
    • - Notes: T::T( T&& ) - is called. -
    • -
    • - Exception Safety: Exceptions can only - be thrown during T::T( T&& - ); in that case, the state of - v is determined by exception - safety guarantees for T::T(T&&). -
    • -
    • - Example: -
      T v1, v2;
      -optional<T> opt(std::move(v1));
      -assert ( *opt == v2 ) ;
      -
      -
    • -
    -

    - space -

    -

    - optional<T&>::optional( T&& - ref ) - = delete -

    -
    • - Notes: This constructor is deleted -
    -

    - space -

    -

    - optional<T (not a ref)>::optional( bool condition, - T const& v ) ; -

    -

    - optional<T&> - ::optional( bool condition, - T& - v ) - ; -

    -
    • - If condition is true, same as: -
    -

    - optional<T (not a ref)>::optional( T const& v ) -

    -

    - optional<T&> - ::optional( T& - v ) -

    -
    • - otherwise, same as: -
    -

    - optional<T (not a ref)>::optional() -

    -

    - optional<T&> - ::optional() -

    -

    - space -

    -

    - optional<T (not a ref)>::optional( optional - const& - rhs ); -

    -
      -
    • - Requires: is_copy_constructible<T>::value - is true. -
    • -
    • - Effect: Copy-Constructs an optional. -
    • -
    • - Postconditions: If rhs is initialized, - *this - is initialized and its value is a copy of the value - of rhs; else *this - is uninitialized. -
    • -
    • - Throws: Whatever T::T( T const& ) throws. -
    • -
    • - Notes: If rhs is initialized, T::T(T const& ) - is called. -
    • -
    • - Exception Safety: Exceptions can only - be thrown during T::T( T const& ); - in that case, this constructor has no effect. -
    • -
    • - Example: -
      optional<T> uninit ;
      -assert (!uninit);
      -
      -optional<T> uinit2 ( uninit ) ;
      -assert ( uninit2 == uninit );
      -
      -optional<T> init( T(2) );
      -assert ( *init == T(2) ) ;
      -
      -optional<T> init2 ( init ) ;
      -assert ( init2 == init ) ;
      -
      -
    • -
    -

    - space -

    -

    - optional<T&>::optional( optional const& rhs ); -

    -
      -
    • - Effect: Copy-Constructs an optional. -
    • -
    • - Postconditions: If rhs - is initialized, *this - is initialized and its value is another reference to the same object - referenced by *rhs; - else *this - is uninitialized. -
    • -
    • - Throws: Nothing. -
    • -
    • - Notes: If rhs - is initialized, both *this - and *rhs - will refer to the same object (they alias). -
    • -
    • - Example: -
      optional<T&> uninit ;
      -assert (!uninit);
      -
      -optional<T&> uinit2 ( uninit ) ;
      -assert ( uninit2 == uninit );
      -
      -T v = 2 ; T& ref = v ;
      -optional<T> init(ref);
      -assert ( *init == v ) ;
      -
      -optional<T> init2 ( init ) ;
      -assert ( *init2 == v ) ;
      -
      -v = 3 ;
      -
      -assert ( *init  == 3 ) ;
      -assert ( *init2 == 3 ) ;
      -
      -
    • -
    -

    - space -

    -

    - optional<T (not a ref)>::optional( optional&& rhs - ) noexcept(see below); -

    -
      -
    • - Requires: is_move_constructible<T>::value - is true. -
    • -
    • - Effect: Move-constructs an optional. -
    • -
    • - Postconditions: If rhs - is initialized, *this - is initialized and its value is move constructed from rhs; - else *this - is uninitialized. -
    • -
    • - Throws: Whatever T::T( T&& ) - throws. -
    • -
    • - Remarks: The expression inside noexcept is equivalent to is_nothrow_move_constructible<T>::value. -
    • -
    • - Notes: If rhs - is initialized, T::T( T && - ) is called. -
    • -
    • - Exception Safety: Exceptions can only - be thrown during T::T( T&& - ); in that case, rhs remains initialized and the value - of *rhs - is determined by exception safety of T::T(T&&). -
    • -
    • - Example: -
      optional<std::unique_ptr<T>> uninit ;
      -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)) );
      -assert ( **init == T(2) ) ;
      -
      -optional<std::unique_ptr<T>> init2 ( std::move(init) ) ;
      -assert ( init );
      -assert ( *init == nullptr );
      -assert ( init2 );
      -assert ( **init2 == T(2) ) ;
      -
      -
    • -
    -

    - space -

    -

    - optional<T&>::optional( optional && - rhs ); -

    -
      -
    • - Effect: Move-Constructs an optional. -
    • -
    • - Postconditions: If rhs - is initialized, *this - is initialized and its value is another reference to the same object - referenced by *rhs; - else *this - is uninitialized. -
    • -
    • - Throws: Nothing. -
    • -
    • - Notes: If rhs - is initialized, both *this - and *rhs - will refer to the same object (they alias). -
    • -
    • - Example: -
      optional<std::unique_ptr<T>&> uninit ;
      -assert (!uninit);
      -
      -optional<std::unique_ptr<T>&> uinit2 ( std::move(uninit) ) ;
      -assert ( uninit2 == uninit );
      -
      -std::unique_ptr<T> v(new T(2)) ;
      -optional<std::unique_ptr<T>&> init(v);
      -assert ( *init == v ) ;
      -
      -optional<std::unique_ptr<T>&> init2 ( std::move(init) ) ;
      -assert ( *init2 == v ) ;
      -
      -*v = 3 ;
      -
      -assert ( **init  == 3 ) ;
      -assert ( **init2 == 3 ) ;
      -
      -
    • -
    -

    - space -

    -

    - template<U> explicit optional<T - (not a ref)>::optional( optional<U> const& rhs ); -

    -
      -
    • - Effect: Copy-Constructs an optional. -
    • -
    • - Postconditions: If rhs - is initialized, *this - is initialized and its value is a copy of the value - of rhs converted to type T; - else *this - is uninitialized. -
    • -
    • - Throws: Whatever T::T( U const& ) throws. -
    • -
    • - Notes: T::T( U const& ) is called if rhs - is initialized, which requires a valid conversion from U to T. -
    • -
    • - Exception Safety: Exceptions can only - be thrown during T::T( U const& ); - in that case, this constructor has no effect. -
    • -
    • - Example: -
      optional<double> x(123.4);
      -assert ( *x == 123.4 ) ;
      -
      -optional<int> y(x) ;
      -assert( *y == 123 ) ;
      -
      -
    • -
    -

    - space -

    -

    - template<U> explicit optional<T - (not a ref)>::optional( optional<U>&& - rhs ); -

    -
      -
    • - Effect: Move-constructs an optional. -
    • -
    • - Postconditions: If rhs - is initialized, *this - is initialized and its value is move-constructed from *rhs; else *this is uninitialized. -
    • -
    • - Throws: Whatever T::T( U&& ) - throws. -
    • -
    • - Notes: T::T( U&& ) - is called if rhs is initialized, - which requires a valid conversion from U - to T. -
    • -
    • - Exception Safety: Exceptions can only - be thrown during T::T( U&& - ); in that case, rhs remains initialized and the value - of *rhs - is determined by exception safety guarantee of T::T( U&& ). -
    • -
    • - Example: -
      optional<double> x(123.4);
      -assert ( *x == 123.4 ) ;
      -
      -optional<int> y(std::move(x)) ;
      -assert( *y == 123 ) ;
      -
      -
    • -
    -

    - space -

    -

    - template<InPlaceFactory> - explicit optional<T - (not a ref)>::optional( InPlaceFactory const& f ); -

    -

    - template<TypedInPlaceFactory> - explicit optional<T - (not a ref)>::optional( TypedInPlaceFactory const& f ); -

    -
      -
    • - Effect: Constructs an optional with a value of T obtained from the factory. -
    • -
    • - Postconditions: *this is initialized - and its value is directly given from the factory - f (i.e., the value is not copied). -
    • -
    • - Throws: Whatever the T - constructor called by the factory throws. -
    • -
    • - Notes: See In-Place - Factories -
    • -
    • - Exception Safety: Exceptions can only - be thrown during the call to the T - constructor used by the factory; in that case, this constructor has no - effect. -
    • -
    • - Example: -
      class C { C ( char, double, std::string ) ; } ;
      -
      -C v('A',123.4,"hello");
      -
      -optional<C> x( in_place   ('A', 123.4, "hello") ); // InPlaceFactory used
      -optional<C> y( in_place<C>('A', 123.4, "hello") ); // TypedInPlaceFactory used
      -
      -assert ( *x == v ) ;
      -assert ( *y == v ) ;
      -
      -
    • -
    -

    - space -

    -

    - optional& - optional<T>::operator= ( none_t ) noexcept; -

    -
      -
    • - Effect: If *this is initialized destroys its contained - value. -
    • -
    • - Postconditions: *this is uninitialized. -
    • -
    -

    - space -

    -

    - optional& - optional<T (not a ref)>::operator= ( T - const& - rhs ) - ; -

    -
      -
    • - Effect: Assigns the value rhs to an optional. -
    • -
    • - Postconditions: *this is initialized and its value is a - copy of rhs. -
    • -
    • - Throws: Whatever T::operator=( T const& ) or T::T(T const&) - throws. -
    • -
    • - Notes: If *this was initialized, T's - assignment operator is used, otherwise, its copy-constructor is used. -
    • -
    • - Exception Safety: In the event of an - exception, the initialization state of *this is unchanged and its value unspecified - as far as optional is - concerned (it is up to T's - operator=()). - If *this - is initially uninitialized and T's - copy constructor fails, *this is left properly uninitialized. -
    • -
    • - Example: -
      T x;
      -optional<T> def ;
      -optional<T> opt(x) ;
      -
      -T y;
      -def = y ;
      -assert ( *def == y ) ;
      -opt = y ;
      -assert ( *opt == y ) ;
      -
      -
    • -
    -

    - space -

    -

    - optional<T&>& - optional<T&>::operator= ( T& - rhs ) - ; -

    -
      -
    • - Effect: (Re)binds the wrapped reference. -
    • -
    • - Postconditions: *this is initialized and it references - the same object referenced by rhs. -
    • -
    • - Notes: If *this was initialized, it is rebound - to the new object. See here - for details on this behavior. -
    • -
    • - Example: -
      int a = 1 ;
      -int b = 2 ;
      -T& ra = a ;
      -T& rb = b ;
      -optional<int&> def ;
      -optional<int&> opt(ra) ;
      -
      -def = rb ; // binds 'def' to 'b' through 'rb'
      -assert ( *def == b ) ;
      -*def = a ; // changes the value of 'b' to a copy of the value of 'a'
      -assert ( b == a ) ;
      -int c = 3;
      -int& rc = c ;
      -opt = rc ; // REBINDS to 'c' through 'rc'
      -c = 4 ;
      -assert ( *opt == 4 ) ;
      -
      -
    • -
    -

    - space -

    -

    - optional& - optional<T (not a ref)>::operator= ( T&& rhs - ) ; -

    -
      -
    • - Effect: Moves the value rhs to an optional. -
    • -
    • - Postconditions: *this is initialized and its value is moved - from rhs. -
    • -
    • - Throws: Whatever T::operator=( T&& ) - or T::T(T &&) - throws. -
    • -
    • - Notes: If *this was initialized, T's - move-assignment operator is used, otherwise, its move-constructor is - used. -
    • -
    • - Exception Safety: In the event of an - exception, the initialization state of *this is unchanged and its value unspecified - as far as optional is - concerned (it is up to T's - operator=()). - If *this - is initially uninitialized and T's - move constructor fails, *this is left properly uninitialized. -
    • -
    • - Example: -
      T x;
      -optional<T> def ;
      -optional<T> opt(x) ;
      -
      -T y1, y2, yR;
      -def = std::move(y1) ;
      -assert ( *def == yR ) ;
      -opt = std::move(y2) ;
      -assert ( *opt == yR ) ;
      -
      -
    • -
    -

    - space -

    -

    - optional<T&>& - optional<T&>::operator= ( T&& - rhs ) - = delete; -

    -
    • - Notes: This assignment operator is deleted. -
    -

    - space -

    -

    - optional& - optional<T (not a ref)>::operator= ( optional - const& - rhs ) - ; -

    -
      -
    • - Requires: T - is CopyConstructible and CopyAssignable. -
    • -
    • -

      - Effects: -

      -
      ----- - - - - - - - - - - - - - - - - - -
      - -

      - *this - contains a value -

      -
      -

      - *this - does not contain a value -

      -
      -

      - rhs contains - a value -

      -
      -

      - assigns *rhs - to the contained value -

      -
      -

      - initializes the contained value as if direct-initializing an - object of type T - with *rhs -

      -
      -

      - rhs does not - contain a value -

      -
      -

      - destroys the contained value by calling val->T::~T() -

      -
      -

      - no effect -

      -
      -
    • -
    • - Returns: *this; -
    • -
    • - Postconditions: bool(rhs) == bool(*this). -
    • -
    • - Exception Safety: If any exception is - thrown, the initialization state of *this and rhs - remains unchanged. If an exception is thrown during the call to T's copy constructor, no effect. If - an exception is thrown during the call to T's - copy assignment, the state of its contained value is as defined by the - exception safety guarantee of T's - copy assignment. -
    • -
    • - Example: -
      T v;
      -optional<T> opt(v);
      -optional<T> def ;
      -
      -opt = def ;
      -assert ( !def ) ;
      -// previous value (copy of 'v') destroyed from within 'opt'.
      -
      -
    • -
    -

    - space -

    -

    - optional<T&> - & optional<T&>::operator= ( optional<T&> const& rhs ) ; -

    -
      -
    • - Effect: (Re)binds thee wrapped reference. -
    • -
    • - Postconditions: If *rhs is initialized, *this is initialized and it references - the same object referenced by *rhs; otherwise, *this is uninitialized (and references - no object). -
    • -
    • - Notes: If *this was initialized and so is *rhs, - *this - is rebound to the new object. See here - for details on this behavior. -
    • -
    • - Example: -
      int a = 1 ;
      -int b = 2 ;
      -T& ra = a ;
      -T& rb = b ;
      -optional<int&> def ;
      -optional<int&> ora(ra) ;
      -optional<int&> orb(rb) ;
      -
      -def = orb ; // binds 'def' to 'b' through 'rb' wrapped within 'orb'
      -assert ( *def == b ) ;
      -*def = ora ; // changes the value of 'b' to a copy of the value of 'a'
      -assert ( b == a ) ;
      -int c = 3;
      -int& rc = c ;
      -optional<int&> orc(rc) ;
      -ora = orc ; // REBINDS ora to 'c' through 'rc'
      -c = 4 ;
      -assert ( *ora == 4 ) ;
      -
      -
    • -
    -

    - space -

    -

    - optional& - optional<T (not a ref)>::operator= ( optional&& rhs - ) noexcept(see below); -

    -
      -
    • - Requires: T - is MoveConstructible - and MoveAssignable. -
    • -
    • -

      - Effects: -

      -
      ----- - - - - - - - - - - - - - - - - - -
      - -

      - *this - contains a value -

      -
      -

      - *this - does not contain a value -

      -
      -

      - rhs contains - a value -

      -
      -

      - assigns std::move(*rhs) to the contained value -

      -
      -

      - initializes the contained value as if direct-initializing an - object of type T - with std::move(*rhs) -

      -
      -

      - rhs does not - contain a value -

      -
      -

      - destroys the contained value by calling val->T::~T() -

      -
      -

      - no effect -

      -
      -
    • -
    • - Returns: *this; -
    • -
    • - Postconditions: bool(rhs) == bool(*this). -
    • -
    • - Remarks: The expression inside noexcept is equivalent to is_nothrow_move_constructible<T>::value && - is_nothrow_move_assignable<T>::value. -
    • -
    • - Exception Safety: If any exception is - thrown, the initialization state of *this and rhs - remains unchanged. If an exception is thrown during the call to T's move constructor, the state of - *rhs - is determined by the exception safety guarantee of T's - move constructor. If an exception is thrown during the call to T's move-assignment, - the state of **this - and *rhs - is determined by the exception safety guarantee of T's move assignment. -
    • -
    • - Example: -
      optional<T> opt(T(2)) ;
      -optional<T> def ;
      -
      -opt = def ;
      -assert ( def ) ;
      -assert ( opt ) ;
      -assert ( *opt == T(2) ) ;
      -
      -
    • -
    -

    - space -

    -

    - optional<T&> - & optional<T&>::operator= ( optional<T&>&& rhs - ) ; -

    -
    • - Effect: Same as optional<T&>::operator= ( optional<T&> const& rhs - ). -
    -

    - space -

    -

    - template<U> optional& - optional<T (not a ref)>::operator= ( optional<U> const& rhs ) ; -

    -
      -
    • -

      - Effect: -

      -
      ----- - - - - - - - - - - - - - - - - - -
      - -

      - *this - contains a value -

      -
      -

      - *this - does not contain a value -

      -
      -

      - rhs contains - a value -

      -
      -

      - assigns *rhs - to the contained value -

      -
      -

      - initializes the contained value as if direct-initializing an - object of type T - with *rhs -

      -
      -

      - rhs does not - contain a value -

      -
      -

      - destroys the contained value by calling val->T::~T() -

      -
      -

      - no effect -

      -
      -
    • -
    • - Returns: *this. -
    • -
    • - Postconditions: bool(rhs) == bool(*this). -
    • -
    • - Exception Safety: If any exception is - thrown, the result of the expression bool(*this) remains unchanged. If an exception is - thrown during the call to T's - constructor, no effect. If an exception is thrown during the call to - T's assignment, the state - of its contained value is as defined by the exception safety guarantee - of T's copy assignment. -
    • -
    • - Example: -
      T v;
      -optional<T> opt0(v);
      -optional<U> opt1;
      -
      -opt1 = opt0 ;
      -assert ( *opt1 == static_cast<U>(v) ) ;
      -
      -
    • -
    -

    - space -

    -

    - template<U> optional& - optional<T (not a ref)>::operator= ( optional<U>&& rhs - ) ; -

    -
      -
    • -

      - Effect: -

      -
      ----- - - - - - - - - - - - - - - - - - -
      - -

      - *this - contains a value -

      -
      -

      - *this - does not contain a value -

      -
      -

      - rhs contains - a value -

      -
      -

      - assigns std::move(*rhs) to the contained value -

      -
      -

      - initializes the contained value as if direct-initializing an - object of type T - with std::move(*rhs) -

      -
      -

      - rhs does not - contain a value -

      -
      -

      - destroys the contained value by calling val->T::~T() -

      -
      -

      - no effect -

      -
      -
    • -
    • - Returns: *this. -
    • -
    • - Postconditions: bool(rhs) == bool(*this). -
    • -
    • - Exception Safety: If any exception is - thrown, the result of the expression bool(*this) remains unchanged. If an exception is - thrown during the call to T's - constructor, no effect. If an exception is thrown during the call to - T's assignment, the state - of its contained value is as defined by the exception safety guarantee - of T's copy assignment. -
    • -
    • - Example: -
      T v;
      -optional<T> opt0(v);
      -optional<U> opt1;
      -
      -opt1 = std::move(opt0) ;
      -assert ( opt0 );
      -assert ( opt1 )
      -assert ( *opt1 == static_cast<U>(v) ) ;
      -
      -
    • -
    -

    - space -

    -

    - template<class... Args> void optional<T - (not a ref)>::emplace( Args...&& - args ); -

    -
      -
    • - Requires: The compiler supports rvalue - references and variadic templates. -
    • -
    • - Effect: If *this is initialized calls *this = none. - Then initializes in-place the contained value as if direct-initializing - an object of type T with - std::forward<Args>(args).... -
    • -
    • - Postconditions: *this is initialized. -
    • -
    • - Throws: Whatever the selected T's constructor throws. -
    • -
    • - Notes: T - need not be MoveConstructible - or MoveAssignable. On - compilers that do not support variadic templates, the signature falls - back to single-argument: template<class Arg> void emplace(Arg&& arg). On compilers that do not support rvalue - references, the signature falls back to two overloads: taking const and non-const - lvalue reference. -
    • -
    • - Exception Safety: If an exception is - thrown during the initialization of T, - *this - is uninitialized. -
    • -
    • - Example: -
      T v;
      -optional<const T> opt;
      -opt.emplace(0);  // create in-place using ctor T(int)
      -opt.emplace();   // destroy previous and default-construct another T
      -opt.emplace(v);  // destroy and copy-construct in-place (no assignment called)
      -
      -
    • -
    -

    - space -

    -

    - template<InPlaceFactory> - optional<T>& - optional<T (not a ref)>::operator=( InPlaceFactory - const& - f ); -

    -

    - template<TypedInPlaceFactory> - optional<T>& - optional<T (not a ref)>::operator=( TypedInPlaceFactory - const& - f ); -

    -
      -
    • - Effect: Assigns an optional - with a value of T obtained - from the factory. -
    • -
    • - Postconditions: *this is initialized - and its value is directly given from the factory - f (i.e., the value is not copied). -
    • -
    • - Throws: Whatever the T - constructor called by the factory throws. -
    • -
    • - Notes: See In-Place - Factories -
    • -
    • - Exception Safety: Exceptions can only - be thrown during the call to the T - constructor used by the factory; in that case, the optional - object will be reset to be uninitialized. -
    • -
    -

    - space -

    -

    - void optional<T - (not a ref)>::reset( T const& v ) ; -

    -
    • - Deprecated: same as operator= ( T - const& - v) - ; -
    -

    - space -

    -

    - void optional<T>::reset() noexcept ; -

    -
    • - Deprecated: Same as operator=( none_t - ); -
    -

    - space -

    -

    - T const& optional<T - (not a ref)>::get() const ; -

    -

    - T& - optional<T (not a ref)>::get() ; -

    -

    - inline T - const& - get ( - optional<T (not a ref)> const& ) ; -

    -

    - inline T& get ( optional<T - (not a ref)> - &) ; -

    -
      -
    • - Requires: *this is initialized -
    • -
    • - Returns: A reference to the contained - value -
    • -
    • - Throws: Nothing. -
    • -
    • - Notes: The requirement is asserted via - BOOST_ASSERT(). -
    • -
    -

    - space -

    -

    - T const& optional<T&>::get() const ; -

    -

    - T& - optional<T&>::get() ; -

    -

    - inline T - const& - get ( - optional<T&> - const& - ) ; -

    -

    - inline T& get ( optional<T&> &) - ; -

    -
      -
    • - Requires: *this is initialized -
    • -
    • - Returns: The - reference contained. -
    • -
    • - Throws: Nothing. -
    • -
    • - Notes: The requirement is asserted via - BOOST_ASSERT(). -
    • -
    -

    - space -

    -

    - T const& optional<T - (not a ref)>::operator*() const& ; -

    -

    - T& - optional<T (not a ref)>::operator*() &; -

    -
      -
    • - Requires: *this is initialized -
    • -
    • - Returns: A reference to the contained - value -
    • -
    • - Throws: Nothing. -
    • -
    • - Notes: The requirement is asserted via - BOOST_ASSERT(). - On compilers that do not support ref-qualifiers on member functions these - two overloads are replaced with the classical two: a const - and non-const member functions. -
    • -
    • - Example: -
      T v ;
      -optional<T> opt ( v );
      -T const& u = *opt;
      -assert ( u == v ) ;
      -T w ;
      -*opt = w ;
      -assert ( *opt == w ) ;
      -
      -
    • -
    -

    - space -

    -

    - T&& - optional<T (not a ref)>::operator*() &&; -

    -
      -
    • - Requires: *this contains a value. -
    • -
    • - Effects: Equivalent to return std::move(*val);. -
    • -
    • - Notes: The requirement is asserted via - BOOST_ASSERT(). - On compilers that do not support ref-qualifiers on member functions this - overload is not present. -
    • -
    -

    - space -

    -

    - T & - optional<T&>::operator*() const& ; -

    -

    - T & - optional<T&>::operator*() & ; -

    -

    - T & - optional<T&>::operator*() && ; -

    -
      -
    • - Requires: *this is initialized -
    • -
    • - Returns: The - reference contained. -
    • -
    • - Throws: Nothing. -
    • -
    • - Notes: The requirement is asserted via - BOOST_ASSERT(). - On compilers that do not support ref-qualifiers on member functions these - three overloads are replaced with the classical two: a const and non-const - member functions. -
    • -
    • - Example: -
      T v ;
      -T& vref = v ;
      -optional<T&> opt ( vref );
      -T const& vref2 = *opt;
      -assert ( vref2 == v ) ;
      -++ v ;
      -assert ( *opt == v ) ;
      -
      -
    • -
    -

    - space -

    -

    - T const& optional<T>::value() const& ; -

    -

    - T& - optional<T>::value() & ; -

    -
      -
    • - Effects: Equivalent to return bool(*this) ? *val : throw bad_optional_access();. -
    • -
    • - Notes: On compilers that do not support - ref-qualifiers on member functions these two overloads are replaced with - the classical two: a const - and non-const member functions. -
    • -
    • - Example: -
      T v ;
      -optional<T> o0, o1 ( v );
      -assert ( o1.value() == v );
      -
      -try {
      -  o0.value(); // throws
      -  assert ( false );
      -}
      -catch(bad_optional_access&) {
      -  assert ( true );
      -}
      -
      -
    • -
    -

    - space -

    -

    - T&& - optional<T>::value() && ; -

    -
      -
    • - Effects: Equivalent to return bool(*this) ? std::move(*val) : throw - bad_optional_access();. -
    • -
    • - Notes: On compilers that do not support - ref-qualifiers on member functions this overload is not present. -
    • -
    -

    - space -

    -

    - template<class U> T optional<T>::value_or(U && - v) - const& - ; -

    -
      -
    • - Effects: Equivalent to if (*this) return **this; else return - std::forward<U>(v);. -
    • -
    • - Remarks: If T - is not CopyConstructible or U && - is not convertible to T, - the program is ill-formed. -
    • -
    • - Notes: On compilers that do not support - ref-qualifiers on member functions this overload is replaced with the - const-qualified member function. - On compilers without rvalue reference support the type of v becomes U - const&. -
    • -
    -

    - space -

    -

    - template<class U> T optional<T>::value_or(U && - v) - && ; -

    -
      -
    • - Effects: Equivalent to if (*this) return std::move(**this); else return std::forward<U>(v);. -
    • -
    • - Remarks: If T - is not MoveConstructible - or U && - is not convertible to T, - the program is ill-formed. -
    • -
    • - Notes: On compilers that do not support - ref-qualifiers on member functions this overload is not present. -
    • -
    -

    - space -

    -

    - template<class F> T optional<T>::value_or_eval(F f) const& ; -

    -
      -
    • - Requires: T - is CopyConstructible and F models a Generator whose result type - is convertible to T. -
    • -
    • - Effects: if - (*this) return **this; else return f();. -
    • -
    • - Notes: On compilers that do not support - ref-qualifiers on member functions this overload is replaced with the - const-qualified member function. -
    • -
    • - Example: -
      int complain_and_0()
      -{
      -  clog << "no value returned, using default" << endl;
      -  return 0;
      -}
      -
      -optional<int> o1 = 1;
      -optional<int> oN = none;
      -
      -int i = o1.value_or_eval(complain_and_0); // fun not called
      -assert (i == 1);
      -
      -int j = oN.value_or_eval(complain_and_0); // fun called
      -assert (i == 0);
      -
      -
    • -
    -

    - space -

    -

    - template<class F> T optional<T>::value_or_eval(F f) && ; -

    -
      -
    • - Requires: T - is MoveConstructible - and F models a Generator - whose result type is convertible to T. -
    • -
    • - Effects: if - (*this) return std::move(**this); else return - f();. -
    • -
    • - Notes: On compilers that do not support - ref-qualifiers on member functions this overload is not present. -
    • -
    -

    - space -

    -

    - T const& optional<T - (not a ref)>::get_value_or( - T const& default) const ; -

    -

    - T& - optional<T (not a ref)>::get_value_or( T& - default ) - ; -

    -

    - inline T - const& - get_optional_value_or ( - optional<T (not a ref)> const& o, T const& default ) ; -

    -

    - inline T& get_optional_value_or - ( optional<T - (not a ref)>& - o, - T& - default ) - ; -

    -
      -
    • - Deprecated: Use value_or() instead. -
    • -
    • - Returns: A reference to the contained - value, if any, or default. -
    • -
    • - Throws: Nothing. -
    • -
    • - Example: -
      T v, z ;
      -optional<T> def;
      -T const& y = def.get_value_or(z);
      -assert ( y == z ) ;
      -
      -optional<T> opt ( v );
      -T const& u = get_optional_value_or(opt,z);
      -assert ( u == v ) ;
      -assert ( u != z ) ;
      -
      -
    • -
    -

    - space -

    -

    - T const* optional<T - (not a ref)>::get_ptr() const ; -

    -

    - T* - optional<T (not a ref)>::get_ptr() ; -

    -

    - inline T - const* - get_pointer ( - optional<T (not a ref)> const& ) ; -

    -

    - inline T* get_pointer - ( optional<T - (not a ref)> - &) ; -

    -
      -
    • - Returns: If *this is initialized, a pointer to the - contained value; else 0 (null). -
    • -
    • - Throws: Nothing. -
    • -
    • - Notes: The contained value is permanently - stored within *this, - so you should not hold nor delete this pointer -
    • -
    • - Example: -
      T v;
      -optional<T> opt(v);
      -optional<T> const copt(v);
      -T* p = opt.get_ptr() ;
      -T const* cp = copt.get_ptr();
      -assert ( p == get_pointer(opt) );
      -assert ( cp == get_pointer(copt) ) ;
      -
      -
    • -
    -

    - space -

    -

    - T const* optional<T - (not a ref)>::operator ->() - const ; -

    -

    - T* - optional<T (not a ref)>::operator - ->() ; -

    -
      -
    • - Requires: *this is initialized. -
    • -
    • - Returns: A pointer to the contained - value. -
    • -
    • - Throws: Nothing. -
    • -
    • - Notes: The requirement is asserted via - BOOST_ASSERT(). -
    • -
    • - Example: -
      struct X { int mdata ; } ;
      -X x ;
      -optional<X> opt (x);
      -opt->mdata = 2 ;
      -
      -
    • -
    -

    - space -

    -

    - explicit optional<T>::operator - bool() - const noexcept - ; -

    -
      -
    • - Returns: get_ptr() != 0. -
    • -
    • - Notes: On compilers that do not support - explicit conversion operators this falls back to safe-bool idiom. -
    • -
    • - Example: -
      optional<T> def ;
      -assert ( def == 0 );
      -optional<T> opt ( v ) ;
      -assert ( opt );
      -assert ( opt != 0 );
      -
      -
    • -
    -

    - space -

    -

    - bool optional<T>::operator!() noexcept ; -

    -
      -
    • - Returns: If *this is uninitialized, true; - else false. -
    • -
    • - Notes: This operator is provided for - those compilers which can't use the unspecified-bool-type operator - in certain boolean contexts. -
    • -
    • - Example: -
      optional<T> opt ;
      -assert ( !opt );
      -*opt = some_T ;
      -
      -// Notice the "double-bang" idiom here.
      -assert ( !!opt ) ;
      -
      -
    • -
    -

    - space -

    -

    - bool optional<T>::is_initialized() const ; -

    -
    • - Deprecated: Same as explicit - operator bool - () ; -
    -

    - space -

    -
    - - Free - functions -
    -

    - space -

    -

    - optional<T (not a ref)> make_optional( T const& v ) -

    -
      -
    • - Returns: optional<T>(v) for the deduced - type T of v. -
    • -
    • - Example: -
      template<class T> void foo ( optional<T> const& opt ) ;
      -
      -foo ( make_optional(1+1) ) ; // Creates an optional<int>
      -
      -
    • -
    -

    - space -

    -

    - optional<T (not a ref)> make_optional( bool condition, - T const& v ) -

    -
      -
    • - Returns: optional<T>(condition,v) for the deduced - type T of v. -
    • -
    • - Example: -
      optional<double> calculate_foo()
      -{
      -  double val = compute_foo();
      -  return make_optional(is_not_nan_and_finite(val),val);
      -}
      -
      -optional<double> v = calculate_foo();
      -if ( !v )
      -  error("foo wasn't computed");
      -
      -
    • -
    -

    - space -

    -

    - bool operator - == ( optional<T> const& x, optional<T> const& y ); -

    -
      -
    • - Requires: T - shall meet requirements of EqualityComparable. -
    • -
    • - Returns: If both x - and y are initialized, - (*x - == *y). - If only x or y is initialized, false. - If both are uninitialized, true. -
    • -
    • - Notes: This definition guarantees that - optional<T> - not containing a value is compared unequal to any optional<T> containing any value, and equal 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 equal_pointees() - instead -
    • -
    • - Example: -
      optional<T> oN, oN_;
      -optional<T> o1(T(1)), o1_(T(1));
      -optional<T> o2(T(2));
      -
      -assert ( oN == oN );  // Identity implies equality
      -assert ( o1 == o1 );  //
      -
      -assert ( oN == oN_ ); // Both uninitialized compare equal
      -
      -assert ( oN != o1 );  // Initialized unequal to initialized.
      -
      -assert ( o1 == o1_ ); // Both initialized compare as (*lhs == *rhs)
      -assert ( o1 != o2 );  //
      -
      -
    • -
    -

    - space -

    -

    - bool operator - < ( - optional<T> const& x, optional<T> const& y ); -

    -
      -
    • - Requires: Expression *x < *y - shall be well-formed and its result shall be convertible to bool. -
    • -
    • - 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 less_pointees() - instead. T need not be - LessThanComparable. Only single - operator< - is required. Other relational operations are defined in terms of this - one. If T's operator< - satisfies the axioms of LessThanComparable (transitivity, - antisymmetry and irreflexivity), optinal<T> is LessThanComparable. -
    • -
    • - Example: -
      optional<T> oN, oN_;
      -optional<T> o0(T(0));
      -optional<T> o1(T(1));
      -
      -assert ( !(oN < oN) );  // Identity implies equivalence
      -assert ( !(o1 < o1) );
      -
      -assert ( !(oN < oN_) ); // Two uninitialized are equivalent
      -assert ( !(oN_ < oN) );
      -
      -assert ( oN < o0 );     // Uninitialized is less than initialized
      -assert ( !(o0 < oN) );
      -
      -assert ( o1 < o2 ) ;    // Two initialized compare as (*lhs < *rhs)
      -assert ( !(o2 < o1) ) ;
      -assert ( !(o2 < o2) ) ;
      -
      -
    • -
    -

    - space -

    -

    - bool operator - != ( optional<T> const& x, optional<T> const& y ); -

    -
    • - Returns: !( - x == - y ); -
    -

    - space -

    -

    - bool operator - > ( - optional<T> const& x, optional<T> const& y ); -

    -
    • - Returns: ( - y < - x ); -
    -

    - space -

    -

    - bool operator - <= ( - optional<T> const& x, optional<T> const& y ); -

    -
    • - Returns: !( - y < - x ); -
    -

    - space -

    -

    - bool operator - >= ( - optional<T> const& x, optional<T> const& y ); -

    -
    • - Returns: !( - x < - y ); -
    -

    - space -

    -

    - bool operator - == ( optional<T> const& x, none_t - ) noexcept; -

    -

    - bool operator - == ( none_t, optional<T> const& x ) noexcept; -

    -
    -

    - space -

    -

    - bool operator - != ( optional<T> const& x, none_t - ) noexcept; -

    -

    - bool operator - != ( none_t, optional<T> const& x ) noexcept; -

    -
    • - Returns: !( - x == - y ); -
    -

    - space -

    -

    - void swap - ( optional<T>& x, optional<T>& y - ) ; -

    -
      -
    • - Requires: Lvalues of type T shall be swappable and T shall be MoveConstructible. -
    • -
    • -

      - Effects: -

      -
      ----- - - - - - - - - - - - - - - - - - -
      - -

      - *this - contains a value -

      -
      -

      - *this - does not contain a value -

      -
      -

      - rhs contains - a value -

      -
      -

      - calls swap(*(*this), *rhs) -

      -
      -

      - initializes the contained value of *this as if direct-initializing - an object of type T - with the expression std::move(*rhs), followed by rhs.val->T::~T(), - *this - contains a value and rhs - does not contain a value -

      -
      -

      - rhs does not - contain a value -

      -
      -

      - initializes the contained value of rhs - as if direct-initializing an object of type T - with the expression std::move(*(*this)), followed by val->T::~T(), - *this - does not contain a value and rhs - contains a value -

      -
      -

      - no effect -

      -
      -
    • -
    • - Postconditions: The states of x and y - interchanged. -
    • -
    • - Throws: If both are initialized, whatever - swap(T&,T&) - throws. If only one is initialized, whatever T::T ( T&& ) - throws. -
    • -
    • - Example: -
      T x(12);
      -T y(21);
      -optional<T> def0 ;
      -optional<T> def1 ;
      -optional<T> optX(x);
      -optional<T> optY(y);
      -
      -boost::swap(def0,def1); // no-op
      -
      -boost::swap(def0,optX);
      -assert ( *def0 == x );
      -assert ( !optX );
      -
      -boost::swap(def0,optX); // Get back to original values
      -
      -boost::swap(optX,optY);
      -assert ( *optX == y );
      -assert ( *optY == x );
      -
      -
    • -
    -
    - - - -
    -
    -
    -PrevUpHomeNext -
    - - diff --git a/doc/html/boost_optional/reference/header__boost_optional_bad_optional_access_hpp_.html b/doc/html/boost_optional/reference/header__boost_optional_bad_optional_access_hpp_.html new file mode 100644 index 0000000..e0d8ba9 --- /dev/null +++ b/doc/html/boost_optional/reference/header__boost_optional_bad_optional_access_hpp_.html @@ -0,0 +1,63 @@ + + + +Header <boost/optional/bad_optional_access.hpp> + + + + + + + + + + + + + + + +
    Boost C++ LibrariesHomeLibrariesPeopleFAQMore
    +
    +
    +PrevUpHomeNext +
    +
    + +
    + +

    +

    +
    namespace boost {
    +
    +class bad_optional_access : public std::logic_error
    +{
    +public:
    +    bad_optional_access(); R
    +};
    +
    +} // namespace boost
    +
    +

    +

    +
    +
    + + + +
    +
    +
    +PrevUpHomeNext +
    + + diff --git a/doc/html/boost_optional/reference/header__boost_optional_bad_optional_access_hpp_/detailed_semantics.html b/doc/html/boost_optional/reference/header__boost_optional_bad_optional_access_hpp_/detailed_semantics.html new file mode 100644 index 0000000..2b69cac --- /dev/null +++ b/doc/html/boost_optional/reference/header__boost_optional_bad_optional_access_hpp_/detailed_semantics.html @@ -0,0 +1,60 @@ + + + +Detailed semantics + + + + + + + + + + + + + + + +
    Boost C++ LibrariesHomeLibrariesPeopleFAQMore
    +
    +
    +PrevUpHomeNext +
    +
    + +

    + space +

    +

    + bad_optional_access(); +

    +
      +
    • + Effect: Constructs an object of class + bad_optional_access. +
    • +
    • + Postconditions: what() returns an implementation-defined + NTBS. +
    • +
    +
    + + + +
    +
    +
    +PrevUpHomeNext +
    + + diff --git a/doc/html/boost_optional/reference/header__boost_optional_hpp_.html b/doc/html/boost_optional/reference/header__boost_optional_hpp_.html new file mode 100644 index 0000000..19ed6cf --- /dev/null +++ b/doc/html/boost_optional/reference/header__boost_optional_hpp_.html @@ -0,0 +1,47 @@ + + + +Header <boost/optional.hpp> + + + + + + + + + + + + + + + +
    Boost C++ LibrariesHomeLibrariesPeopleFAQMore
    +
    +
    +PrevUpHomeNext +
    +
    + +

    + This is an alias for header <boost/optional/optional.hpp>. +

    +
    + + + +
    +
    +
    +PrevUpHomeNext +
    + + diff --git a/doc/html/boost_optional/reference/header__boost_optional_optional_fwd_hpp_.html b/doc/html/boost_optional/reference/header__boost_optional_optional_fwd_hpp_.html new file mode 100644 index 0000000..d87a473 --- /dev/null +++ b/doc/html/boost_optional/reference/header__boost_optional_optional_fwd_hpp_.html @@ -0,0 +1,66 @@ + + + +Header <boost/optional/optional_fwd.hpp> + + + + + + + + + + + + + + + +
    Boost C++ LibrariesHomeLibrariesPeopleFAQMore
    +
    +
    +PrevUpHomeNext +
    +
    + +
    + +

    +

    +
    namespace boost {
    +
    +template <class T> class optional ;
    +
    +template <class T> void swap ( optional<T>& , optional<T>& );
    +
    +template <class T> struct optional_swap_should_use_default_constructor ;
    +
    +} // namespace boost
    +
    +

    +

    +

    + This header only contains declarations. +

    +
    +
    + + + +
    +
    +
    +PrevUpHomeNext +
    + + diff --git a/doc/html/boost_optional/reference/header__boost_optional_optional_hpp_/detailed_semantics.html b/doc/html/boost_optional/reference/header__boost_optional_optional_hpp_/detailed_semantics.html new file mode 100644 index 0000000..a54a583 --- /dev/null +++ b/doc/html/boost_optional/reference/header__boost_optional_optional_hpp_/detailed_semantics.html @@ -0,0 +1,2387 @@ + + + +Detailed Semantics + + + + + + + + + + + + + + + +
    Boost C++ LibrariesHomeLibrariesPeopleFAQMore
    +
    +
    +PrevUpHomeNext +
    +
    + +

    + Because T might be of reference + type, in the sequel, those entries whose semantic depends on T being of reference type or not will + be distinguished using the following convention: +

    +
      +
    • + If the entry reads: optional<T(not + a ref)>, + the description corresponds only to the case where T + is not of reference type. +
    • +
    • + If the entry reads: optional<T&>, the description corresponds + only to the case where T + is of reference type. +
    • +
    • + If the entry reads: optional<T>, the description is the same for + both cases. +
    • +
    +
    + + + + + +
    [Note]Note

    + The following section contains various assert() which are used only to show the postconditions + as sample code. It is not implied that the type T + must support each particular expression but that if the expression is + supported, the implied condition holds. +

    +

    + space +

    +
    + + optional + class member functions +
    +

    + space +

    +

    + optional<T>::optional() + noexcept; +

    +
      +
    • + Effect: Default-Constructs an optional. +
    • +
    • + Postconditions: *this is uninitialized. +
    • +
    • + Notes: T's default constructor is not called. +
    • +
    • + Example: +
      optional<T> def ;
      +assert ( !def ) ;
      +
      +
    • +
    +

    + space +

    +

    + optional<T>::optional( + none_t ) + noexcept; +

    +
      +
    • + Effect: Constructs an optional uninitialized. +
    • +
    • + Postconditions: *this is uninitialized. +
    • +
    • + Notes: T's + default constructor is not called. + The expression boost::none + denotes an instance of boost::none_t + that can be used as the parameter. +
    • +
    • + Example: +
      #include <boost/none.hpp>
      +optional<T> n(none) ;
      +assert ( !n ) ;
      +
      +
    • +
    +

    + space +

    +

    + optional<T (not a ref)>::optional( T const& v ) +

    +
      +
    • + Requires: is_copy_constructible<T>::value + is true. +
    • +
    • + Effect: Directly-Constructs an optional. +
    • +
    • + Postconditions: *this is initialized + and its value is a copy of v. +
    • +
    • + Throws: Whatever T::T( T const& + ) throws. +
    • +
    • + Notes: T::T( T const& + ) is called. +
    • +
    • + Exception Safety: Exceptions can only + be thrown during T::T( T const& + ); in that case, this constructor + has no effect. +
    • +
    • + Example: +
      T v;
      +optional<T> opt(v);
      +assert ( *opt == v ) ;
      +
      +
    • +
    +

    + space +

    +

    + optional<T&>::optional( + T& + ref ) +

    +
      +
    • + Effect: Directly-Constructs an optional. +
    • +
    • + Postconditions: *this is initialized + and its value is an instance of an internal type wrapping the reference + ref. +
    • +
    • + Throws: Nothing. +
    • +
    • + Example: +
      T v;
      +T& vref = v ;
      +optional<T&> opt(vref);
      +assert ( *opt == v ) ;
      +++ v ; // mutate referee
      +assert (*opt == v);
      +
      +
    • +
    +

    + space +

    +

    + optional<T (not a ref)>::optional( T&& v + ) +

    +
      +
    • + Requires: is_move_constructible<T>::value + is true. +
    • +
    • + Effect: Directly-Move-Constructs an + optional. +
    • +
    • + Postconditions: *this is initialized + and its value is move-constructed from v. +
    • +
    • + Throws: Whatever T::T( T&& ) + throws. +
    • +
    • + Notes: T::T( T&& ) + is called. +
    • +
    • + Exception Safety: Exceptions can only + be thrown during T::T( T&& ); + in that case, the state of v + is determined by exception safety guarantees for T::T(T&&). +
    • +
    • + Example: +
      T v1, v2;
      +optional<T> opt(std::move(v1));
      +assert ( *opt == v2 ) ;
      +
      +
    • +
    +

    + space +

    +

    + optional<T&>::optional( + T&& + ref ) + = delete +

    +
    • + Notes: This constructor is deleted +
    +

    + space +

    +

    + optional<T (not a ref)>::optional( bool condition, + T const& v ) ; +

    +

    + optional<T&> + ::optional( bool condition, + T& + v ) + ; +

    +
    • + If condition is true, same as: +
    +

    + optional<T (not a ref)>::optional( T const& v ) +

    +

    + optional<T&> + ::optional( T& v ) +

    +
    • + otherwise, same as: +
    +

    + optional<T (not a ref)>::optional() +

    +

    + optional<T&> + ::optional() +

    +

    + space +

    +

    + optional<T (not a ref)>::optional( optional + const& + rhs ); +

    +
      +
    • + Requires: is_copy_constructible<T>::value + is true. +
    • +
    • + Effect: Copy-Constructs an optional. +
    • +
    • + Postconditions: If rhs is initialized, + *this + is initialized and its value is a copy of the + value of rhs; else + *this + is uninitialized. +
    • +
    • + Throws: Whatever T::T( T const& + ) throws. +
    • +
    • + Notes: If rhs is initialized, T::T(T const& ) + is called. +
    • +
    • + Exception Safety: Exceptions can only + be thrown during T::T( T const& + ); in that case, this constructor + has no effect. +
    • +
    • + Example: +
      optional<T> uninit ;
      +assert (!uninit);
      +
      +optional<T> uinit2 ( uninit ) ;
      +assert ( uninit2 == uninit );
      +
      +optional<T> init( T(2) );
      +assert ( *init == T(2) ) ;
      +
      +optional<T> init2 ( init ) ;
      +assert ( init2 == init ) ;
      +
      +
    • +
    +

    + space +

    +

    + optional<T&>::optional( + optional const& rhs + ); +

    +
      +
    • + Effect: Copy-Constructs an optional. +
    • +
    • + Postconditions: If rhs + is initialized, *this + is initialized and its value is another reference to the same object + referenced by *rhs; + else *this + is uninitialized. +
    • +
    • + Throws: Nothing. +
    • +
    • + Notes: If rhs + is initialized, both *this and *rhs will refer to the same object + (they alias). +
    • +
    • + Example: +
      optional<T&> uninit ;
      +assert (!uninit);
      +
      +optional<T&> uinit2 ( uninit ) ;
      +assert ( uninit2 == uninit );
      +
      +T v = 2 ; T& ref = v ;
      +optional<T> init(ref);
      +assert ( *init == v ) ;
      +
      +optional<T> init2 ( init ) ;
      +assert ( *init2 == v ) ;
      +
      +v = 3 ;
      +
      +assert ( *init  == 3 ) ;
      +assert ( *init2 == 3 ) ;
      +
      +
    • +
    +

    + space +

    +

    + optional<T (not a ref)>::optional( optional&& rhs + ) noexcept(see below); +

    +
      +
    • + Requires: is_move_constructible<T>::value + is true. +
    • +
    • + Effect: Move-constructs an optional. +
    • +
    • + Postconditions: If rhs + is initialized, *this + is initialized and its value is move constructed from rhs; else *this is uninitialized. +
    • +
    • + Throws: Whatever T::T( T&& ) + throws. +
    • +
    • + Remarks: The expression inside noexcept is equivalent to is_nothrow_move_constructible<T>::value. +
    • +
    • + Notes: If rhs + is initialized, T::T( T && + ) is called. +
    • +
    • + Exception Safety: Exceptions can only + be thrown during T::T( T&& ); + in that case, rhs remains + initialized and the value of *rhs is determined by exception safety + of T::T(T&&). +
    • +
    • + Example: +
      optional<std::unique_ptr<T>> uninit ;
      +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)) );
      +assert ( **init == T(2) ) ;
      +
      +optional<std::unique_ptr<T>> init2 ( std::move(init) ) ;
      +assert ( init );
      +assert ( *init == nullptr );
      +assert ( init2 );
      +assert ( **init2 == T(2) ) ;
      +
      +
    • +
    +

    + space +

    +

    + optional<T&>::optional( + optional && + rhs ); +

    +
      +
    • + Effect: Move-Constructs an optional. +
    • +
    • + Postconditions: If rhs + is initialized, *this + is initialized and its value is another reference to the same object + referenced by *rhs; + else *this + is uninitialized. +
    • +
    • + Throws: Nothing. +
    • +
    • + Notes: If rhs + is initialized, both *this and *rhs will refer to the same object + (they alias). +
    • +
    • + Example: +
      optional<std::unique_ptr<T>&> uninit ;
      +assert (!uninit);
      +
      +optional<std::unique_ptr<T>&> uinit2 ( std::move(uninit) ) ;
      +assert ( uninit2 == uninit );
      +
      +std::unique_ptr<T> v(new T(2)) ;
      +optional<std::unique_ptr<T>&> init(v);
      +assert ( *init == v ) ;
      +
      +optional<std::unique_ptr<T>&> init2 ( std::move(init) ) ;
      +assert ( *init2 == v ) ;
      +
      +*v = 3 ;
      +
      +assert ( **init  == 3 ) ;
      +assert ( **init2 == 3 ) ;
      +
      +
    • +
    +

    + space +

    +

    + template<U> explicit optional<T + (not a ref)>::optional( + optional<U> const& rhs ); +

    +
      +
    • + Effect: Copy-Constructs an optional. +
    • +
    • + Postconditions: If rhs + is initialized, *this + is initialized and its value is a copy of the + value of rhs converted to type T; + else *this + is uninitialized. +
    • +
    • + Throws: Whatever T::T( U const& + ) throws. +
    • +
    • + Notes: T::T( U const& + ) is called if rhs is initialized, which requires + a valid conversion from U + to T. +
    • +
    • + Exception Safety: Exceptions can only + be thrown during T::T( U const& + ); in that case, this constructor + has no effect. +
    • +
    • + Example: +
      optional<double> x(123.4);
      +assert ( *x == 123.4 ) ;
      +
      +optional<int> y(x) ;
      +assert( *y == 123 ) ;
      +
      +
    • +
    +

    + space +

    +

    + template<U> explicit optional<T + (not a ref)>::optional( + optional<U>&& + rhs ); +

    +
      +
    • + Effect: Move-constructs an optional. +
    • +
    • + Postconditions: If rhs + is initialized, *this + is initialized and its value is move-constructed from *rhs; + else *this + is uninitialized. +
    • +
    • + Throws: Whatever T::T( U&& ) + throws. +
    • +
    • + Notes: T::T( U&& ) + is called if rhs is + initialized, which requires a valid conversion from U + to T. +
    • +
    • + Exception Safety: Exceptions can only + be thrown during T::T( U&& ); + in that case, rhs remains + initialized and the value of *rhs is determined by exception safety + guarantee of T::T( U&& + ). +
    • +
    • + Example: +
      optional<double> x(123.4);
      +assert ( *x == 123.4 ) ;
      +
      +optional<int> y(std::move(x)) ;
      +assert( *y == 123 ) ;
      +
      +
    • +
    +

    + space +

    +

    + template<InPlaceFactory> + explicit optional<T + (not a ref)>::optional( + InPlaceFactory const& f ); +

    +

    + template<TypedInPlaceFactory> + explicit optional<T + (not a ref)>::optional( + TypedInPlaceFactory const& f ); +

    +
      +
    • + Effect: Constructs an optional with a value of T obtained from the factory. +
    • +
    • + Postconditions: *this is initialized + and its value is directly given from the factory + f (i.e., the value + is not copied). +
    • +
    • + Throws: Whatever the T constructor called by the factory + throws. +
    • +
    • + Notes: See In-Place + Factories +
    • +
    • + Exception Safety: Exceptions can only + be thrown during the call to the T + constructor used by the factory; in that case, this constructor has + no effect. +
    • +
    • + Example: +
      class C { C ( char, double, std::string ) ; } ;
      +
      +C v('A',123.4,"hello");
      +
      +optional<C> x( in_place   ('A', 123.4, "hello") ); // InPlaceFactory used
      +optional<C> y( in_place<C>('A', 123.4, "hello") ); // TypedInPlaceFactory used
      +
      +assert ( *x == v ) ;
      +assert ( *y == v ) ;
      +
      +
    • +
    +

    + space +

    +

    + optional& + optional<T>::operator= ( none_t + ) noexcept; +

    +
      +
    • + Effect: If *this is initialized destroys its contained + value. +
    • +
    • + Postconditions: *this is uninitialized. +
    • +
    +

    + space +

    +

    + optional& + optional<T (not a ref)>::operator= ( T + const& + rhs ) + ; +

    +
      +
    • + Effect: Assigns the value rhs to an optional. +
    • +
    • + Postconditions: *this is initialized and its value is + a copy of rhs. +
    • +
    • + Throws: Whatever T::operator=( T const& + ) or T::T(T const&) + throws. +
    • +
    • + Notes: If *this was initialized, T's assignment operator is used, + otherwise, its copy-constructor is used. +
    • +
    • + Exception Safety: In the event of + an exception, the initialization state of *this is unchanged and its value unspecified + as far as optional + is concerned (it is up to T's + operator=()). + If *this + is initially uninitialized and T's + copy constructor fails, *this is left properly uninitialized. +
    • +
    • + Example: +
      T x;
      +optional<T> def ;
      +optional<T> opt(x) ;
      +
      +T y;
      +def = y ;
      +assert ( *def == y ) ;
      +opt = y ;
      +assert ( *opt == y ) ;
      +
      +
    • +
    +

    + space +

    +

    + optional<T&>& + optional<T&>::operator= ( T& rhs + ) ; +

    +
      +
    • + Effect: (Re)binds the wrapped reference. +
    • +
    • + Postconditions: *this is initialized and it references + the same object referenced by rhs. +
    • +
    • + Notes: If *this was initialized, it is rebound + to the new object. See here + for details on this behavior. +
    • +
    • + Example: +
      int a = 1 ;
      +int b = 2 ;
      +T& ra = a ;
      +T& rb = b ;
      +optional<int&> def ;
      +optional<int&> opt(ra) ;
      +
      +def = rb ; // binds 'def' to 'b' through 'rb'
      +assert ( *def == b ) ;
      +*def = a ; // changes the value of 'b' to a copy of the value of 'a'
      +assert ( b == a ) ;
      +int c = 3;
      +int& rc = c ;
      +opt = rc ; // REBINDS to 'c' through 'rc'
      +c = 4 ;
      +assert ( *opt == 4 ) ;
      +
      +
    • +
    +

    + space +

    +

    + optional& + optional<T (not a ref)>::operator= ( T&& rhs + ) ; +

    +
      +
    • + Effect: Moves the value rhs to an optional. +
    • +
    • + Postconditions: *this is initialized and its value is + moved from rhs. +
    • +
    • + Throws: Whatever T::operator=( T&& ) + or T::T(T &&) + throws. +
    • +
    • + Notes: If *this was initialized, T's move-assignment operator is used, + otherwise, its move-constructor is used. +
    • +
    • + Exception Safety: In the event of + an exception, the initialization state of *this is unchanged and its value unspecified + as far as optional + is concerned (it is up to T's + operator=()). + If *this + is initially uninitialized and T's + move constructor fails, *this is left properly uninitialized. +
    • +
    • + Example: +
      T x;
      +optional<T> def ;
      +optional<T> opt(x) ;
      +
      +T y1, y2, yR;
      +def = std::move(y1) ;
      +assert ( *def == yR ) ;
      +opt = std::move(y2) ;
      +assert ( *opt == yR ) ;
      +
      +
    • +
    +

    + space +

    +

    + optional<T&>& + optional<T&>::operator= ( T&& rhs + ) = + delete; +

    +
    • + Notes: This assignment operator is + deleted. +
    +

    + space +

    +

    + optional& + optional<T (not a ref)>::operator= ( optional + const& + rhs ) + ; +

    +
      +
    • + Requires: T + is CopyConstructible and CopyAssignable. +
    • +
    • +

      + Effects: +

      +
      +++++ + + + + + + + + + + + + + + + + + +
      + +

      + *this + contains a value +

      +
      +

      + *this + does not contain a value +

      +
      +

      + rhs contains + a value +

      +
      +

      + assigns *rhs + to the contained value +

      +
      +

      + initializes the contained value as if direct-initializing + an object of type T + with *rhs +

      +
      +

      + rhs does + not contain a value +

      +
      +

      + destroys the contained value by calling val->T::~T() +

      +
      +

      + no effect +

      +
      +
    • +
    • + Returns: *this; +
    • +
    • + Postconditions: bool(rhs) == bool(*this). +
    • +
    • + Exception Safety: If any exception + is thrown, the initialization state of *this and rhs + remains unchanged. If an exception is thrown during the call to T's copy constructor, no effect. + If an exception is thrown during the call to T's + copy assignment, the state of its contained value is as defined by + the exception safety guarantee of T's + copy assignment. +
    • +
    • + Example: +
      T v;
      +optional<T> opt(v);
      +optional<T> def ;
      +
      +opt = def ;
      +assert ( !def ) ;
      +// previous value (copy of 'v') destroyed from within 'opt'.
      +
      +
    • +
    +

    + space +

    +

    + optional<T&> + & optional<T&>::operator= ( optional<T&> const& rhs + ) ; +

    +
      +
    • + Effect: (Re)binds thee wrapped reference. +
    • +
    • + Postconditions: If *rhs is initialized, *this + is initialized and it references the same object referenced by *rhs; + otherwise, *this + is uninitialized (and references no object). +
    • +
    • + Notes: If *this was initialized and so is *rhs, + *this + is rebound to the new object. See here + for details on this behavior. +
    • +
    • + Example: +
      int a = 1 ;
      +int b = 2 ;
      +T& ra = a ;
      +T& rb = b ;
      +optional<int&> def ;
      +optional<int&> ora(ra) ;
      +optional<int&> orb(rb) ;
      +
      +def = orb ; // binds 'def' to 'b' through 'rb' wrapped within 'orb'
      +assert ( *def == b ) ;
      +*def = ora ; // changes the value of 'b' to a copy of the value of 'a'
      +assert ( b == a ) ;
      +int c = 3;
      +int& rc = c ;
      +optional<int&> orc(rc) ;
      +ora = orc ; // REBINDS ora to 'c' through 'rc'
      +c = 4 ;
      +assert ( *ora == 4 ) ;
      +
      +
    • +
    +

    + space +

    +

    + optional& + optional<T (not a ref)>::operator= ( optional&& rhs + ) noexcept(see below); +

    +
      +
    • + Requires: T + is MoveConstructible + and MoveAssignable. +
    • +
    • +

      + Effects: +

      +
      +++++ + + + + + + + + + + + + + + + + + +
      + +

      + *this + contains a value +

      +
      +

      + *this + does not contain a value +

      +
      +

      + rhs contains + a value +

      +
      +

      + assigns std::move(*rhs) to the contained value +

      +
      +

      + initializes the contained value as if direct-initializing + an object of type T + with std::move(*rhs) +

      +
      +

      + rhs does + not contain a value +

      +
      +

      + destroys the contained value by calling val->T::~T() +

      +
      +

      + no effect +

      +
      +
    • +
    • + Returns: *this; +
    • +
    • + Postconditions: bool(rhs) == bool(*this). +
    • +
    • + Remarks: The expression inside noexcept is equivalent to is_nothrow_move_constructible<T>::value && + is_nothrow_move_assignable<T>::value. +
    • +
    • + Exception Safety: If any exception + is thrown, the initialization state of *this and rhs + remains unchanged. If an exception is thrown during the call to T's move constructor, the state of + *rhs + is determined by the exception safety guarantee of T's + move constructor. If an exception is thrown during the call to T's + move-assignment, the state of **this and *rhs is determined by the exception + safety guarantee of T's move assignment. +
    • +
    • + Example: +
      optional<T> opt(T(2)) ;
      +optional<T> def ;
      +
      +opt = def ;
      +assert ( def ) ;
      +assert ( opt ) ;
      +assert ( *opt == T(2) ) ;
      +
      +
    • +
    +

    + space +

    +

    + optional<T&> + & optional<T&>::operator= ( optional<T&>&& rhs + ) ; +

    +
    • + Effect: Same as optional<T&>::operator= ( optional<T&> + const& + rhs ). +
    +

    + space +

    +

    + template<U> optional& + optional<T (not a ref)>::operator= ( optional<U> const& rhs + ) ; +

    +
      +
    • +

      + Effect: +

      +
      +++++ + + + + + + + + + + + + + + + + + +
      + +

      + *this + contains a value +

      +
      +

      + *this + does not contain a value +

      +
      +

      + rhs contains + a value +

      +
      +

      + assigns *rhs + to the contained value +

      +
      +

      + initializes the contained value as if direct-initializing + an object of type T + with *rhs +

      +
      +

      + rhs does + not contain a value +

      +
      +

      + destroys the contained value by calling val->T::~T() +

      +
      +

      + no effect +

      +
      +
    • +
    • + Returns: *this. +
    • +
    • + Postconditions: bool(rhs) == bool(*this). +
    • +
    • + Exception Safety: If any exception + is thrown, the result of the expression bool(*this) remains unchanged. If an exception + is thrown during the call to T's + constructor, no effect. If an exception is thrown during the call to + T's assignment, the + state of its contained value is as defined by the exception safety + guarantee of T's copy + assignment. +
    • +
    • + Example: +
      T v;
      +optional<T> opt0(v);
      +optional<U> opt1;
      +
      +opt1 = opt0 ;
      +assert ( *opt1 == static_cast<U>(v) ) ;
      +
      +
    • +
    +

    + space +

    +

    + template<U> optional& + optional<T (not a ref)>::operator= ( optional<U>&& rhs + ) ; +

    +
      +
    • +

      + Effect: +

      +
      +++++ + + + + + + + + + + + + + + + + + +
      + +

      + *this + contains a value +

      +
      +

      + *this + does not contain a value +

      +
      +

      + rhs contains + a value +

      +
      +

      + assigns std::move(*rhs) to the contained value +

      +
      +

      + initializes the contained value as if direct-initializing + an object of type T + with std::move(*rhs) +

      +
      +

      + rhs does + not contain a value +

      +
      +

      + destroys the contained value by calling val->T::~T() +

      +
      +

      + no effect +

      +
      +
    • +
    • + Returns: *this. +
    • +
    • + Postconditions: bool(rhs) == bool(*this). +
    • +
    • + Exception Safety: If any exception + is thrown, the result of the expression bool(*this) remains unchanged. If an exception + is thrown during the call to T's + constructor, no effect. If an exception is thrown during the call to + T's assignment, the + state of its contained value is as defined by the exception safety + guarantee of T's copy + assignment. +
    • +
    • + Example: +
      T v;
      +optional<T> opt0(v);
      +optional<U> opt1;
      +
      +opt1 = std::move(opt0) ;
      +assert ( opt0 );
      +assert ( opt1 )
      +assert ( *opt1 == static_cast<U>(v) ) ;
      +
      +
    • +
    +

    + space +

    +

    + template<class... Args> + void optional<T + (not a ref)>::emplace( + Args...&& + args ); +

    +
      +
    • + Requires: The compiler supports rvalue + references and variadic templates. +
    • +
    • + Effect: If *this is initialized calls *this = none. + Then initializes in-place the contained value as if direct-initializing + an object of type T + with std::forward<Args>(args).... +
    • +
    • + Postconditions: *this is initialized. +
    • +
    • + Throws: Whatever the selected T's constructor throws. +
    • +
    • + Notes: T + need not be MoveConstructible + or MoveAssignable. + On compilers that do not support variadic templates, the signature + falls back to single-argument: template<class + Arg> + void emplace(Arg&& arg). On compilers that do not support + rvalue references, the signature falls back to two overloads: taking + const and non-const lvalue reference. +
    • +
    • + Exception Safety: If an exception + is thrown during the initialization of T, + *this + is uninitialized. +
    • +
    • + Example: +
      T v;
      +optional<const T> opt;
      +opt.emplace(0);  // create in-place using ctor T(int)
      +opt.emplace();   // destroy previous and default-construct another T
      +opt.emplace(v);  // destroy and copy-construct in-place (no assignment called)
      +
      +
    • +
    +

    + space +

    +

    + template<InPlaceFactory> + optional<T>& + optional<T (not a ref)>::operator=( InPlaceFactory + const& + f ); +

    +

    + template<TypedInPlaceFactory> + optional<T>& + optional<T (not a ref)>::operator=( TypedInPlaceFactory + const& + f ); +

    +
      +
    • + Effect: Assigns an optional + with a value of T obtained + from the factory. +
    • +
    • + Postconditions: *this is initialized + and its value is directly given from the factory + f (i.e., the value + is not copied). +
    • +
    • + Throws: Whatever the T constructor called by the factory + throws. +
    • +
    • + Notes: See In-Place + Factories +
    • +
    • + Exception Safety: Exceptions can only + be thrown during the call to the T + constructor used by the factory; in that case, the optional + object will be reset to be uninitialized. +
    • +
    +

    + space +

    +

    + void optional<T + (not a ref)>::reset( T const& v ) ; +

    +
    • + Deprecated: same as operator= + ( T + const& + v) + ; +
    +

    + space +

    +

    + void optional<T>::reset() noexcept + ; +

    +
    • + Deprecated: Same as operator=( + none_t ); +
    +

    + space +

    +

    + T const& optional<T + (not a ref)>::get() const ; +

    +

    + T& + optional<T (not a ref)>::get() ; +

    +

    + inline T + const& + get ( + optional<T (not a ref)> const& ) ; +

    +

    + inline T& get + ( optional<T + (not a ref)> + &) ; +

    +
      +
    • + Requires: *this is initialized +
    • +
    • + Returns: A reference to the contained + value +
    • +
    • + Throws: Nothing. +
    • +
    • + Notes: The requirement is asserted + via BOOST_ASSERT(). +
    • +
    +

    + space +

    +

    + T const& optional<T&>::get() const ; +

    +

    + T& + optional<T&>::get() ; +

    +

    + inline T + const& + get ( + optional<T&> + const& + ) ; +

    +

    + inline T& get + ( optional<T&> &) + ; +

    +
      +
    • + Requires: *this is initialized +
    • +
    • + Returns: The + reference contained. +
    • +
    • + Throws: Nothing. +
    • +
    • + Notes: The requirement is asserted + via BOOST_ASSERT(). +
    • +
    +

    + space +

    +

    + T const& optional<T + (not a ref)>::operator*() + const& + ; +

    +

    + T& + optional<T (not a ref)>::operator*() &; +

    +
      +
    • + Requires: *this is initialized +
    • +
    • + Returns: A reference to the contained + value +
    • +
    • + Throws: Nothing. +
    • +
    • + Notes: The requirement is asserted + via BOOST_ASSERT(). + On compilers that do not support ref-qualifiers on member functions + these two overloads are replaced with the classical two: a const and non-const + member functions. +
    • +
    • + Example: +
      T v ;
      +optional<T> opt ( v );
      +T const& u = *opt;
      +assert ( u == v ) ;
      +T w ;
      +*opt = w ;
      +assert ( *opt == w ) ;
      +
      +
    • +
    +

    + space +

    +

    + T&& + optional<T (not a ref)>::operator*() &&; +

    +
      +
    • + Requires: *this contains a value. +
    • +
    • + Effects: Equivalent to return std::move(*val);. +
    • +
    • + Notes: The requirement is asserted + via BOOST_ASSERT(). + On compilers that do not support ref-qualifiers on member functions + this overload is not present. +
    • +
    +

    + space +

    +

    + T & + optional<T&>::operator*() + const& + ; +

    +

    + T & + optional<T&>::operator*() + & ; +

    +

    + T & + optional<T&>::operator*() + && ; +

    +
      +
    • + Requires: *this is initialized +
    • +
    • + Returns: The + reference contained. +
    • +
    • + Throws: Nothing. +
    • +
    • + Notes: The requirement is asserted + via BOOST_ASSERT(). + On compilers that do not support ref-qualifiers on member functions + these three overloads are replaced with the classical two: a const and non-const + member functions. +
    • +
    • + Example: +
      T v ;
      +T& vref = v ;
      +optional<T&> opt ( vref );
      +T const& vref2 = *opt;
      +assert ( vref2 == v ) ;
      +++ v ;
      +assert ( *opt == v ) ;
      +
      +
    • +
    +

    + space +

    +

    + T const& optional<T>::value() const& ; +

    +

    + T& + optional<T>::value() & ; +

    +
      +
    • + Effects: Equivalent to return bool(*this) ? *val : throw bad_optional_access();. +
    • +
    • + Notes: On compilers that do not support + ref-qualifiers on member functions these two overloads are replaced + with the classical two: a const + and non-const member functions. +
    • +
    • + Example: +
      T v ;
      +optional<T> o0, o1 ( v );
      +assert ( o1.value() == v );
      +
      +try {
      +  o0.value(); // throws
      +  assert ( false );
      +}
      +catch(bad_optional_access&) {
      +  assert ( true );
      +}
      +
      +
    • +
    +

    + space +

    +

    + T&& + optional<T>::value() && ; +

    +
      +
    • + Effects: Equivalent to return bool(*this) ? std::move(*val) : throw bad_optional_access();. +
    • +
    • + Notes: On compilers that do not support + ref-qualifiers on member functions this overload is not present. +
    • +
    +

    + space +

    +

    + template<class U> T optional<T>::value_or(U && + v) + const& + ; +

    +
      +
    • + Effects: Equivalent to if (*this) return **this; else return + std::forward<U>(v);. +
    • +
    • + Remarks: If T + is not CopyConstructible or U && + is not convertible to T, + the program is ill-formed. +
    • +
    • + Notes: On compilers that do not support + ref-qualifiers on member functions this overload is replaced with the + const-qualified member + function. On compilers without rvalue reference support the type of + v becomes U const&. +
    • +
    +

    + space +

    +

    + template<class U> T optional<T>::value_or(U && + v) + && ; +

    +
      +
    • + Effects: Equivalent to if (*this) return std::move(**this); else return std::forward<U>(v);. +
    • +
    • + Remarks: If T + is not MoveConstructible + or U && + is not convertible to T, + the program is ill-formed. +
    • +
    • + Notes: On compilers that do not support + ref-qualifiers on member functions this overload is not present. +
    • +
    +

    + space +

    +

    + template<class F> T optional<T>::value_or_eval(F f) const& ; +

    +
      +
    • + Requires: T + is CopyConstructible and F models a Generator whose result type + is convertible to T. +
    • +
    • + Effects: if + (*this) return **this; else return f();. +
    • +
    • + Notes: On compilers that do not support + ref-qualifiers on member functions this overload is replaced with the + const-qualified member + function. +
    • +
    • + Example: +
      int complain_and_0()
      +{
      +  clog << "no value returned, using default" << endl;
      +  return 0;
      +}
      +
      +optional<int> o1 = 1;
      +optional<int> oN = none;
      +
      +int i = o1.value_or_eval(complain_and_0); // fun not called
      +assert (i == 1);
      +
      +int j = oN.value_or_eval(complain_and_0); // fun called
      +assert (i == 0);
      +
      +
    • +
    +

    + space +

    +

    + template<class F> T optional<T>::value_or_eval(F f) && + ; +

    +
      +
    • + Requires: T + is MoveConstructible + and F models a Generator + whose result type is convertible to T. +
    • +
    • + Effects: if + (*this) return std::move(**this); else return + f();. +
    • +
    • + Notes: On compilers that do not support + ref-qualifiers on member functions this overload is not present. +
    • +
    +

    + space +

    +

    + T const& optional<T + (not a ref)>::get_value_or( + T const& default) const ; +

    +

    + T& + optional<T (not a ref)>::get_value_or( T& default + ) ; +

    +

    + inline T + const& + get_optional_value_or ( + optional<T (not a ref)> const& o, T const& default ) ; +

    +

    + inline T& get_optional_value_or + ( optional<T + (not a ref)>& + o, + T& + default ) + ; +

    +
      +
    • + Deprecated: Use value_or() instead. +
    • +
    • + Returns: A reference to the contained + value, if any, or default. +
    • +
    • + Throws: Nothing. +
    • +
    • + Example: +
      T v, z ;
      +optional<T> def;
      +T const& y = def.get_value_or(z);
      +assert ( y == z ) ;
      +
      +optional<T> opt ( v );
      +T const& u = get_optional_value_or(opt,z);
      +assert ( u == v ) ;
      +assert ( u != z ) ;
      +
      +
    • +
    +

    + space +

    +

    + T const* optional<T + (not a ref)>::get_ptr() + const ; +

    +

    + T* + optional<T (not a ref)>::get_ptr() ; +

    +

    + inline T + const* + get_pointer ( + optional<T (not a ref)> const& ) ; +

    +

    + inline T* get_pointer + ( optional<T + (not a ref)> + &) ; +

    +
      +
    • + Returns: If *this is initialized, a pointer to the + contained value; else 0 + (null). +
    • +
    • + Throws: Nothing. +
    • +
    • + Notes: The contained value is permanently + stored within *this, + so you should not hold nor delete this pointer +
    • +
    • + Example: +
      T v;
      +optional<T> opt(v);
      +optional<T> const copt(v);
      +T* p = opt.get_ptr() ;
      +T const* cp = copt.get_ptr();
      +assert ( p == get_pointer(opt) );
      +assert ( cp == get_pointer(copt) ) ;
      +
      +
    • +
    +

    + space +

    +

    + T const* optional<T + (not a ref)>::operator ->() + const ; +

    +

    + T* + optional<T (not a ref)>::operator + ->() ; +

    +
      +
    • + Requires: *this is initialized. +
    • +
    • + Returns: A pointer to the contained + value. +
    • +
    • + Throws: Nothing. +
    • +
    • + Notes: The requirement is asserted + via BOOST_ASSERT(). +
    • +
    • + Example: +
      struct X { int mdata ; } ;
      +X x ;
      +optional<X> opt (x);
      +opt->mdata = 2 ;
      +
      +
    • +
    +

    + space +

    +

    + explicit optional<T>::operator + bool() + const noexcept + ; +

    +
      +
    • + Returns: get_ptr() != 0. +
    • +
    • + Notes: On compilers that do not support + explicit conversion operators this falls back to safe-bool idiom. +
    • +
    • + Example: +
      optional<T> def ;
      +assert ( def == 0 );
      +optional<T> opt ( v ) ;
      +assert ( opt );
      +assert ( opt != 0 );
      +
      +
    • +
    +

    + space +

    +

    + bool optional<T>::operator!() noexcept + ; +

    +
      +
    • + Returns: If *this is uninitialized, true; else false. +
    • +
    • + Notes: This operator is provided for + those compilers which can't use the unspecified-bool-type + operator in certain boolean contexts. +
    • +
    • + Example: +
      optional<T> opt ;
      +assert ( !opt );
      +*opt = some_T ;
      +
      +// Notice the "double-bang" idiom here.
      +assert ( !!opt ) ;
      +
      +
    • +
    +

    + space +

    +

    + bool optional<T>::is_initialized() const ; +

    +
    • + Deprecated: Same as explicit operator + bool () + ; +
    +

    + space +

    +
    + + Free + functions +
    +

    + space +

    +

    + optional<T (not a ref)> make_optional( T const& v ) +

    +
      +
    • + Returns: optional<T>(v) for the deduced + type T of v. +
    • +
    • + Example: +
      template<class T> void foo ( optional<T> const& opt ) ;
      +
      +foo ( make_optional(1+1) ) ; // Creates an optional<int>
      +
      +
    • +
    +

    + space +

    +

    + optional<T (not a ref)> make_optional( bool condition, + T const& v ) +

    +
      +
    • + Returns: optional<T>(condition,v) for the deduced + type T of v. +
    • +
    • + Example: +
      optional<double> calculate_foo()
      +{
      +  double val = compute_foo();
      +  return make_optional(is_not_nan_and_finite(val),val);
      +}
      +
      +optional<double> v = calculate_foo();
      +if ( !v )
      +  error("foo wasn't computed");
      +
      +
    • +
    +

    + space +

    +

    + bool operator + == ( + optional<T> const& x, optional<T> const& y ); +

    +
      +
    • + Requires: T + shall meet requirements of EqualityComparable. +
    • +
    • + Returns: If both x + and y are initialized, + (*x + == *y). + If only x or y is initialized, false. + If both are uninitialized, true. +
    • +
    • + Notes: This definition guarantees + that optional<T> + not containing a value is compared unequal to any optional<T> containing any value, and equal + 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 equal_pointees() + instead +
    • +
    • + Example: +
      optional<T> oN, oN_;
      +optional<T> o1(T(1)), o1_(T(1));
      +optional<T> o2(T(2));
      +
      +assert ( oN == oN );  // Identity implies equality
      +assert ( o1 == o1 );  //
      +
      +assert ( oN == oN_ ); // Both uninitialized compare equal
      +
      +assert ( oN != o1 );  // Initialized unequal to initialized.
      +
      +assert ( o1 == o1_ ); // Both initialized compare as (*lhs == *rhs)
      +assert ( o1 != o2 );  //
      +
      +
    • +
    +

    + space +

    +

    + bool operator + < ( + optional<T> const& x, optional<T> const& y ); +

    +
      +
    • + Requires: Expression *x < *y shall be well-formed and its result + shall be convertible to bool. +
    • +
    • + 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 less_pointees() + instead. T need not + be LessThanComparable. Only + single operator< + is required. Other relational operations are defined in terms of this + one. If T's operator< + satisfies the axioms of LessThanComparable (transitivity, + antisymmetry and irreflexivity), optinal<T> is LessThanComparable. +
    • +
    • + Example: +
      optional<T> oN, oN_;
      +optional<T> o0(T(0));
      +optional<T> o1(T(1));
      +
      +assert ( !(oN < oN) );  // Identity implies equivalence
      +assert ( !(o1 < o1) );
      +
      +assert ( !(oN < oN_) ); // Two uninitialized are equivalent
      +assert ( !(oN_ < oN) );
      +
      +assert ( oN < o0 );     // Uninitialized is less than initialized
      +assert ( !(o0 < oN) );
      +
      +assert ( o1 < o2 ) ;    // Two initialized compare as (*lhs < *rhs)
      +assert ( !(o2 < o1) ) ;
      +assert ( !(o2 < o2) ) ;
      +
      +
    • +
    +

    + space +

    +

    + bool operator + != ( + optional<T> const& x, optional<T> const& y ); +

    +
    • + Returns: !( + x == + y ); +
    +

    + space +

    +

    + bool operator + > ( + optional<T> const& x, optional<T> const& y ); +

    +
    • + Returns: ( + y < + x ); +
    +

    + space +

    +

    + bool operator + <= ( + optional<T> const& x, optional<T> const& y ); +

    +
    • + Returns: !( + y < + x ); +
    +

    + space +

    +

    + bool operator + >= ( + optional<T> const& x, optional<T> const& y ); +

    +
    • + Returns: !( + x < + y ); +
    +

    + space +

    +

    + bool operator + == ( + optional<T> const& x, none_t ) + noexcept; +

    +

    + bool operator + == ( + none_t, + optional<T> const& x ) noexcept; +

    +
    +

    + space +

    +

    + bool operator + != ( + optional<T> const& x, none_t ) + noexcept; +

    +

    + bool operator + != ( + none_t, + optional<T> const& x ) noexcept; +

    +
    • + Returns: !( + x == + y ); +
    +

    + space +

    +

    + void swap + ( optional<T>& x, optional<T>& y + ) ; +

    +
      +
    • + Requires: Lvalues of type T shall be swappable and T shall be MoveConstructible. +
    • +
    • +

      + Effects: +

      +
      +++++ + + + + + + + + + + + + + + + + + +
      + +

      + *this + contains a value +

      +
      +

      + *this + does not contain a value +

      +
      +

      + rhs contains + a value +

      +
      +

      + calls swap(*(*this), *rhs) +

      +
      +

      + initializes the contained value of *this as if direct-initializing + an object of type T + with the expression std::move(*rhs), followed by rhs.val->T::~T(), + *this + contains a value and rhs + does not contain a value +

      +
      +

      + rhs does + not contain a value +

      +
      +

      + initializes the contained value of rhs + as if direct-initializing an object of type T with the expression + std::move(*(*this)), + followed by val->T::~T(), *this does not contain a value + and rhs contains + a value +

      +
      +

      + no effect +

      +
      +
    • +
    • + Postconditions: The states of x and y + interchanged. +
    • +
    • + Throws: If both are initialized, whatever + swap(T&,T&) + throws. If only one is initialized, whatever T::T ( T&& ) + throws. +
    • +
    • + Example: +
      T x(12);
      +T y(21);
      +optional<T> def0 ;
      +optional<T> def1 ;
      +optional<T> optX(x);
      +optional<T> optY(y);
      +
      +boost::swap(def0,def1); // no-op
      +
      +boost::swap(def0,optX);
      +assert ( *def0 == x );
      +assert ( !optX );
      +
      +boost::swap(def0,optX); // Get back to original values
      +
      +boost::swap(optX,optY);
      +assert ( *optX == y );
      +assert ( *optY == x );
      +
      +
    • +
    +
    + + + +
    +
    +
    +PrevUpHomeNext +
    + + diff --git a/doc/html/boost_optional/reference/io_header.html b/doc/html/boost_optional/reference/io_header.html new file mode 100644 index 0000000..c61e5c6 --- /dev/null +++ b/doc/html/boost_optional/reference/io_header.html @@ -0,0 +1,72 @@ + + + +Header <boost/optional/optional_io.hpp> + + + + + + + + + + + + + + + +
    Boost C++ LibrariesHomeLibrariesPeopleFAQMore
    +
    +
    +PrevUpHomeNext +
    +
    + +
    + +

    +

    +
    #include <istream>
    +#include <ostream>
    +#include <boost/optional/optional.hpp>
    +
    +namespace boost {
    +
    +template <class CharType, class CharTrait, class T>
    +  std::basic_ostream<CharType, CharTrait>&
    +  operator<<(std::basic_ostream<CharType, CharTrait>& out, optional<T> const& v); R
    +
    +  template <class CharType, class CharTrait>
    +  std::basic_ostream<CharType, CharTrait>&
    +  operator<<(std::basic_ostream<CharType, CharTrait>& out, none_t const&); R
    +
    +template<class CharType, class CharTrait, class T>
    +  std::basic_istream<CharType, CharTrait>&
    +  operator>>(std::basic_istream<CharType, CharTrait>& in, optional<T>& v); R
    +
    +} // namespace boost
    +
    +

    +

    +
    +
    + + + +
    +
    +
    +PrevUpHomeNext +
    + + diff --git a/doc/html/boost_optional/reference/io_header/io_semantics.html b/doc/html/boost_optional/reference/io_header/io_semantics.html new file mode 100644 index 0000000..c368ac7 --- /dev/null +++ b/doc/html/boost_optional/reference/io_header/io_semantics.html @@ -0,0 +1,112 @@ + + + +Detailed semantics + + + + + + + + + + + + + + + +
    Boost C++ LibrariesHomeLibrariesPeopleFAQMore
    +
    +
    +PrevUpHomeNext +
    +
    + +

    + template + <class + CharType, + class CharTrait, class T> +
        std::basic_ostream<CharType, CharTrait>&
        operator<<(std::basic_ostream<CharType, CharTrait>& + out, + optional<T> const& v); +

    +
      +
    • + Effect: Outputs an implementation-defined + string. The output contains the information about whether the optional + object contains a value or not. If v + contains a value, the output contains result of calling out << + *v. +
    • +
    • + Returns: out. +
    • +
    +

    + space +

    +

    + template <class CharType, class CharTrait, + class T>
        std::basic_ostream<CharType, CharTrait>& +
        operator<<(std::basic_ostream<CharType, CharTrait>& out, none_t); +

    +
      +
    • + Effect: Outputs an implementation-defined + string. +
    • +
    • + Returns: out. +
    • +
    +

    + space +

    +

    + template <class CharType, class CharTrait, + class T>
        std::basic_ostream<CharType, CharTrait>& +
        operator>>(std::basic_istream<CharType, CharTrait>& in, optional<T>& v); +

    +
      +
    • + Requires: T + is DefaultConstructible and + MoveConstructible. +
    • +
    • + Effect: Reads the value of optional + object from in. If + the string representation indicates that the optional object should + contain a value, v + contains a value and its contained value is obtained as if by default-constructing + an object o of type + T and then calling + in >> + o; otherwise v does not contain a value, and the + previously contained value (if any) has been destroyed. +
    • +
    • + Returns: out. +
    • +
    +
    + + + +
    +
    +
    +PrevUpHomeNext +
    + + diff --git a/doc/html/index.html b/doc/html/index.html index 0e063f2..f00d5e8 100644 --- a/doc/html/index.html +++ b/doc/html/index.html @@ -76,9 +76,17 @@
    Reference
    -
    Synopsis
    -
    Detailed - Semantics
    +
    Header + <boost/none.hpp>
    +
    Header + <boost/optional/bad_optional_access.hpp>
    +
    Header <boost/optional/optional_io.hpp>
    +
    Header + <boost/optional/optional_fwd.hpp>
    +
    Header + <boost/optional/optional.hpp>
    +
    Header + <boost/optional.hpp>
    Dependencies and Portability
    @@ -138,7 +146,7 @@

    - +

    Last revised: March 09, 2015 at 09:53:44 GMT

    Last revised: March 09, 2015 at 20:53:41 GMT


    diff --git a/doc/html/optional/reference.html b/doc/html/optional/reference.html index 21e9ebb..242e029 100644 --- a/doc/html/optional/reference.html +++ b/doc/html/optional/reference.html @@ -7,7 +7,7 @@ - + @@ -20,157 +20,53 @@

    -PrevUpHomeNext +PrevUpHomeNext
    -
    // In Header: <boost/optional/optional.hpp>
    +
    + +

    +

    +
    namespace boost {
     
    -namespace boost {
    +class none_t {};
     
    -template <class T>
    -class optional
    -{
    -public :
    -
    -    typedef T value_type;
    -
    -    // (If T is of reference type, the parameters and results by reference are by value)
    -
    -    optional () noexcept ; R
    -
    -    optional ( none_t ) noexcept ; R
    -
    -    optional ( T const& v ) ; R
    -
    -    optional ( T&& v ) ; R
    -
    -    // [new in 1.34]
    -    optional ( bool condition, T const& v ) ; R
    -
    -    optional ( optional const& rhs ) ; R
    -
    -    optional ( optional&& rhs ) noexcept(see below) ; R
    -
    -    template<class U> explicit optional ( optional<U> const& rhs ) ; R
    -
    -    template<class U> explicit optional ( optional<U>&& rhs ) ; R
    -
    -    template<class InPlaceFactory> explicit optional ( InPlaceFactory const& f ) ; R
    -
    -    template<class TypedInPlaceFactory> explicit optional ( TypedInPlaceFactory const& f ) ; R
    -
    -    optional& operator = ( none_t ) noexcept ; R
    -
    -    optional& operator = ( T const& v ) ; R
    -
    -    optional& operator = ( T&& v ) ; R
    -
    -    optional& operator = ( optional const& rhs ) ; R
    -
    -    optional& operator = ( optional&& rhs ) noexcept(see below) ; R
    -
    -    template<class U> optional& operator = ( optional<U> const& rhs ) ; R
    -
    -    template<class U> optional& operator = ( optional<U>&& rhs ) ; R
    -
    -    template<class... Args> void emplace ( Args...&& args ) ; R
    -
    -    template<class InPlaceFactory> optional& operator = ( InPlaceFactory const& f ) ; R
    -
    -    template<class TypedInPlaceFactory> optional& operator = ( TypedInPlaceFactory const& f ) ; R
    -
    -    T const& get() const ; R
    -    T&       get() ; R
    -
    -    T const* operator ->() const ; R
    -    T*       operator ->() ; R
    -
    -    T const& operator *() const& ; R
    -    T&       operator *() & ; R
    -    T&&      operator *() && ; R
    -
    -    T const& value() const& ; R
    -    T&       value() & ; R
    -    T&&      value() && ; R
    -
    -    template<class U> T value_or( U && v ) const& ; R
    -    template<class U> T value_or( U && v ) && ; R
    -
    -    template<class F> T value_or_eval( F f ) const& ; R
    -    template<class F> T value_or_eval( F f ) && ; R
    -
    -    T const* get_ptr() const ; R
    -    T*       get_ptr() ; R
    -
    -    explicit operator bool() const noexcept ; R
    -
    -    bool operator!() const noexcept ; R
    -
    -    // deprecated methods
    -
    -    // (deprecated)
    -    void reset() noexcept ; R
    -
    -    // (deprecated)
    -    void reset ( T const& ) ; R
    -
    -    // (deprecated)
    -    bool is_initialized() const ; R
    -
    -    // (deprecated)
    -    T const& get_value_or( T const& default ) const ; R
    -};
    -
    -template<class T> inline bool operator == ( optional<T> const& x, optional<T> const& y ) ; R
    -
    -template<class T> inline bool operator != ( optional<T> const& x, optional<T> const& y ) ; R
    -
    -template<class T> inline bool operator <  ( optional<T> const& x, optional<T> const& y ) ; R
    -
    -template<class T> inline bool operator >  ( optional<T> const& x, optional<T> const& y ) ; R
    -
    -template<class T> inline bool operator <= ( optional<T> const& x, optional<T> const& y ) ; R
    -
    -template<class T> inline bool operator >= ( optional<T> const& x, optional<T> const& y ) ; R
    -
    -template<class T> inline bool operator == ( optional<T> const& x, none_t ) noexcept ; R
    -
    -template<class T> inline bool operator != ( optional<T> const& x, none_t ) noexcept ; R
    -
    -template<class T> inline optional<T> make_optional ( T const& v ) ; R
    -
    -template<class T> inline optional<T> make_optional ( bool condition, T const& v ) ; R
    -
    -template<class T> inline T const& get_optional_value_or ( optional<T> const& opt, T const& default ) ; R
    -
    -template<class T> inline T const& get ( optional<T> const& opt ) ; R
    -
    -template<class T> inline T& get ( optional<T> & opt ) ; R
    -
    -template<class T> inline T const* get ( optional<T> const* opt ) ; R
    -
    -template<class T> inline T* get ( optional<T>* opt ) ; R
    -
    -template<class T> inline T const* get_pointer ( optional<T> const& opt ) ; R
    -
    -template<class T> inline T* get_pointer ( optional<T> & opt ) ; R
    -
    -template<class T> inline void swap( optional<T>& x, optional<T>& y ) ; R
    +extern const none_t none; // see below
     
     } // namespace boost
     
    +

    +

    +

    + Variable none has external + linkage, however it is not required to link with any library to obtain + its definition. Only by including this header file, the definition becomes + available, by means of using template instantiation. +

    +
    @@ -183,7 +79,7 @@

    -PrevUpHomeNext +PrevUpHomeNext
    diff --git a/doc/html/boost_optional/reference/synopsis.html b/doc/html/optional/reference/header__boost_optional_optional_hpp_.html similarity index 64% rename from doc/html/boost_optional/reference/synopsis.html rename to doc/html/optional/reference/header__boost_optional_optional_hpp_.html index 99adcfd..c5f3e55 100644 --- a/doc/html/boost_optional/reference/synopsis.html +++ b/doc/html/optional/reference/header__boost_optional_optional_hpp_.html @@ -1,13 +1,13 @@ -Synopsis +Header <boost/optional/optional.hpp> - - - - + + + + @@ -20,147 +20,158 @@

    -PrevUpHomeNext +PrevUpHomeNext
    +
    +
    // In Header: <boost/optional/optional.hpp>
     
     namespace boost {
     
    -template<class T>
    +template <class T>
     class optional
     {
    -    public :
    +public :
    +
    +    typedef T value_type;
     
         // (If T is of reference type, the parameters and results by reference are by value)
     
    -    optional () noexcept ; R
    +    optional () noexcept ; R
     
    -    optional ( none_t ) noexcept ; R
    +    optional ( none_t ) noexcept ; R
     
    -    optional ( T const& v ) ; R
    +    optional ( T const& v ) ; R
     
    -    optional ( T&& v ) ; R
    +    optional ( T&& v ) ; R
     
         // [new in 1.34]
    -    optional ( bool condition, T const& v ) ; R
    +    optional ( bool condition, T const& v ) ; R
     
    -    optional ( optional const& rhs ) ; R
    +    optional ( optional const& rhs ) ; R
     
    -    optional ( optional&& rhs ) noexcept(see below) ; R
    +    optional ( optional&& rhs ) noexcept(see below) ; R
     
    -    template<class U> explicit optional ( optional<U> const& rhs ) ; R
    +    template<class U> explicit optional ( optional<U> const& rhs ) ; R
     
    -    template<class U> explicit optional ( optional<U>&& rhs ) ; R
    +    template<class U> explicit optional ( optional<U>&& rhs ) ; R
     
    -    template<class InPlaceFactory> explicit optional ( InPlaceFactory const& f ) ; R
    +    template<class InPlaceFactory> explicit optional ( InPlaceFactory const& f ) ; R
     
    -    template<class TypedInPlaceFactory> explicit optional ( TypedInPlaceFactory const& f ) ; R
    +    template<class TypedInPlaceFactory> explicit optional ( TypedInPlaceFactory const& f ) ; R
     
    -    optional& operator = ( none_t ) noexcept ; R
    +    optional& operator = ( none_t ) noexcept ; R
     
    -    optional& operator = ( T const& v ) ; R
    +    optional& operator = ( T const& v ) ; R
     
    -    optional& operator = ( T&& v ) ; R
    +    optional& operator = ( T&& v ) ; R
     
    -    optional& operator = ( optional const& rhs ) ; R
    +    optional& operator = ( optional const& rhs ) ; R
     
    -    optional& operator = ( optional&& rhs ) noexcept(see below) ; R
    +    optional& operator = ( optional&& rhs ) noexcept(see below) ; R
     
    -    template<class U> optional& operator = ( optional<U> const& rhs ) ; R
    +    template<class U> optional& operator = ( optional<U> const& rhs ) ; R
     
    -    template<class U> optional& operator = ( optional<U>&& rhs ) ; R
    +    template<class U> optional& operator = ( optional<U>&& rhs ) ; R
     
    -    template<class... Args> void emplace ( Args...&& args ) ; R
    +    template<class... Args> void emplace ( Args...&& args ) ; R
     
    -    template<class InPlaceFactory> optional& operator = ( InPlaceFactory const& f ) ; R
    +    template<class InPlaceFactory> optional& operator = ( InPlaceFactory const& f ) ; R
     
    -    template<class TypedInPlaceFactory> optional& operator = ( TypedInPlaceFactory const& f ) ; R
    +    template<class TypedInPlaceFactory> optional& operator = ( TypedInPlaceFactory const& f ) ; R
     
    -    T const& get() const ; R
    -    T&       get() ; R
    +    T const& get() const ; R
    +    T&       get() ; R
     
    -    T const* operator ->() const ; R
    -    T*       operator ->() ; R
    +    T const* operator ->() const ; R
    +    T*       operator ->() ; R
     
    -    T const& operator *() const& ; R
    -    T&       operator *() &; R
    -    T&&      operator *() &&; R
    +    T const& operator *() const& ; R
    +    T&       operator *() & ; R
    +    T&&      operator *() && ; R
     
    -    T const& value() const& ; R
    -    T&       value() & ; R
    -    T&&      value() && ; R
    +    T const& value() const& ; R
    +    T&       value() & ; R
    +    T&&      value() && ; R
     
    -    template<class U> T value_or( U && v ) const& ; R
    -    template<class U> T value_or( U && v ) && ; R
    +    template<class U> T value_or( U && v ) const& ; R
    +    template<class U> T value_or( U && v ) && ; R
     
    -    T const* get_ptr() const ; R
    -    T*       get_ptr() ; R
    +    template<class F> T value_or_eval( F f ) const& ; R
    +    template<class F> T value_or_eval( F f ) && ; R
     
    -    explicit operator bool() const ; R
    +    T const* get_ptr() const ; R
    +    T*       get_ptr() ; R
     
    -    bool operator!() const noexcept ; R
    +    explicit operator bool() const noexcept ; R
    +
    +    bool operator!() const noexcept ; R
     
         // deprecated methods
     
         // (deprecated)
    -    void reset() noexcept ; R
    +    void reset() noexcept ; R
     
         // (deprecated)
    -    void reset ( T const& ) ; R
    +    void reset ( T const& ) ; R
     
         // (deprecated)
    -    bool is_initialized() const ; R
    +    bool is_initialized() const ; R
     
         // (deprecated)
    -    T const& get_value_or( T const& default ) const ; R
    +    T const& get_value_or( T const& default ) const ; R
     };
     
    -template<class T> inline bool operator == ( optional<T> const& x, optional<T> const& y ) ; R
    +template<class T> inline bool operator == ( optional<T> const& x, optional<T> const& y ) ; R
     
    -template<class T> inline bool operator != ( optional<T> const& x, optional<T> const& y ) ; R
    +template<class T> inline bool operator != ( optional<T> const& x, optional<T> const& y ) ; R
     
    -template<class T> inline bool operator <  ( optional<T> const& x, optional<T> const& y ) ; R
    +template<class T> inline bool operator <  ( optional<T> const& x, optional<T> const& y ) ; R
     
    -template<class T> inline bool operator >  ( optional<T> const& x, optional<T> const& y ) ; R
    +template<class T> inline bool operator >  ( optional<T> const& x, optional<T> const& y ) ; R
     
    -template<class T> inline bool operator <= ( optional<T> const& x, optional<T> const& y ) ; R
    +template<class T> inline bool operator <= ( optional<T> const& x, optional<T> const& y ) ; R
     
    -template<class T> inline bool operator >= ( optional<T> const& x, optional<T> const& y ) ; R
    +template<class T> inline bool operator >= ( optional<T> const& x, optional<T> const& y ) ; R
     
    -template<class T> inline bool operator == ( optional<T> const& x, none_t ) noexcept ; R
    +template<class T> inline bool operator == ( optional<T> const& x, none_t ) noexcept ; R
     
    -template<class T> inline bool operator != ( optional<T> const& x, none_t ) noexcept ; R
    +template<class T> inline bool operator != ( optional<T> const& x, none_t ) noexcept ; R
     
    -template<class T> inline optional<T> make_optional ( T const& v ) ; R
    +template<class T> inline optional<T> make_optional ( T const& v ) ; R
     
    -template<class T> inline optional<T> make_optional ( bool condition, T const& v ) ; R
    +template<class T> inline optional<T> make_optional ( bool condition, T const& v ) ; R
     
    -template<class T> inline T const& get_optional_value_or ( optional<T> const& opt, T const& default ) ; R
    +template<class T> inline T const& get_optional_value_or ( optional<T> const& opt, T const& default ) ; R
     
    -template<class T> inline T const& get ( optional<T> const& opt ) ; R
    +template<class T> inline T const& get ( optional<T> const& opt ) ; R
     
    -template<class T> inline T& get ( optional<T> & opt ) ; R
    +template<class T> inline T& get ( optional<T> & opt ) ; R
     
    -template<class T> inline T const* get ( optional<T> const* opt ) ; R
    +template<class T> inline T const* get ( optional<T> const* opt ) ; R
     
    -template<class T> inline T* get ( optional<T>* opt ) ; R
    +template<class T> inline T* get ( optional<T>* opt ) ; R
     
    -template<class T> inline T const* get_pointer ( optional<T> const& opt ) ; R
    +template<class T> inline T const* get_pointer ( optional<T> const& opt ) ; R
     
    -template<class T> inline T* get_pointer ( optional<T> & opt ) ; R
    +template<class T> inline T* get_pointer ( optional<T> & opt ) ; R
     
    -template<class T> inline void swap( optional<T>& x, optional<T>& y ) ; R
    +template<class T> inline void swap( optional<T>& x, optional<T>& y ) ; R
     
     } // namespace boost
     
    +
    -

    -PrevUpHomeNext +PrevUpHomeNext
    diff --git a/include/boost/optional/optional_io.hpp b/include/boost/optional/optional_io.hpp index 28612fd..16dbf95 100644 --- a/include/boost/optional/optional_io.hpp +++ b/include/boost/optional/optional_io.hpp @@ -62,7 +62,11 @@ operator>>(std::basic_istream& in, optional& v) { T x; in >> x; +#ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES + v = boost::move(x); +#else v = x; +#endif } else { From 15d9fcdbd1dbe46fd8ddadf6d014dacbb3bf43f1 Mon Sep 17 00:00:00 2001 From: Andrzej Krzemienski Date: Tue, 10 Mar 2015 07:14:36 +0100 Subject: [PATCH 4/5] added missing overload for value_or fo non-C++11 compilers --- include/boost/optional/optional.hpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/include/boost/optional/optional.hpp b/include/boost/optional/optional.hpp index 126cf02..afcb807 100644 --- a/include/boost/optional/optional.hpp +++ b/include/boost/optional/optional.hpp @@ -1106,6 +1106,15 @@ class optional : public optional_detail::optional_base else return v; } + + template + value_type value_or ( U& v ) const + { + if (this->is_initialized()) + return get(); + else + return v; + } #endif From 9d3f2fa825dc68ec73778ff5495f2c5eefce2a26 Mon Sep 17 00:00:00 2001 From: Andrzej Krzemienski Date: Fri, 13 Mar 2015 22:53:47 +0100 Subject: [PATCH 5/5] Doc: spelling fix from jsjohns --- doc/11_development.qbk | 2 +- .../tutorial/design_overview/the_interface.html | 4 ++-- doc/html/index.html | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/11_development.qbk b/doc/11_development.qbk index d2f1b1f..9e3ef44 100644 --- a/doc/11_development.qbk +++ b/doc/11_development.qbk @@ -171,7 +171,7 @@ Also, the presence of the possibly uninitialized state requires additional operations not provided by `T` itself which are supported by a special interface. [heading Lexically-hinted Value Access in the presence of possibly -untitialized optional objects: The operators * and ->] +uninitialized optional objects: The operators * and ->] A relevant feature of a pointer is that it can have a [*null pointer value]. This is a ['special] value which is used to indicate that the pointer is not diff --git a/doc/html/boost_optional/tutorial/design_overview/the_interface.html b/doc/html/boost_optional/tutorial/design_overview/the_interface.html index e8c1e39..c3833ff 100644 --- a/doc/html/boost_optional/tutorial/design_overview/the_interface.html +++ b/doc/html/boost_optional/tutorial/design_overview/the_interface.html @@ -63,8 +63,8 @@

    - Lexically-hinted - Value Access in the presence of possibly untitialized optional objects: + Lexically-hinted + Value Access in the presence of possibly uninitialized optional objects: The operators * and ->

    diff --git a/doc/html/index.html b/doc/html/index.html index f00d5e8..891941d 100644 --- a/doc/html/index.html +++ b/doc/html/index.html @@ -146,7 +146,7 @@

    - +

    Last revised: March 09, 2015 at 20:53:41 GMT

    Last revised: March 13, 2015 at 21:52:15 GMT