diff --git a/doc/91_relnotes.qbk b/doc/91_relnotes.qbk index 81449dc..1dced5f 100644 --- a/doc/91_relnotes.qbk +++ b/doc/91_relnotes.qbk @@ -13,7 +13,12 @@ [heading Boost Release X.XX] -* Now `boost::optional` is specialized for reference parameters. This way the `sizeof` of optional reference is that of a pointer, and a number of bugs is avoided. +* Now `boost::optional` is specialized for reference parameters. This addresses a couple of issues: + * the `sizeof` of optional reference is that of a pointer, + * some bugs connected to copying optional references are gone, + * you can swap optional references: it is like swapping pointers: shalow, underlying objects are not affected, + * optional references to abstract types work. +* Documented nested typedefs ([@https://svn.boost.org/trac/boost/ticket/5193 Trac #5193]). [heading Boost Release 1.60] diff --git a/doc/html/boost_optional/relnotes.html b/doc/html/boost_optional/relnotes.html index c920338..53b9020 100644 --- a/doc/html/boost_optional/relnotes.html +++ b/doc/html/boost_optional/relnotes.html @@ -31,11 +31,32 @@ Boost Release X.XX -

Boost diff --git a/doc/html/index.html b/doc/html/index.html index 2cdf6cd..15c6d1e 100644 --- a/doc/html/index.html +++ b/doc/html/index.html @@ -146,7 +146,7 @@ - +

Last revised: February 16, 2016 at 20:02:53 GMT

Last revised: February 16, 2016 at 22:59:47 GMT


diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index bcb3c75..765fe53 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -30,7 +30,6 @@ import testing ; [ 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_ref_swap.cpp ] [ run optional_test_inplace_factory.cpp ] [ run optional_test_io.cpp ] [ run optional_test_move.cpp ] diff --git a/test/optional_test_ref_assign_portable_minimum.cpp b/test/optional_test_ref_assign_portable_minimum.cpp index 2a548ab..9ee0a0f 100644 --- a/test/optional_test_ref_assign_portable_minimum.cpp +++ b/test/optional_test_ref_assign_portable_minimum.cpp @@ -38,7 +38,7 @@ void test_optional_ref_assignment() int main() { test_optional_ref_assignment(); - //test_optional_ref_assignment(); + test_optional_ref_assignment(); return boost::report_errors(); } diff --git a/test/optional_test_ref_convert_assign_non_int.cpp b/test/optional_test_ref_convert_assign_non_int.cpp index d59e46e..556b757 100644 --- a/test/optional_test_ref_convert_assign_non_int.cpp +++ b/test/optional_test_ref_convert_assign_non_int.cpp @@ -33,7 +33,7 @@ void test_all_const_cases() int main() { test_all_const_cases(); - //test_all_const_cases(); + test_all_const_cases(); return boost::report_errors(); } diff --git a/test/optional_test_ref_converting_ctor.cpp b/test/optional_test_ref_converting_ctor.cpp index d7df3dc..735c354 100644 --- a/test/optional_test_ref_converting_ctor.cpp +++ b/test/optional_test_ref_converting_ctor.cpp @@ -101,7 +101,7 @@ int main() { test_all_const_cases(); test_all_const_cases(); - //test_all_const_cases(); + test_all_const_cases(); return boost::report_errors(); } diff --git a/test/optional_test_ref_portable_minimum.cpp b/test/optional_test_ref_portable_minimum.cpp index e8439c9..a923804 100644 --- a/test/optional_test_ref_portable_minimum.cpp +++ b/test/optional_test_ref_portable_minimum.cpp @@ -256,11 +256,11 @@ void test_equality() BOOST_TEST( (o2 != oN)); } -template +template void test_order() { typename concrete_type_of::type v1(1), v2(2), v2_(2), v3(3); - optional o1(v1), o2(v2), o2_(v2_), o3(v3), o3_(v3), oN, oN_; + optional o1(v1), o2(v2), o2_(v2_), o3(v3), o3_(v3), oN, oN_; // o2 and o2_ point to different objects; o3 and o3_ point to the same object BOOST_TEST(!(oN < oN)); @@ -399,13 +399,35 @@ void test_order() BOOST_TEST(!(o3_ < oN_)); } -template +template void test_swap() { typename concrete_type_of::type v1(1), v2(2); - optional o1(v1), o1_(v1), o2(v2), o2_(v2), oN, oN_; + optional o1(v1), o1_(v1), o2(v2), o2_(v2), oN, oN_; - // swap(o1, o1); DOESN'T WORK + swap(o1, o1); + BOOST_TEST(o1); + BOOST_TEST(boost::addressof(*o1) == boost::addressof(v1)); + + swap(oN, oN_); + BOOST_TEST(!oN); + BOOST_TEST(!oN_); + + swap(o1, oN); + BOOST_TEST(!o1); + BOOST_TEST(oN); + BOOST_TEST(boost::addressof(*oN) == boost::addressof(v1)); + + swap(oN, o1); + BOOST_TEST(!oN); + BOOST_TEST(o1); + BOOST_TEST(boost::addressof(*o1) == boost::addressof(v1)); + + swap(o1_, o2_); + BOOST_TEST(o1_); + BOOST_TEST(o2_); + BOOST_TEST(boost::addressof(*o1_) == boost::addressof(v2)); + BOOST_TEST(boost::addressof(*o2_) == boost::addressof(v1)); } template @@ -431,18 +453,19 @@ void test_optional_const_ref() test_arrow_noconst_const(); test_equality(); test_order(); - //test_swap(); + test_swap(); + test_swap(); } int main() { test_optional_ref(); test_optional_ref(); - //test_optional_ref(); + test_optional_ref(); test_optional_const_ref(); test_optional_const_ref(); - //test_optional_const_ref(); + test_optional_const_ref(); return boost::report_errors(); } diff --git a/test/optional_test_ref_swap.cpp b/test/optional_test_ref_swap.cpp deleted file mode 100644 index c9a6986..0000000 --- a/test/optional_test_ref_swap.cpp +++ /dev/null @@ -1,106 +0,0 @@ -// Copyright (C) 2016 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 maintainer 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; - -struct Iface -{ - virtual void fun() = 0; - protected: ~Iface() {} -}; - -struct Impl : Iface -{ - void fun() {} -}; - -template -void test_swap_empty_with_empty() -{ - boost::optional o1, o2; - swap(o1, o2); - - BOOST_TEST(!o1); - BOOST_TEST(!o2); -} - -template -void test_swap_value_with_empty(U v1) -{ - boost::optional o1 (v1), o2; - swap(o1, o2); - - BOOST_TEST(!o1); - BOOST_TEST(o2); - BOOST_TEST(boost::addressof(*o2) == boost::addressof(v1)); -} - -template -void test_swap_empty_with_value(U v2) -{ - boost::optional o1, o2(v2); - swap(o1, o2); - - BOOST_TEST(o1); - BOOST_TEST(boost::addressof(*o1) == boost::addressof(v2)); - BOOST_TEST(!o2); -} - -template -void test_swap_value_with_value(U v1, U v2) -{ - boost::optional o1(v1), o2(v2); - swap(o1, o2); - - BOOST_TEST(o1); - BOOST_TEST(o2); - BOOST_TEST(boost::addressof(*o1) == boost::addressof(v2)); - BOOST_TEST(boost::addressof(*o2) == boost::addressof(v1)); -} - -int main() -{ - std::string s1 ("AAA"), s2 ("BB"); - int i1 = 1, i2 = 2; - Impl p1, p2; - - test_swap_empty_with_empty( ); - test_swap_value_with_empty(s1 ); - test_swap_empty_with_value( s2); - test_swap_value_with_value(s1, s2); - - test_swap_empty_with_empty( ); - test_swap_value_with_empty(i1 ); - test_swap_empty_with_value( i2); - test_swap_value_with_value(i1, i2); - - test_swap_empty_with_empty( ); - test_swap_value_with_empty(p1 ); - test_swap_empty_with_value( p2); - test_swap_value_with_value(p1, p2); - - test_swap_empty_with_empty( ); - test_swap_value_with_empty(p1 ); - test_swap_empty_with_value( p2); - test_swap_value_with_value(p1, p2); - - return boost::report_errors(); -}