diff --git a/doc/01_quick_start.qbk b/doc/01_quick_start.qbk
index 71053e1..4a94429 100644
--- a/doc/01_quick_start.qbk
+++ b/doc/01_quick_start.qbk
@@ -17,18 +17,18 @@
Let's write and use a converter function that converts an a `std::string` to an `int`. It is possible that for a given string (e.g. `"cat"`) there exist no value of type `int` capable of representing the conversion result. We do not consider such situation an error. We expect that the converter can be used only to check if the conversion is possible. A natural signature for this function can be:
#include
#include <boost/optional.hpp> -boost::optionl<int> convert(const std::string& text); +boost::optional<int> convert(const std::string& text);
All necessary functionality can be included with one header <boost/optional.hpp>
.
@@ -65,16 +65,16 @@
can use our function:
const std::string& text = /*... */; -boost::optionl<int> oi = convert(text); // move-construct -if (oi) // contextual conversion to bool - int i = *oi; // operator* +boost::optional<int> oi = convert(text); // move-construct +if (oi) // contextual conversion to bool + int i = *oi; // operator*
In order to test if optional
contains a value, we use the contextual conversion to type bool
. Because of this we can combine the initialization
of the optional object and the test into one instruction:
if (boost::optionl<int> oi = convert(text)) +if (boost::optional<int> oi = convert(text)) int i = *oi;@@ -114,10 +114,13 @@ Finally, you can provide a callback to be called when trying to access the contained value fails:
-int l = convert(text).value_or_eval([]() -> int { - cout << "could not convert; using -1 instead" << endl; +int fallback_to_default() +{ + cerr << "could not convert; using -1 instead" << endl; return -1; -}); +} + +int l = convert(text).value_or_eval(fallback_to_default);This will call the provided callback and return whatever the callback returns. @@ -128,7 +131,7 @@ Now, let's consider how function
-convert
can be implemented.boost::optionl<int> convert(const std::string& text) +boost::optional<int> convert(const std::string& text) { std::stringstream s(text); int i; diff --git a/doc/html/boost_optional/quick_start/optional_automatic_variables.html b/doc/html/boost_optional/quick_start/optional_automatic_variables.html index f577e11..bcf6b37 100644 --- a/doc/html/boost_optional/quick_start/optional_automatic_variables.html +++ b/doc/html/boost_optional/quick_start/optional_automatic_variables.html @@ -31,9 +31,9 @@ We could write functionconvert
in a slightly different manner, so that it has a singlereturn
-statement: -boost::optionl<int> convert(const std::string& text) +boost::optional<int> convert(const std::string& text) { - boost::optionl<int> ans; + boost::optional<int> ans; std::stringstream s(text); int i; if ((s >> i) && s.get() == std::char_traits<char>::eof()) diff --git a/doc/html/boost_optional/reference/detailed_semantics.html b/doc/html/boost_optional/reference/detailed_semantics.html index e428dbf..6dc0456 100644 --- a/doc/html/boost_optional/reference/detailed_semantics.html +++ b/doc/html/boost_optional/reference/detailed_semantics.html @@ -902,40 +902,52 @@
- - Effect: Move-assigns another
optional
to anoptional
. + Requires:T
+ isMoveConstructible
+ andMoveAssignable
.- - Postconditions: If
rhs
- is initialized,*this
- is initialized and its value is moved from*rhs
,rhs
- remains initialized; else*this
is uninitialized. + Effects: ++
- + If
+!*this + && !rhs
no effect, otherwise +- + if
+bool(*this) + && !rhs
, destroys the contained value + by callingval->T::~T()
, otherwise +- + if
+!*this + && bool(rhs)
, initializes the contained value + as if direct-initializing an object of typeT
+ withstd::move(*rhs)
, + otherwise +- + (if
+bool(*this) + && bool(rhs)
) assignsstd::move(*rhs)
to the contained value. +- - Throws: Whatever
T::operator( T&& )
- orT::T( T && - )
throws. + Postconditions:bool(rhs) == bool(*this)
.- Remarks: The expression inside
noexcept
is equivalent tois_nothrow_move_constructible<T>::value && is_nothrow_move_assignable<T>::value
.- - Notes: If both
-*this
andrhs
- are initially initialized,T
's - move assignment operator is used. If*this
- is initially initialized butrhs
- is uninitialized,T
's - [destructor] is called. If*this
is initially uninitialized butrhs
is initialized,T
's - move constructor 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 toT
's -operator=()
). - If*this
- is initially uninitialized andT
's - move constructor fails,*this
is left properly uninitialized. + Exception Safety: If any exception is + thrown, the initialization state of*this
andrhs
+ remain unchanged. If an exception is thrown during the call toT
's move constructor, the state of +*rhs
+ is determined by the exception safety guarantee ofT
'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: @@ -1064,6 +1076,8 @@ optional<U> opt1; opt1 = std::move(opt0) ; +assert ( opt0 ); +assert ( opt1 ) assert ( *opt1 == static_cast<U>(v) ) ;
@@ -1823,7 +1837,7 @@@@ -1881,50 +1882,44 @@
- Requires:
T
- shall meet requirements ofEqualityComparable
. + shall meet requirements ofEqualityComparable
.- Returns: If both
-x
@@ -1833,41 +1847,28 @@ If onlyx
ory
is initialized,false
. If both are uninitialized,true
.- - Throws: Nothing. -
- Notes: Pointers have shallow relational operators while
optional
- has deep relational operators. Do not useoperator - ==
directly in generic code which - expect to be given either anoptional<T>
or a pointer; useequal_pointees()
+ has deep relational operators. Do not useoperator==
directly in generic code which expect + to be given either anoptional<T>
or a pointer; useequal_pointees()
instead- Example: -
T x(12); -T y(12); -T z(21); -optional<T> def0 ; -optional<T> def1 ; -optional<T> optX(x); -optional<T> optY(y); -optional<T> optZ(z); +optional<T> oN, oN_; +optional<T> o1(T(1)), o1_(T(1)); +optional<T> o2(T(2)); -// Identity always hold -assert ( def0 == def0 ); -assert ( optX == optX ); +assert ( oN == oN ); // Identity implies equality +assert ( o1 == o1 ); // -// Both uninitialized compare equal -assert ( def0 == def1 ); +assert ( oN == oN_ ); // Both uninitialized compare equal -// Only one initialized compare unequal. -assert ( def0 != optX ); +assert ( oN != o1 ); // Initialized unequal to initialized. -// Both initialized compare as (*lhs == *rhs) -assert ( optX == optY ) ; -assert ( optX != optZ ) ; +assert ( o1 == o1_ ); // Both initialized compare as (*lhs == *rhs) +assert ( o1 != o2 ); //@@ -1935,16 +1930,11 @@
- - Requires:
T
- shall meet requirements ofLessThanComparable
. + Requires: Expression*x < *y
+ shall be well-formed and its result shall be convertible tobool
.- - Returns: If
-y
- is not initialized,false
. - Ify
is initialized and -x
is not initialized, -true
. If bothx
andy
- are initialized,(*x - < *y)
. -- - Throws: Nothing. + Returns:
(!y) ? false : (!x) ? true + : *x < *y
.- Notes: Pointers have shallow relational operators while
optional
- has deep relational operators. Do not useoperator - <
directly in generic code - which expect to be given either anoptional<T>
or a pointer; useless_pointees()
- instead. + has deep relational operators. Do not useoperator<
directly in generic code which expect + to be given either anoptional<T>
or a pointer; useless_pointees()
+ instead.T
need not be +LessThanComparable
. Only single +operator<
+ is required. Other relational operations are defined in terms of this + one. IfT
'soperator<
+ satisfies the axioms ofLessThanComparable
(transitivity, + antisymmetry and irreflexivity),optinal<T>
isLessThanComparable
.- Example: -
T x(12); -T y(34); -optional<T> def ; -optional<T> optX(x); -optional<T> optY(y); +optional<T> oN, oN_; +optional<T> o0(T(0)); +optional<T> o1(T(1)); -// Identity always hold -assert ( !(def < def) ); -assert ( optX == optX ); +assert ( !(oN < oN) ); // Identity implies equivalence +assert ( !(o1 < o1) ); -// Both uninitialized compare equal -assert ( def0 == def1 ); +assert ( !(oN < oN_) ); // Two uninitialized are equivalent +assert ( !(oN_ < oN) ); -// Only one initialized compare unequal. -assert ( def0 != optX ); +assert ( oN < o0 ); // Uninitialized is less than initialized +assert ( !(o0 < oN) ); -// Both initialized compare as (*lhs == *rhs) -assert ( optX == optY ) ; -assert ( optX != optZ ) ; +assert ( o1 < o2 ) ; // Two initialized compare as (*lhs < *rhs) +assert ( !(o2 < o1) ) ; +assert ( !(o2 < o2) ) ;bool operator != ( optional<T> const& x, optional<T> const& y );
--
- +
+
- Returns:
-!( x == y );
-- - Throws: Nothing. -
-@@ -1953,16 +1943,11 @@ > ( optional<T> const& x, optional<T> const& y ); -
![]()
-
- +
+
- Returns:
-( y < x );
-- - Throws: Nothing. -
-@@ -1971,16 +1956,11 @@ <= ( optional<T> const& x, optional<T> const& y ); -
![]()
-
- +
+
- Returns:
-!( y < x );
-- - Throws: Nothing. -
-@@ -1989,27 +1969,30 @@ >= ( optional<T> const& x, optional<T> const& y ); -
+-
- +
+ x < + y ); +
- Returns:
-!( - x<y );
-- - Throws: Nothing. -
-+
+
+
bool operator == ( optional<T> const& x, none_t ) noexcept;
+
bool operator + == ( none_t, optional<T> const& x ) noexcept;
+
- Returns:
!x
.- Notes:
T
- need not meet requirements ofEqualityComparable
. + need not meet requirements ofEqualityComparable
.@@ -2020,6 +2003,10 @@ != ( optional<T> const& x, none_t ) noexcept;
++
bool operator + != ( none_t, optional<T> const& x ) noexcept;
+
- Returns:
!( x == @@ -2035,12 +2022,37 @@
- - Effect: If both
+x
- andy
are initialized, - callsswap(*x,*y)
- usingstd::swap
. If only one is initialized, say -x
, calls:y.reset(*x); x.reset();
- If none is initialized, does nothing. + Requires: Lvalues of typeT
shall be swappable andT
shall beMoveConstructible
. +- + Effects: +
+
- + If
+!*this + && !rhs
, no effect, otherwise +- + if
+bool(*this) + && !rhs
, initializes the contained + value ofrhs
as + if direct-initializing an object of typeT
+ with the expressionstd::move(*(*this))
, followed byval->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 typeT
+ with the expressionstd::move(*rhs)
, followed byrhs.val->T::~T()
,*this
contains a value andrhs
does not contain a value, + otherwise +- + (if
+bool(*this) + && bool(rhs)
) callsswap(*(*this), *rhs)
. +- Postconditions: The states of
-x
andy
@@ -2052,17 +2064,6 @@ throws. If only one is initialized, whateverT::T ( T&& )
throws.- - Notes: If both are initialized,
-swap(T&,T&)
- is used unqualified but withstd::swap
- introduced in scope. If only one is initialized,T::~T()
andT::T( T&& )
- is called. -- - Exception Safety: If both are initialized, - this operation has the exception safety guarantees of
swap(T&,T&)
. If only one is initialized, it - has the same basic guarantee asoptional<T>::operator= ( T&& )
. -- Example:
T x(12); diff --git a/doc/html/index.html b/doc/html/index.html index 0380423..f217eaa 100644 --- a/doc/html/index.html +++ b/doc/html/index.html @@ -133,7 +133,7 @@
Last revised: June 20, 2014 at 09:06:52 GMT |
+Last revised: June 20, 2014 at 16:17:17 GMT |