From 726b227aa95848d8de9d8f0e0b2d0554d1101e41 Mon Sep 17 00:00:00 2001 From: Andrzej Krzemienski Date: Wed, 21 Jan 2015 00:10:51 +0100 Subject: [PATCH] operator<< improvements --- doc/00_optional.qbk | 15 ++-- doc/14_io.qbk | 37 ++++++++ ...erences.qbk => 15_optional_references.qbk} | 0 ...actories.qbk => 16_in_place_factories.qbk} | 0 ...optional_bool.qbk => 17_optional_bool.qbk} | 0 ...ion_safety.qbk => 18_exception_safety.qbk} | 0 ...uirements.qbk => 19_type_requirements.qbk} | 0 ..._performance.qbk => 1A_on_performance.qbk} | 0 doc/91_relnotes.qbk | 2 + doc/html/boost_optional/acknowledgements.html | 2 +- .../dependencies_and_portability.html | 2 +- .../optional_reference_binding.html | 2 +- doc/html/boost_optional/quick_start.html | 2 +- ...sing_unnecessary_default_construction.html | 2 +- .../optional_automatic_variables.html | 2 +- .../quick_start/optional_data_members.html | 2 +- .../quick_start/storage_in_containers.html | 2 +- .../reference/detailed_semantics.html | 2 +- doc/html/boost_optional/relnotes.html | 17 +++- .../tutorial/a_note_about_optional_bool_.html | 2 +- .../tutorial/design_overview.html | 2 +- .../design_overview/the_interface.html | 2 +- .../design_overview/the_semantics.html | 2 +- .../tutorial/exception_safety_guarantees.html | 2 +- .../tutorial/in_place_factories.html | 2 +- .../boost_optional/tutorial/io_operators.html | 87 +++++++++++++++++++ .../tutorial/optional_references.html | 8 +- .../tutorial/performance_considerations.html | 2 +- ...for_assignment_of_optional_references.html | 2 +- .../tutorial/relational_operators.html | 8 +- .../tutorial/type_requirements.html | 2 +- .../tutorial/when_to_use_optional.html | 2 +- doc/html/index.html | 5 +- doc/html/optional/reference.html | 2 +- doc/html/optional/tutorial.html | 3 +- include/boost/optional/optional.hpp | 9 +- include/boost/optional/optional_io.hpp | 3 +- test/Jamfile.v2 | 1 + test/optional_test_fail_io_without_io.cpp | 24 +++++ 39 files changed, 213 insertions(+), 46 deletions(-) create mode 100644 doc/14_io.qbk rename doc/{14_optional_references.qbk => 15_optional_references.qbk} (100%) rename doc/{15_in_place_factories.qbk => 16_in_place_factories.qbk} (100%) rename doc/{16_optional_bool.qbk => 17_optional_bool.qbk} (100%) rename doc/{17_exception_safety.qbk => 18_exception_safety.qbk} (100%) rename doc/{18_type_requirements.qbk => 19_type_requirements.qbk} (100%) rename doc/{19_on_performance.qbk => 1A_on_performance.qbk} (100%) create mode 100644 doc/html/boost_optional/tutorial/io_operators.html create mode 100644 test/optional_test_fail_io_without_io.cpp diff --git a/doc/00_optional.qbk b/doc/00_optional.qbk index 2f940b7..28532de 100644 --- a/doc/00_optional.qbk +++ b/doc/00_optional.qbk @@ -2,7 +2,7 @@ [quickbook 1.4] [authors [Cacciola Carballal, Fernando Luis]] [copyright 2003-2007 Fernando Luis Cacciola Carballal] - [copyright 2014 Andrzej Krzemieński] + [copyright 2014-2015 Andrzej Krzemieński] [category miscellaneous] [id optional] [dirname optional] @@ -80,12 +80,13 @@ This is how you solve it with `boost::optional`: [include 11_development.qbk] [include 12_when_to_use.qbk] [include 13_relational_operators.qbk] -[include 14_optional_references.qbk] -[include 15_in_place_factories.qbk] -[include 16_optional_bool.qbk] -[include 17_exception_safety.qbk] -[include 18_type_requirements.qbk] -[include 19_on_performance.qbk] +[include 14_io.qbk] +[include 15_optional_references.qbk] +[include 16_in_place_factories.qbk] +[include 17_optional_bool.qbk] +[include 18_exception_safety.qbk] +[include 19_type_requirements.qbk] +[include 1A_on_performance.qbk] [endsect] [section Reference] [include 20_reference.qbk] diff --git a/doc/14_io.qbk b/doc/14_io.qbk new file mode 100644 index 0000000..0fb4e89 --- /dev/null +++ b/doc/14_io.qbk @@ -0,0 +1,37 @@ + +[section IO operators] + +It is possible to use `optional` with IO streams, provided that `T` can be used with streams. IOStream operators are defined in a separate header. + +`` +#include +#include + +int main() +{ + boost::optional o1 = 1, oN = boost::none; + std::cout << o1; + std::cin >> oN; +} +`` + +The current implementation does not guarantee any particular output. What it guarantees is that if streaming out and then back in `T` gives the same value, then streaming out and then back in `optional` will also give back the same result: + +`` +#include +#include +#include + +int main() +{ + boost::optional o1 = 1, oN = boost::none; + boost::optional x1, x2; + std::stringstream s; + s << o1 << oN; + s >> x1 >> x2; + assert (o1 == x1); + assert (oN == x2); +} +`` + +[endsect] diff --git a/doc/14_optional_references.qbk b/doc/15_optional_references.qbk similarity index 100% rename from doc/14_optional_references.qbk rename to doc/15_optional_references.qbk diff --git a/doc/15_in_place_factories.qbk b/doc/16_in_place_factories.qbk similarity index 100% rename from doc/15_in_place_factories.qbk rename to doc/16_in_place_factories.qbk diff --git a/doc/16_optional_bool.qbk b/doc/17_optional_bool.qbk similarity index 100% rename from doc/16_optional_bool.qbk rename to doc/17_optional_bool.qbk diff --git a/doc/17_exception_safety.qbk b/doc/18_exception_safety.qbk similarity index 100% rename from doc/17_exception_safety.qbk rename to doc/18_exception_safety.qbk diff --git a/doc/18_type_requirements.qbk b/doc/19_type_requirements.qbk similarity index 100% rename from doc/18_type_requirements.qbk rename to doc/19_type_requirements.qbk diff --git a/doc/19_on_performance.qbk b/doc/1A_on_performance.qbk similarity index 100% rename from doc/19_on_performance.qbk rename to doc/1A_on_performance.qbk diff --git a/doc/91_relnotes.qbk b/doc/91_relnotes.qbk index 94a9c61..666571c 100644 --- a/doc/91_relnotes.qbk +++ b/doc/91_relnotes.qbk @@ -14,6 +14,8 @@ [heading Boost Release 1.58] * `boost::none_t` is no longer convertible from literal `0`. This avoids a bug where `optional> oi = 0;` would initialize an optional object with no contained value. +* 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. [heading Boost Release 1.57] diff --git a/doc/html/boost_optional/acknowledgements.html b/doc/html/boost_optional/acknowledgements.html index 9c8019a..d025d50 100644 --- a/doc/html/boost_optional/acknowledgements.html +++ b/doc/html/boost_optional/acknowledgements.html @@ -116,7 +116,7 @@ -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-PrevUpHomeNext +PrevUpHomeNext

@@ -101,7 +101,7 @@

-

-PrevUpHomeNext +PrevUpHomeNext
diff --git a/doc/html/boost_optional/tutorial/performance_considerations.html b/doc/html/boost_optional/tutorial/performance_considerations.html index d054e01..2e2d4ca 100644 --- a/doc/html/boost_optional/tutorial/performance_considerations.html +++ b/doc/html/boost_optional/tutorial/performance_considerations.html @@ -209,7 +209,7 @@
-
-