From defe1c94d69513ad8ef64eff91dccd85f5950753 Mon Sep 17 00:00:00 2001 From: Beman Dawes Date: Tue, 7 Nov 2006 19:11:57 +0000 Subject: [PATCH 01/24] Add copyright, license [SVN r35905] --- index.html | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/index.html b/index.html index 3b6f47e..030ae38 100644 --- a/index.html +++ b/index.html @@ -3,6 +3,11 @@ -Automatic redirection failed, please go to doc/tuple_users_guide.html +Automatic redirection failed, please go to doc/tuple_users_guide.html
+

© Copyright Beman Dawes, 2001

+

Distributed under the Boost Software License, Version 1.0. (See accompanying +file LICENSE_1_0.txt or copy +at www.boost.org/LICENSE_1_0.txt)

\ No newline at end of file From 0af5b764429244dff60e785c6e9d37fca0ae7e80 Mon Sep 17 00:00:00 2001 From: Daniel James Date: Sun, 7 Jan 2007 23:50:56 +0000 Subject: [PATCH 02/24] Merge fixed links from RC_1_34_0. [SVN r36660] --- index.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.html b/index.html index 030ae38..d8c1cf8 100644 --- a/index.html +++ b/index.html @@ -7,7 +7,7 @@ Automatic redirection failed, please go to  

© Copyright Beman Dawes, 2001

Distributed under the Boost Software License, Version 1.0. (See accompanying -file LICENSE_1_0.txt or copy +file LICENSE_1_0.txt or copy at www.boost.org/LICENSE_1_0.txt)

- \ No newline at end of file + From 19b8004830f88f8a60ab35647e69647a419221c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaakko=20J=C3=A4rvi?= Date: Tue, 6 Feb 2007 00:23:26 +0000 Subject: [PATCH 03/24] Fixed a typo. [SVN r36896] --- doc/tuple_advanced_interface.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/tuple_advanced_interface.html b/doc/tuple_advanced_interface.html index 4eb3ed8..9fefe6d 100644 --- a/doc/tuple_advanced_interface.html +++ b/doc/tuple_advanced_interface.html @@ -101,7 +101,7 @@ For a one-element cons list the tail argument (null_type) can be om

The template access_traits defines three type functions. Let T be a type of an element in a tuple:

    -
  1. access_traits<T>::type maps T to the return type of the non-const access functions (nonmeber and member get functions, and the get_head function).
  2. +
  3. access_traits<T>::non_const_type maps T to the return type of the non-const access functions (nonmeber and member get functions, and the get_head function).
  4. access_traits<T>::const_type maps T to the return type of the const access functions.
  5. access_traits<T>::parameter_type maps T to the parameter type of the tuple constructor.
From d08c9bfab1e43e9866152229f596523e99ec0688 Mon Sep 17 00:00:00 2001 From: Vladimir Prus Date: Wed, 8 Aug 2007 19:42:04 +0000 Subject: [PATCH 04/24] Update to V2 [SVN r38530] --- test/Jamfile | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/test/Jamfile b/test/Jamfile index 16d0431..66574f6 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -1,20 +1,8 @@ -subproject libs/tuple/test ; -unit-test tuple_test_bench - : tuple_test_bench.cpp - ../../test/build/boost_test_exec_monitor - : $(BOOST_ROOT) - ; - -unit-test io_test - : io_test.cpp - ../../test/build/boost_test_exec_monitor - : $(BOOST_ROOT) - ; - -unit-test another_tuple_test_bench - : another_tuple_test_bench.cpp - ../../test/build/boost_test_exec_monitor - : $(BOOST_ROOT) - ; +project : requirements /boost/test//boost_test_exec_monitor ; +test-suite tuple : + [ run tuple_test_bench.cpp ] + [ run io_test.cpp ] + [ run another_tuple_test_bench.cpp ] + ; \ No newline at end of file From 62d366fa6843885e4b4286acd6e0237a8c40c471 Mon Sep 17 00:00:00 2001 From: Daniel James Date: Sun, 10 Feb 2008 14:56:22 +0000 Subject: [PATCH 05/24] Link to people pages on the website, as they've been removed from the download. [SVN r43209] --- doc/tuple_users_guide.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/tuple_users_guide.html b/doc/tuple_users_guide.html index e794a8e..c448b1a 100644 --- a/doc/tuple_users_guide.html +++ b/doc/tuple_users_guide.html @@ -516,7 +516,7 @@ Järvi J.: ML-Style Tuple Assignment in Standard C++ - Extending the Mult

Last modified 2003-09-07

-

© Copyright Jaakko Järvi 2001. +

© Copyright Jaakko Järvi 2001. Permission to copy, use, modify, sell and distribute this software and its documentation is granted provided this copyright notice appears in all copies. This software and its documentation is provided "as is" without express or implied warranty, and with no claim as to its suitability for any purpose. From a30a7f960460796a19e4f8b89dc280399eec59c0 Mon Sep 17 00:00:00 2001 From: Beman Dawes Date: Sat, 28 Jun 2008 13:45:21 +0000 Subject: [PATCH 06/24] =?UTF-8?q?With=20his=20kind=20permission,=20change?= =?UTF-8?q?=20Jaakko=20"J=C3=A4rvi"=20to=20"Jarvi"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [SVN r46808] --- include/boost/tuple/detail/tuple_basic.hpp | 2 +- include/boost/tuple/detail/tuple_basic_no_partial_spec.hpp | 2 +- include/boost/tuple/tuple.hpp | 2 +- include/boost/tuple/tuple_comparison.hpp | 2 +- include/boost/tuple/tuple_io.hpp | 2 +- test/another_tuple_test_bench.cpp | 2 +- test/io_test.cpp | 2 +- test/tuple_test_bench.cpp | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/include/boost/tuple/detail/tuple_basic.hpp b/include/boost/tuple/detail/tuple_basic.hpp index 9341fbc..ba59441 100644 --- a/include/boost/tuple/detail/tuple_basic.hpp +++ b/include/boost/tuple/detail/tuple_basic.hpp @@ -1,6 +1,6 @@ // tuple_basic.hpp ----------------------------------------------------- -// Copyright (C) 1999, 2000 Jaakko Järvi (jaakko.jarvi@cs.utu.fi) +// Copyright (C) 1999, 2000 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi) // // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at diff --git a/include/boost/tuple/detail/tuple_basic_no_partial_spec.hpp b/include/boost/tuple/detail/tuple_basic_no_partial_spec.hpp index d0275d4..bb38662 100644 --- a/include/boost/tuple/detail/tuple_basic_no_partial_spec.hpp +++ b/include/boost/tuple/detail/tuple_basic_no_partial_spec.hpp @@ -1,6 +1,6 @@ // - tuple_basic_no_partial_spec.hpp ----------------------------------------- -// Copyright (C) 1999, 2000 Jaakko Järvi (jaakko.jarvi@cs.utu.fi) +// Copyright (C) 1999, 2000 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi) // Copyright (C) 2001 Douglas Gregor (gregod@rpi.edu) // Copyright (C) 2001 Gary Powell (gary.powell@sierra.com) // diff --git a/include/boost/tuple/tuple.hpp b/include/boost/tuple/tuple.hpp index ee7fbc4..7703597 100644 --- a/include/boost/tuple/tuple.hpp +++ b/include/boost/tuple/tuple.hpp @@ -1,6 +1,6 @@ // tuple.hpp - Boost Tuple Library -------------------------------------- -// Copyright (C) 1999, 2000 Jaakko Järvi (jaakko.jarvi@cs.utu.fi) +// Copyright (C) 1999, 2000 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi) // // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at diff --git a/include/boost/tuple/tuple_comparison.hpp b/include/boost/tuple/tuple_comparison.hpp index 00ddd14..178bbb9 100644 --- a/include/boost/tuple/tuple_comparison.hpp +++ b/include/boost/tuple/tuple_comparison.hpp @@ -1,6 +1,6 @@ // tuple_comparison.hpp ----------------------------------------------------- // -// Copyright (C) 2001 Jaakko Järvi (jaakko.jarvi@cs.utu.fi) +// Copyright (C) 2001 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi) // Copyright (C) 2001 Gary Powell (gary.powell@sierra.com) // // Distributed under the Boost Software License, Version 1.0. (See diff --git a/include/boost/tuple/tuple_io.hpp b/include/boost/tuple/tuple_io.hpp index 40c2599..b355e56 100644 --- a/include/boost/tuple/tuple_io.hpp +++ b/include/boost/tuple/tuple_io.hpp @@ -1,6 +1,6 @@ // tuple_io.hpp -------------------------------------------------------------- -// Copyright (C) 2001 Jaakko Järvi (jaakko.jarvi@cs.utu.fi) +// Copyright (C) 2001 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi) // 2001 Gary Powell (gary.powell@sierra.com) // // Distributed under the Boost Software License, Version 1.0. (See diff --git a/test/another_tuple_test_bench.cpp b/test/another_tuple_test_bench.cpp index 34080d4..1d1e535 100644 --- a/test/another_tuple_test_bench.cpp +++ b/test/another_tuple_test_bench.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 1999, 2000 Jaakko Järvi (jaakko.jarvi@cs.utu.fi) +// Copyright (C) 1999, 2000 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi) // // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at diff --git a/test/io_test.cpp b/test/io_test.cpp index d376534..f65ad42 100644 --- a/test/io_test.cpp +++ b/test/io_test.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 1999, 2000 Jaakko Järvi (jaakko.jarvi@cs.utu.fi) +// Copyright (C) 1999, 2000 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi) // // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at diff --git a/test/tuple_test_bench.cpp b/test/tuple_test_bench.cpp index 65e7695..134815f 100644 --- a/test/tuple_test_bench.cpp +++ b/test/tuple_test_bench.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 1999, 2000 Jaakko Järvi (jaakko.jarvi@cs.utu.fi) +// Copyright (C) 1999, 2000 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi) // // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at From 776be602e508e609222c8cb122e4ea7caf8d2641 Mon Sep 17 00:00:00 2001 From: "Michael A. Jackson" Date: Sat, 1 Nov 2008 13:15:41 +0000 Subject: [PATCH 07/24] Continuing merge of CMake build system files into trunk with the encouragement of Doug Gregor [SVN r49510] --- CMakeLists.txt | 21 +++++++++++++++++++++ test/CMakeLists.txt | 2 ++ 2 files changed, 23 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 test/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..26cf773 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,21 @@ +#---------------------------------------------------------------------------- +# This file was automatically generated from the original CMakeLists.txt file +# Add a variable to hold the headers for the library +set (lib_headers + tuple +) + +# Add a library target to the build system +boost_library_project( + tuple + # SRCDIRS + TESTDIRS test + HEADERS ${lib_headers} + # DOCDIRS + DESCRIPTION "Ease definition of functions returning multiple values, and more." + MODULARIZED + AUTHORS "Jaakko Jarvi " + # MAINTAINERS +) + + diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000..6fa2d20 --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,2 @@ +boost_test_run(tuple_test_bench DEPENDS boost_test_exec_monitor) +boost_test_run(io_test DEPENDS boost_test_exec_monitor) From 4e452cb734c1dde597cf46dc09492348cef1bd1e Mon Sep 17 00:00:00 2001 From: "Michael A. Jackson" Date: Fri, 7 Nov 2008 17:02:56 +0000 Subject: [PATCH 08/24] Updating CMake files to latest trunk. Added dependency information for regression tests and a few new macros for internal use. [SVN r49627] --- test/CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 6fa2d20..c61971b 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,2 +1,5 @@ +boost_additional_test_dependencies(tuple BOOST_DEPENDS test) + + boost_test_run(tuple_test_bench DEPENDS boost_test_exec_monitor) boost_test_run(io_test DEPENDS boost_test_exec_monitor) From 1d1970d81d1739a3e1839f27eaea4cbcef73911e Mon Sep 17 00:00:00 2001 From: "Michael A. Jackson" Date: Fri, 7 Nov 2008 17:05:27 +0000 Subject: [PATCH 09/24] Updating dependency information for modularized libraries. [SVN r49628] --- module.cmake | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 module.cmake diff --git a/module.cmake b/module.cmake new file mode 100644 index 0000000..4c52344 --- /dev/null +++ b/module.cmake @@ -0,0 +1,2 @@ +boost_module(tuple DEPENDS static_assert) + From e9dc95ae935b4de1ac4ab2772a13cad568aa105d Mon Sep 17 00:00:00 2001 From: Steven Watanabe Date: Thu, 26 Feb 2009 02:35:44 +0000 Subject: [PATCH 10/24] Supress gcc warning. Fixes #2388 [SVN r51449] --- include/boost/tuple/tuple_comparison.hpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/boost/tuple/tuple_comparison.hpp b/include/boost/tuple/tuple_comparison.hpp index 178bbb9..73723a1 100644 --- a/include/boost/tuple/tuple_comparison.hpp +++ b/include/boost/tuple/tuple_comparison.hpp @@ -69,8 +69,8 @@ inline bool neq(const null_type&, const null_type&) { retur template inline bool lt(const T1& lhs, const T2& rhs) { return lhs.get_head() < rhs.get_head() || - !(rhs.get_head() < lhs.get_head()) && - lt(lhs.get_tail(), rhs.get_tail()); + ( !(rhs.get_head() < lhs.get_head()) && + lt(lhs.get_tail(), rhs.get_tail())); } template<> inline bool lt(const null_type&, const null_type&) { return false; } @@ -78,8 +78,8 @@ inline bool lt(const null_type&, const null_type&) { return template inline bool gt(const T1& lhs, const T2& rhs) { return lhs.get_head() > rhs.get_head() || - !(rhs.get_head() > lhs.get_head()) && - gt(lhs.get_tail(), rhs.get_tail()); + ( !(rhs.get_head() > lhs.get_head()) && + gt(lhs.get_tail(), rhs.get_tail())); } template<> inline bool gt(const null_type&, const null_type&) { return false; } From 451415ebce0aec1bb51eeed7d7ae433184f19028 Mon Sep 17 00:00:00 2001 From: Joel de Guzman Date: Fri, 20 Mar 2009 01:21:42 +0000 Subject: [PATCH 11/24] fixed tuples::length not having a specialization for const tuple<> and const null_type [SVN r51862] --- include/boost/tuple/detail/tuple_basic.hpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/include/boost/tuple/detail/tuple_basic.hpp b/include/boost/tuple/detail/tuple_basic.hpp index ba59441..348fd80 100644 --- a/include/boost/tuple/detail/tuple_basic.hpp +++ b/include/boost/tuple/detail/tuple_basic.hpp @@ -213,7 +213,7 @@ struct element_impl<0, T, true /* IsConst */> template -struct element: +struct element: public detail::element_impl::value> { }; @@ -488,11 +488,20 @@ struct length > { BOOST_STATIC_CONSTANT(int, value = 0); }; +template<> +struct length const> { + BOOST_STATIC_CONSTANT(int, value = 0); +}; + template<> struct length { BOOST_STATIC_CONSTANT(int, value = 0); }; +template<> +struct length { + BOOST_STATIC_CONSTANT(int, value = 0); +}; namespace detail { From 70e04d2965f58713746e78bfbb8cfd0dcd8fe65f Mon Sep 17 00:00:00 2001 From: Daniel James Date: Sat, 21 Mar 2009 15:35:35 +0000 Subject: [PATCH 12/24] Fix html. [SVN r51881] --- doc/tuple_advanced_interface.html | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/doc/tuple_advanced_interface.html b/doc/tuple_advanced_interface.html index 9fefe6d..cde11c5 100644 --- a/doc/tuple_advanced_interface.html +++ b/doc/tuple_advanced_interface.html @@ -2,14 +2,13 @@ Tuple library advanced features + + C++ Boost - - -

Tuple library advanced features

The advanced features described in this document are all under namespace ::boost::tuples From 08277fd057a9bd5a5c5481327ec47bec1a2cda24 Mon Sep 17 00:00:00 2001 From: Steven Watanabe Date: Sat, 23 May 2009 16:39:13 +0000 Subject: [PATCH 13/24] Allow printing an empty tuple [SVN r53211] --- include/boost/tuple/tuple_io.hpp | 32 ++++++++++++++++++++++++++++++++ test/io_test.cpp | 26 +++++++++++++++++++++----- 2 files changed, 53 insertions(+), 5 deletions(-) diff --git a/include/boost/tuple/tuple_io.hpp b/include/boost/tuple/tuple_io.hpp index b355e56..10cdb1c 100644 --- a/include/boost/tuple/tuple_io.hpp +++ b/include/boost/tuple/tuple_io.hpp @@ -285,6 +285,21 @@ print(std::basic_ostream& o, const cons& t) { } // namespace detail #if defined (BOOST_NO_TEMPLATED_STREAMS) + +inline std::ostream& operator<<(std::ostream& o, const null_type& t) { + if (!o.good() ) return o; + + const char l = + detail::format_info::get_manipulator(o, detail::format_info::open); + const char r = + detail::format_info::get_manipulator(o, detail::format_info::close); + + o << l; + o << r; + + return o; +} + template inline std::ostream& operator<<(std::ostream& o, const cons& t) { if (!o.good() ) return o; @@ -305,6 +320,23 @@ inline std::ostream& operator<<(std::ostream& o, const cons& t) { #else +template +inline std::basic_ostream& +operator<<(std::basic_ostream& o, + const null_type& t) { + if (!o.good() ) return o; + + const CharType l = + detail::format_info::get_manipulator(o, detail::format_info::open); + const CharType r = + detail::format_info::get_manipulator(o, detail::format_info::close); + + o << l; + o << r; + + return o; +} + template inline std::basic_ostream& operator<<(std::basic_ostream& o, diff --git a/test/io_test.cpp b/test/io_test.cpp index f65ad42..ea5460f 100644 --- a/test/io_test.cpp +++ b/test/io_test.cpp @@ -70,6 +70,15 @@ int test_main(int argc, char * argv[] ) { os1 << make_tuple(1, 2, 3); BOOST_CHECK (os1.str() == std::string("[1,2,3][1,2,3]") ); + // check empty tuple. + useThisOStringStream os3; + os3 << make_tuple(); + BOOST_CHECK (os3.str() == std::string("()") ); + os3 << set_open('['); + os3 << set_close(']'); + os3 << make_tuple(); + BOOST_CHECK (os3.str() == std::string("()[]") ); + ofstream tmp("temp.tmp"); #if !defined (BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) @@ -98,12 +107,19 @@ int test_main(int argc, char * argv[] ) { // reading tuple in format (a b c); - useThisIStringStream is("(100 200 300)"); - - tuple ti; - BOOST_CHECK(bool(is >> ti)); - BOOST_CHECK(ti == make_tuple(100, 200, 300)); + useThisIStringStream is1("(100 200 300)"); + tuple ti1; + BOOST_CHECK(bool(is1 >> ti1)); + BOOST_CHECK(ti1 == make_tuple(100, 200, 300)); + + useThisIStringStream is2("()"); + tuple<> ti2; + BOOST_CHECK(bool(is2 >> ti2)); + useThisIStringStream is3("[]"); + is3 >> set_open('['); + is3 >> set_close(']'); + BOOST_CHECK(bool(is3 >> ti2)); // Note that strings are problematic: // writing a tuple on a stream and reading it back doesn't work in From e89ea11d63cc7b230f9fd469f19e100285c26e97 Mon Sep 17 00:00:00 2001 From: Steven Watanabe Date: Sat, 23 May 2009 16:49:33 +0000 Subject: [PATCH 14/24] Avoid ambiguites between std and boost components in C++0x mode. Fixes #3026 [SVN r53212] --- test/another_tuple_test_bench.cpp | 1 - test/io_test.cpp | 17 ++++++++--------- test/tuple_test_bench.cpp | 3 +-- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/test/another_tuple_test_bench.cpp b/test/another_tuple_test_bench.cpp index 1d1e535..15074da 100644 --- a/test/another_tuple_test_bench.cpp +++ b/test/another_tuple_test_bench.cpp @@ -23,7 +23,6 @@ #include #include -using namespace std; using namespace boost; using namespace boost::tuples; diff --git a/test/io_test.cpp b/test/io_test.cpp index ea5460f..cf6dfb0 100644 --- a/test/io_test.cpp +++ b/test/io_test.cpp @@ -27,15 +27,14 @@ #include #endif -using namespace std; using namespace boost; #if defined BOOST_NO_STRINGSTREAM -typedef ostrstream useThisOStringStream; -typedef istrstream useThisIStringStream; +typedef std::ostrstream useThisOStringStream; +typedef std::istrstream useThisIStringStream; #else -typedef ostringstream useThisOStringStream; -typedef istringstream useThisIStringStream; +typedef std::ostringstream useThisOStringStream; +typedef std::istringstream useThisIStringStream; #endif int test_main(int argc, char * argv[] ) { @@ -79,19 +78,19 @@ int test_main(int argc, char * argv[] ) { os3 << make_tuple(); BOOST_CHECK (os3.str() == std::string("()[]") ); - ofstream tmp("temp.tmp"); + std::ofstream tmp("temp.tmp"); #if !defined (BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) tmp << make_tuple("One", "Two", 3); #endif tmp << set_delimiter(':'); - tmp << make_tuple(1000, 2000, 3000) << endl; + tmp << make_tuple(1000, 2000, 3000) << std::endl; tmp.close(); // When teading tuples from a stream, manipulators must be set correctly: - ifstream tmp3("temp.tmp"); - tuple j; + std::ifstream tmp3("temp.tmp"); + tuple j; #if !defined (BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) tmp3 >> j; diff --git a/test/tuple_test_bench.cpp b/test/tuple_test_bench.cpp index 134815f..eec9e1c 100644 --- a/test/tuple_test_bench.cpp +++ b/test/tuple_test_bench.cpp @@ -21,7 +21,6 @@ #include #include -using namespace std; using namespace boost; // ---------------------------------------------------------------------------- @@ -274,7 +273,7 @@ make_tuple_test() BOOST_CHECK(get<1>(t1) == 'a'); tuple t2; - t2 = make_tuple((short int)2, std::string("Hi")); + t2 = boost::make_tuple((short int)2, std::string("Hi")); BOOST_CHECK(get<0>(t2) == 2); BOOST_CHECK(get<1>(t2) == "Hi"); From b7c2e00b646172027ae1a25b119344c5f0c5f1f2 Mon Sep 17 00:00:00 2001 From: Steven Watanabe Date: Sat, 23 May 2009 18:59:02 +0000 Subject: [PATCH 15/24] Fix typos/markup problems in tuple docs. Fixes # [SVN r53218] --- doc/design_decisions_rationale.html | 52 ++++++----- doc/tuple_advanced_interface.html | 38 ++++---- doc/tuple_users_guide.html | 140 +++++++++++++++------------- 3 files changed, 119 insertions(+), 111 deletions(-) diff --git a/doc/design_decisions_rationale.html b/doc/design_decisions_rationale.html index ec05494..21f7457 100644 --- a/doc/design_decisions_rationale.html +++ b/doc/design_decisions_rationale.html @@ -1,3 +1,4 @@ + Design decisions rationale for Boost Tuple Library @@ -20,8 +21,8 @@ Tuples were originally under a subnamespace. As a result of the discussion, tuple definitions were moved directly under the boost namespace. As a result of a continued discussion, the subnamespace was reintroduced. The final (I truly hope so) solution is now to have all definitions in namespace ::boost::tuples, and the most common names in the ::boost namespace as well. -This is accomplished with using declarations (suggested by Dave Abrahams): -
namespace boost {
+This is accomplished with using declarations (suggested by Dave Abrahams):

+
namespace boost {
   namespace tuples {
       ...      
     // All library code
@@ -32,8 +33,8 @@ This is accomplished with using declarations (suggested by Dave Abrahams):
   using tuples::tie;
   using tuples::get;
 }
-
-With this arrangement, tuple creation with direct constructor calls, make_tuple or tie functions do not need the namespace qualifier. +
+

With this arrangement, tuple creation with direct constructor calls, make_tuple or tie functions do not need the namespace qualifier. Further, all functions that manipulate tuples are found with Koenig-lookup. The only exceptions are the get<N> functions, which are always called with an explicitly qualified template argument, and thus Koenig-lookup does not apply. Therefore, get is lifted to ::boost namespace with a using declaration. @@ -54,9 +55,9 @@ The rationale for not using the most natural name 'tuple' is to avoid having an Namespace names are, however, not generally in plural form in boost libraries. First, no real trouble was reported for using the same name for a namespace and a class and we considered changing the name 'tuples' to 'tuple'. But we found some trouble after all. -Both gcc and edg compilers reject using declarations where the namespace and class names are identical: +Both gcc and edg compilers reject using declarations where the namespace and class names are identical:

-
namespace boost {
+
namespace boost {
   namespace tuple {
     ... tie(...);
     class tuple; 
@@ -66,13 +67,13 @@ Both gcc and edg compilers reject using declarations where the namespace and cla
   using tuple::tuple; // error
     ...
 }
-
+
-Note, however, that a corresponding using declaration in the global namespace seems to be ok: +

Note, however, that a corresponding using declaration in the global namespace seems to be ok:

-
+

 using boost::tuple::tuple; // ok;
-
+

The end mark of the cons list (nil, null_type, ...)

@@ -80,14 +81,15 @@ using boost::tuple::tuple; // ok;

Tuples are internally represented as cons lists: -

tuple<int, int>
-
-inherits from -
cons<int, cons<int, null_type> >
+
tuple<int, int>
+
+

inherits from

+
cons<int, cons<int, null_type> >
 
+

null_type is the end mark of the list. Original proposition was nil, but the name is used in MacOS, and might have caused problems, so null_type was chosen instead. -Other names considered were null_t and unit (the empty tuple type in SML). +Other names considered were null_t and unit (the empty tuple type in SML).

Note that null_type is the internal representation of an empty tuple: tuple<> inherits from null_type.

@@ -95,22 +97,22 @@ Note that null_type is the internal representation of an empty tupl

Element indexing

-Whether to use 0- or 1-based indexing was discussed more than thoroughly, and the following observations were made: +Whether to use 0- or 1-based indexing was discussed more than thoroughly, and the following observations were made:

  • 0-based indexing is 'the C++ way' and used with arrays etc.
  • 1-based 'name like' indexing exists as well, eg. bind1st, bind2nd, pair::first, etc.
-Tuple access with the syntax get<N>(a), or a.get<N>() (where a is a tuple and N an index), was considered to be of the first category, hence, the index of the first element in a tuple is 0. +

Tuple access with the syntax get<N>(a), or a.get<N>() (where a is a tuple and N an index), was considered to be of the first category, hence, the index of the first element in a tuple is 0.

A suggestion to provide 1-based 'name like' indexing with constants like _1st, _2nd, _3rd, ... was made. By suitably chosen constant types, this would allow alternative syntaxes: -

a.get<0>() == a.get(_1st) == a[_1st] == a(_1st);
-
+
a.get<0>() == a.get(_1st) == a[_1st] == a(_1st);
+
-We chose not to provide more than one indexing method for the following reasons: +

We chose not to provide more than one indexing method for the following reasons:

  • 0-based indexing might not please everyone, but once its fixed, it is less confusing than having two different methods (would anyone want such constants for arrays?).
  • Adding the other indexing scheme doesn't really provide anything new (like a new feature) to the user of the library.
  • @@ -125,18 +127,18 @@ Such constants are easy to add.

    Tuple comparison

    -The comparison operator implements lexicographical order. -Other orderings were considered, mainly dominance (a < b iff for each i a(i) < b(i)). -Our belief is, that lexicographical ordering, though not mathematically the most natural one, is the most frequently needed ordering in everyday programming. +

    The comparison operator implements lexicographical order. +Other orderings were considered, mainly dominance (a < b iff for each i a(i) < b(i)). +Our belief is, that lexicographical ordering, though not mathematically the most natural one, is the most frequently needed ordering in everyday programming.

    Streaming

    The characters specified with tuple stream manipulators are stored within the space allocated by ios_base::xalloc, which allocates storage for long type objects. static_cast is used in casting between long and the stream's character type. -Streams that have character types not convertible back and forth to long thus fail to compile. +Streams that have character types not convertible back and forth to long thus fail to compile.

    -This may be revisited at some point. The two possible solutions are: +

    This may be revisited at some point. The two possible solutions are:

    • Allow only plain char types as the tuple delimiters and use widen and narrow to convert between the real character type of the stream. This would always compile, but some calls to set manipulators might result in a different diff --git a/doc/tuple_advanced_interface.html b/doc/tuple_advanced_interface.html index cde11c5..c783f02 100644 --- a/doc/tuple_advanced_interface.html +++ b/doc/tuple_advanced_interface.html @@ -15,39 +15,39 @@ The advanced features described in this document are all under namespace :

      Metafunctions for tuple types

      -Suppose T is a tuple type, and N is a constant integral expression. +Suppose T is a tuple type, and N is a constant integral expression.

      -
      element<N, T>::type
      +
      element<N, T>::type
      -gives the type of the Nth element in the tuple type T. If T is const, the resulting type is const qualified as well. +

      gives the type of the Nth element in the tuple type T. If T is const, the resulting type is const qualified as well. Note that the constness of T does not affect reference type elements.

      -
      length<T>::value
      +
      length<T>::value
      -gives the length of the tuple type T. +

      gives the length of the tuple type T.

      Cons lists

      Tuples are internally represented as cons lists. -For example, the tuple +For example, the tuple

      -
      tuple<A, B, C, D>
      +
      tuple<A, B, C, D>
      - inherits from the type -
      cons<A, cons<B, cons<C, cons<D, null_type> > > >
      -
      +

      inherits from the type

      +
      cons<A, cons<B, cons<C, cons<D, null_type> > > >
      +
      -The tuple template provides the typedef inherited to access the cons list representation. E.g.: +

      The tuple template provides the typedef inherited to access the cons list representation. E.g.: tuple<A>::inherited is the type cons<A, null_type>.

      Empty tuple

      -The internal representation of the empty tuple tuple<> is null_type. +The internal representation of the empty tuple tuple<> is null_type.

      Head and tail

      @@ -83,11 +83,11 @@ inline void set_to_zero(cons<H, T>& x) { x.get_head() = 0; set_to_zero A cons list can be default constructed provided that all its elements can be default constructed.

      -A cons list can be constructed from its head and tail. The prototype of the constructor is: +A cons list can be constructed from its head and tail. The prototype of the constructor is:

      cons(typename access_traits<head_type>::parameter_type h,
            const tail_type& t)
       
      -The traits template for the head parameter selects correct parameter types for different kinds of element types (for reference elements the parameter type equals the element type, for non-reference types the parameter type is a reference to const non-volatile element type). +

      The traits template for the head parameter selects correct parameter types for different kinds of element types (for reference elements the parameter type equals the element type, for non-reference types the parameter type is a reference to const non-volatile element type).

      For a one-element cons list the tail argument (null_type) can be omitted. @@ -98,16 +98,16 @@ For a one-element cons list the tail argument (null_type) can be om

      access_traits

      -The template access_traits defines three type functions. Let T be a type of an element in a tuple: +The template access_traits defines three type functions. Let T be a type of an element in a tuple:

        -
      1. access_traits<T>::non_const_type maps T to the return type of the non-const access functions (nonmeber and member get functions, and the get_head function).
      2. +
      3. access_traits<T>::non_const_type maps T to the return type of the non-const access functions (nonmember and member get functions, and the get_head function).
      4. access_traits<T>::const_type maps T to the return type of the const access functions.
      5. access_traits<T>::parameter_type maps T to the parameter type of the tuple constructor.

      make_tuple_traits

      -The element types of the tuples that are created with the make_tuple functions are computed with the type function make_tuple_traits. -The type function call make_tuple_traits<T>::type implements the following type mapping: +

      The element types of the tuples that are created with the make_tuple functions are computed with the type function make_tuple_traits. +The type function call make_tuple_traits<T>::type implements the following type mapping:

      • any reference type -> compile time error
      • @@ -119,7 +119,7 @@ The type function call make_tuple_traits<T>::type implements
      -Objects of type reference_wrapper are created with the ref and cref functions (see The make_tuple function.) +

      Objects of type reference_wrapper are created with the ref and cref functions (see The make_tuple function.)

      Reference wrappers were originally part of the tuple library, but they are now a general utility of boost. diff --git a/doc/tuple_users_guide.html b/doc/tuple_users_guide.html index c448b1a..c68edfc 100644 --- a/doc/tuple_users_guide.html +++ b/doc/tuple_users_guide.html @@ -1,3 +1,4 @@ + The Boost Tuple Library @@ -53,20 +54,22 @@ To compensate for this "deficiency", the Boost Tuple Library implement

      Using the library

      -

      To use the library, just include: +

      To use the library, just include:

      #include "boost/tuple/tuple.hpp"
      -

      Comparison operators can be included with: +

      Comparison operators can be included with:

      #include "boost/tuple/tuple_comparison.hpp"
      -

      To use tuple input and output operators, +

      To use tuple input and output operators,

      #include "boost/tuple/tuple_io.hpp"
      -Both tuple_io.hpp and tuple_comparison.hpp include tuple.hpp. +

      Both tuple_io.hpp and tuple_comparison.hpp include tuple.hpp.

      -

      All definitions are in namespace ::boost::tuples, but the most common names are lifted to namespace ::boost with using declarations. These names are: tuple, make_tuple, tie and get. Further, ref and cref are defined directly under the ::boost namespace. +

      All definitions are in namespace ::boost::tuples, but the most common names are lifted to namespace +::boost with using declarations. These names are: tuple, make_tuple, tie and get. +Further, ref and cref are defined directly under the ::boost namespace.

      Tuple types

      @@ -80,11 +83,11 @@ C++ types, but objects of such types cannot exist. Hence, if a tuple type contains such types as elements, the tuple type can exist, but not an object of that type. There are natural limitations for element types that cannot -be be copied, or that are not default constructible (see 'Constructing tuples' - below). +be copied, or that are not default constructible (see 'Constructing tuples' + below).

      -For example, the following definitions are valid tuple instantiations (A, B and C are some user defined classes): +For example, the following definitions are valid tuple instantiations (A, B and C are some user defined classes):

      tuple<int>
       tuple<double&, const double&, const double, double*, const double*>
      @@ -98,7 +101,7 @@ tuple<A*, tuple<const A*, const B&, C>, bool, void*>
       

      The tuple constructor takes the tuple elements as arguments. For an n-element tuple, the constructor can be invoked with k arguments, where 0 <= k <= n. -For example: +For example:

      tuple<int, double>() 
       tuple<int, double>(1) 
       tuple<int, double>(1, 3.14)
      @@ -106,7 +109,7 @@ tuple<int, double>(1, 3.14)
       
       

      If no initial value for an element is provided, it is default initialized (and hence must be default initializable). -For example. +For example.

      class X {
         X(); 
      @@ -118,7 +121,7 @@ tuple<X,X,X>()                                              // error: no d
       tuple<X,X,X>(string("Jaba"), string("Daba"), string("Duu")) // ok
       
      -In particular, reference types do not have a default initialization: +

      In particular, reference types do not have a default initialization:

      tuple<double&>()                // error: reference must be 
                                       // initialized explicitly
      @@ -134,7 +137,7 @@ tuple<const double&>(d+3.14)    // ok, but dangerous:
       

      Using an initial value for an element that cannot be copied, is a compile -time error: +time error:

      class Y { 
         Y(const Y&); 
      @@ -148,15 +151,15 @@ tuple<char[10], Y>(a, Y()); // error, neither arrays nor Y can be copied
       tuple<char[10], Y>();       // ok
       
      -Note particularly that the following is perfectly ok: -
      Y y;
      +

      Note particularly that the following is perfectly ok:

      +
      Y y;
       tuple<char(&)[10], Y&>(a, y); 
       
      -It is possible to come up with a tuple type that cannot be constructed. +

      It is possible to come up with a tuple type that cannot be constructed. This occurs if an element that cannot be initialized has a lower index than an element that requires initialization. -For example: tuple<char[10], int&>. +For example: tuple<char[10], int&>.

      In sum, the tuple construction is semantically just a group of individual elementary constructions.

      @@ -165,19 +168,19 @@ For example: tuple<char[10], int&>.

      Tuples can also be constructed using the make_tuple (cf. std::make_pair) helper functions. -This makes the construction more convenient, saving the programmer from explicitly specifying the element types: +This makes the construction more convenient, saving the programmer from explicitly specifying the element types:

      tuple<int, int, double> add_multiply_divide(int a, int b) {
         return make_tuple(a+b, a*b, double(a)/double(b));
       }
       

      -By default, the element types are deduced to the plain non-reference types. E.g: +By default, the element types are deduced to the plain non-reference types. E.g.:

      void foo(const A& a, B& b) { 
         ...
         make_tuple(a, b);
       
      -The make_tuple invocation results in a tuple of type tuple<A, B>. +

      The make_tuple invocation results in a tuple of type tuple<A, B>.

      Sometimes the plain non-reference type is not desired, e.g. if the element type cannot be copied. @@ -185,8 +188,9 @@ Therefore, the programmer can control the type deduction and state that a refere non-const type should be used as the element type instead. This is accomplished with two helper template functions: ref and cref. Any argument can be wrapped with these functions to get the desired type. -The mechanism does not compromise const correctness since a const object wrapped with ref results in a tuple element with const reference type (see the fifth code line below). -For example: +The mechanism does not compromise const correctness since a const object wrapped with ref results +in a tuple element with const reference type (see the fifth example below). +For example:

      A a; B b; const A ca = a;
       make_tuple(cref(a), b);      // creates tuple<const A&, B>
      @@ -198,19 +202,19 @@ make_tuple(ref(ca));         // creates tuple<const A&>
       
       
       

      -Array arguments to make_tuple functions are deduced to reference to const types by default; there is no need to wrap them with cref. For example: +Array arguments to make_tuple functions are deduced to reference to const types by default; there is no need to wrap them with cref. For example:

      make_tuple("Donald", "Daisy");
       
      -This creates an object of type tuple<const char (&)[7], const char (&)[6]> +

      This creates an object of type tuple<const char (&)[7], const char (&)[6]> (note that the type of a string literal is an array of const characters, not const char*). However, to get make_tuple to create a tuple with an element of a -non-const array type one must use the ref wrapper. +non-const array type one must use the ref wrapper.

      Function pointers are deduced to the plain non-reference type, that is, to plain function pointer. A tuple can also hold a reference to a function, -but such a tuple cannot be constructed with make_tuple (a const qualified function type would result, which is illegal): +but such a tuple cannot be constructed with make_tuple (a const qualified function type would result, which is illegal):

      void f(int i);
         ...
       make_tuple(&f); // tuple<void (*)(int)>
      @@ -222,19 +226,19 @@ make_tuple(f);                    // not ok
       

      Accessing tuple elements

      -Tuple elements are accessed with the expression: +Tuple elements are accessed with the expression:

      t.get<N>()
       
      -or +

      or

      get<N>(t)
       
      -where t is a tuple object and N is a constant integral expression specifying the index of the element to be accessed. +

      where t is a tuple object and N is a constant integral expression specifying the index of the element to be accessed. Depending on whether t is const or not, get returns the Nth element as a reference to const or non-const type. The index of the first element is 0 and thus N must be between 0 and k-1, where k is the number of elements in the tuple. -Violations of these constrains are detected at compile time. Examples: +Violations of these constraints are detected at compile time. Examples:

      double d = 2.7; A a;
       tuple<int, double&, const A&> t(1, d, a);
      @@ -253,16 +257,18 @@ A aa = get<3>(t);     // error: index out of bounds
       ++get<0>(t);  // ok, can be used as any variable
       
      +

      Note! The member get functions are not supported with MS Visual C++ compiler. Further, the compiler has trouble with finding the non-member get functions without an explicit namespace qualifier. -Hence, all get calls should be qualified as: tuples::get<N>(a_tuple) when writing code that shoud compile with MSVC++ 6.0. +Hence, all get calls should be qualified as: tuples::get<N>(a_tuple) when writing code that should compile with MSVC++ 6.0. +

      Copy construction and tuple assignment

      A tuple can be copy constructed from another tuple, provided that the element types are element-wise copy constructible. Analogously, a tuple can be assigned to another tuple, provided that the element types are element-wise assignable. -For example: +For example:

      class A {};
       class B : public A {};
      @@ -274,32 +280,32 @@ tuple<int, A*, C, C> a(t); // ok
       a = t;                     // ok 
       
      -In both cases, the conversions performed are: char -> int, B* -> A* (derived class pointer to base class pointer), B -> C (a user defined conversion) and D -> C (a user defined conversion). +

      In both cases, the conversions performed are: char -> int, B* -> A* (derived class pointer to base class pointer), B -> C (a user defined conversion) and D -> C (a user defined conversion).

      -Note that assignment is also defined from std::pair types: +Note that assignment is also defined from std::pair types:

      tuple<float, int> a = std::make_pair(1, 'a');
       

      Relational operators

      -Tuples reduce the operators ==, !=, <, >, <= and >= to the corresponding elementary operators. +Tuples reduce the operators ==, !=, <, >, <= and >= to the corresponding elementary operators. This means, that if any of these operators is defined between all elements of two tuples, then the same operator is defined between the tuples as well. -The equality operators for two tuples a and b are defined as: +The equality operators for two tuples a and b are defined as:

      • a == b iff for each i: ai == bi
      • a != b iff exists i: ai != bi
      -The operators <, >, <= and >= implement a lexicographical ordering. +

      The operators <, >, <= and >= implement a lexicographical ordering.

      -Note that an attempt to compare two tuples of different lengths results in a compile time error.

      -Also, the comparison operators are "short-circuited": elementary comparisons start from the first elements and are performed only until the result is clear. +Note that an attempt to compare two tuples of different lengths results in a compile time error. +Also, the comparison operators are "short-circuited": elementary comparisons start from the first elements and are performed only until the result is clear.

      -

      Examples: +

      Examples:

      tuple<std::string, int, A> t1(std::string("same?"), 2, A());
       tuple<std::string, long, A> t2(std::string("same?"), 2, A());
      @@ -316,7 +322,7 @@ t1 == t3;               // false, does not print "All the..."
       
       

      Tiers are tuples, where all elements are of non-const reference types. -They are constructed with a call to the tie function template (cf. make_tuple): +They are constructed with a call to the tie function template (cf. make_tuple):

      int i; char c; double d; 
         ...
      @@ -329,26 +335,26 @@ The same result could be achieved with the call make_tuple(ref(i), ref(c),
       

      -A tuple that contains non-const references as elements can be used to 'unpack' another tuple into variables. E.g.: +A tuple that contains non-const references as elements can be used to 'unpack' another tuple into variables. E.g.:

      int i; char c; double d; 
       tie(i, c, d) = make_tuple(1,'a', 5.5);
       std::cout << i << " " <<  c << " " << d;
       
      -This code prints 1 a 5.5 to the standard output stream. +

      This code prints 1 a 5.5 to the standard output stream. A tuple unpacking operation like this is found for example in ML and Python. -It is convenient when calling functions which return tuples. +It is convenient when calling functions which return tuples.

      -The tying mechanism works with std::pair templates as well: +The tying mechanism works with std::pair templates as well:

      int i; char c;
       tie(i, c) = std::make_pair(1, 'a');
       

      Ignore

      -There is also an object called ignore which allows you to ignore an element assigned by a tuple. -The idea is that a function may return a tuple, only part of which you are interested in. For example (note, that ignore is under the tuples subnamespace): +

      There is also an object called ignore which allows you to ignore an element assigned by a tuple. +The idea is that a function may return a tuple, only part of which you are interested in. For example (note, that ignore is under the tuples subnamespace):

      char c;
       tie(tuples::ignore, c) = std::make_pair(1, 'a');
      @@ -374,10 +380,10 @@ For Example:
       
       cout << a; 
       
      -outputs the tuple as: (1.0 2 Howdy folks!) +

      outputs the tuple as: (1.0 2 Howdy folks!)

      -The library defines three manipulators for changing the default behavior: +The library defines three manipulators for changing the default behavior:

      • set_open(char) defines the character that is output before the first element.
      • @@ -387,27 +393,27 @@ last element. elements.
      -Note, that these manipulators are defined in the tuples subnamespace. -For example: -
      cout << tuples::set_open('[') << tuples::set_close(']') << tuples::set_delimiter(',') << a; 
      +

      Note, that these manipulators are defined in the tuples subnamespace. +For example:

      +
      cout << tuples::set_open('[') << tuples::set_close(']') << tuples::set_delimiter(',') << a; 
       
      -outputs the same tuple a as: [1.0,2,Howdy folks!] +

      outputs the same tuple a as: [1.0,2,Howdy folks!]

      The same manipulators work with operator>> and istream as well. Suppose the cin stream contains the following data:

      (1 2 3) [4:5]
      -The code: +

      The code:

      -
      tuple<int, int, int> i;
      +
      tuple<int, int, int> i;
       tuple<int, int> j;
       
       cin >> i;
      -cin >> tuples::set_open('[') >> tuples::set_close(']') >> tules::set_delimiter(':');
      +cin >> tuples::set_open('[') >> tuples::set_close(']') >> tuples::set_delimiter(':');
       cin >> j;
       
      -reads the data into the tuples i and j. +

      reads the data into the tuples i and j.

      Note that extracting tuples with std::string or C-style string @@ -417,9 +423,9 @@ parseable.

      Performance

      -All tuple access and construction functions are small inlined one-liners. -Therefore, a decent compiler can eliminate any extra cost of using tuples compared to using hand written tuple like classes. -Particularly, with a decent compiler there is no performance difference between this code: +

      All tuple access and construction functions are small inlined one-liners. +Therefore, a decent compiler can eliminate any extra cost of using tuples compared to using hand-written tuple like classes. +Particularly, with a decent compiler there is no performance difference between this code:

      class hand_made_tuple { 
         A a; B b; C c;
      @@ -435,7 +441,7 @@ hand_made_tuple hmt(A(), B(), C());
       hmt.getA(); hmt.getB(); hmt.getC();
       
      -and this code: +

      and this code:

      tuple<A, B, C> t(A(), B(), C());
       t.get<0>(); t.get<1>(); t.get<2>(); 
      @@ -446,23 +452,23 @@ t.get<0>(); t.get<1>(); t.get<2>();
       

      Depending on the optimizing ability of the compiler, the tier mechanism may have a small performance penalty compared to using non-const reference parameters as a mechanism for returning multiple values from a function. -For example, suppose that the following functions f1 and f2 have equivalent functionalities: +For example, suppose that the following functions f1 and f2 have equivalent functionalities:

      void f1(int&, double&);
       tuple<int, double> f2();
       
      -Then, the call #1 may be slightly faster than #2 in the code below: +

      Then, the call #1 may be slightly faster than #2 in the code below:

      int i; double d;
         ...
       f1(i,d);         // #1
       tie(i,d) = f2(); // #2
       
      -See +

      See [1, 2] - for more in-depth discussions about efficiency. + for more in-depth discussions about efficiency.

      Effect on Compile Time

      @@ -470,7 +476,7 @@ See Compiling tuples can be slow due to the excessive amount of template instantiations. Depending on the compiler and the tuple length, it may be more than 10 times slower to compile a tuple construct, compared to compiling an equivalent explicitly written class, such as the hand_made_tuple class above. However, as a realistic program is likely to contain a lot of code in addition to tuple definitions, the difference is probably unnoticeable. -Compile time increases between 5 to 10 percentages were measured for programs which used tuples very frequently. +Compile time increases between 5 and 10 percent were measured for programs which used tuples very frequently. With the same test programs, memory consumption of compiling increased between 22% to 27%. See [1, 2] @@ -492,10 +498,10 @@ Below is a list of compilers and known problems with each compiler:

      Acknowledgements

      -Gary Powell has been an indispensable helping hand. In particular, stream manipulators for tuples were his idea. Doug Gregor came up with a working version for MSVC, David Abrahams found a way to get rid of most of the restrictions for compilers not supporting partial specialization. Thanks to Jeremy Siek, William Kempf and Jens Maurer for their help and suggestions. +

      Gary Powell has been an indispensable helping hand. In particular, stream manipulators for tuples were his idea. Doug Gregor came up with a working version for MSVC, David Abrahams found a way to get rid of most of the restrictions for compilers not supporting partial specialization. Thanks to Jeremy Siek, William Kempf and Jens Maurer for their help and suggestions. The comments by Vesa Karvonen, John Max Skaller, Ed Brey, Beman Dawes, David Abrahams and Hartmut Kaiser helped to improve the library. -The idea for the tie mechanism came from an old usenet article by Ian McCulloch, where he proposed something similar for std::pairs. +The idea for the tie mechanism came from an old usenet article by Ian McCulloch, where he proposed something similar for std::pairs.

      References

      From a75a686fae3763c21d3d7a97564a03cc5d0a3f91 Mon Sep 17 00:00:00 2001 From: "Troy D. Straszheim" Date: Sun, 26 Jul 2009 00:49:56 +0000 Subject: [PATCH 16/24] Copyrights on CMakeLists.txt to keep them from clogging up the inspect reports. This is essentially the same commit as r55095 on the release branch. [SVN r55159] --- CMakeLists.txt | 6 ++++++ test/CMakeLists.txt | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 26cf773..a0321f4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,3 +1,9 @@ +# +# Copyright Troy D. Straszheim +# +# Distributed under the Boost Software License, Version 1.0. +# See http://www.boost.org/LICENSE_1_0.txt +# #---------------------------------------------------------------------------- # This file was automatically generated from the original CMakeLists.txt file # Add a variable to hold the headers for the library diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index c61971b..0896726 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,3 +1,9 @@ +# +# Copyright Troy D. Straszheim +# +# Distributed under the Boost Software License, Version 1.0. +# See http://www.boost.org/LICENSE_1_0.txt +# boost_additional_test_dependencies(tuple BOOST_DEPENDS test) From d908a5d5668a50d96988bc42a9a37559b7439571 Mon Sep 17 00:00:00 2001 From: "Troy D. Straszheim" Date: Sat, 17 Oct 2009 02:07:38 +0000 Subject: [PATCH 17/24] rm cmake from trunk. I'm not entirely sure this is necessary to satisfy the inspect script, but I'm not taking any chances, and it is easy to put back [SVN r56942] --- CMakeLists.txt | 27 --------------------------- module.cmake | 2 -- test/CMakeLists.txt | 11 ----------- 3 files changed, 40 deletions(-) delete mode 100644 CMakeLists.txt delete mode 100644 module.cmake delete mode 100644 test/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt deleted file mode 100644 index a0321f4..0000000 --- a/CMakeLists.txt +++ /dev/null @@ -1,27 +0,0 @@ -# -# Copyright Troy D. Straszheim -# -# Distributed under the Boost Software License, Version 1.0. -# See http://www.boost.org/LICENSE_1_0.txt -# -#---------------------------------------------------------------------------- -# This file was automatically generated from the original CMakeLists.txt file -# Add a variable to hold the headers for the library -set (lib_headers - tuple -) - -# Add a library target to the build system -boost_library_project( - tuple - # SRCDIRS - TESTDIRS test - HEADERS ${lib_headers} - # DOCDIRS - DESCRIPTION "Ease definition of functions returning multiple values, and more." - MODULARIZED - AUTHORS "Jaakko Jarvi " - # MAINTAINERS -) - - diff --git a/module.cmake b/module.cmake deleted file mode 100644 index 4c52344..0000000 --- a/module.cmake +++ /dev/null @@ -1,2 +0,0 @@ -boost_module(tuple DEPENDS static_assert) - diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt deleted file mode 100644 index 0896726..0000000 --- a/test/CMakeLists.txt +++ /dev/null @@ -1,11 +0,0 @@ -# -# Copyright Troy D. Straszheim -# -# Distributed under the Boost Software License, Version 1.0. -# See http://www.boost.org/LICENSE_1_0.txt -# -boost_additional_test_dependencies(tuple BOOST_DEPENDS test) - - -boost_test_run(tuple_test_bench DEPENDS boost_test_exec_monitor) -boost_test_run(io_test DEPENDS boost_test_exec_monitor) From 052b3db77fef930439fa6421b5cc897d22da6ca0 Mon Sep 17 00:00:00 2001 From: Steven Watanabe Date: Wed, 9 Jun 2010 17:45:24 +0000 Subject: [PATCH 18/24] Make reading a tuple work with std::noskipws. Fixes #1920 [SVN r62678] --- include/boost/tuple/tuple_io.hpp | 4 ++++ test/io_test.cpp | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/include/boost/tuple/tuple_io.hpp b/include/boost/tuple/tuple_io.hpp index 10cdb1c..06a2339 100644 --- a/include/boost/tuple/tuple_io.hpp +++ b/include/boost/tuple/tuple_io.hpp @@ -384,6 +384,8 @@ extract_and_check_delimiter( if (is.good() && c!=d) { is.setstate(std::ios::failbit); } + } else { + is >> std::ws; } return is; } @@ -478,6 +480,8 @@ extract_and_check_delimiter( if (is.good() && c!=d) { is.setstate(std::ios::failbit); } + } else { + is >> std::ws; } return is; } diff --git a/test/io_test.cpp b/test/io_test.cpp index cf6dfb0..95babe3 100644 --- a/test/io_test.cpp +++ b/test/io_test.cpp @@ -120,6 +120,13 @@ int test_main(int argc, char * argv[] ) { is3 >> set_close(']'); BOOST_CHECK(bool(is3 >> ti2)); + // Make sure that whitespace between elements + // is skipped. + useThisIStringStream is4("(100 200 300)"); + + BOOST_CHECK(bool(is4 >> std::noskipws >> ti1)); + BOOST_CHECK(ti1 == make_tuple(100, 200, 300)); + // Note that strings are problematic: // writing a tuple on a stream and reading it back doesn't work in // general. If this is wanted, some kind of a parseable string class From 1b07c1a2d45da32539b65f6aa29aec9e81bca577 Mon Sep 17 00:00:00 2001 From: Steven Watanabe Date: Wed, 9 Jun 2010 18:28:16 +0000 Subject: [PATCH 19/24] Reimplement boost::tuples::element and boost::tuples::get to make better use of memoization. Fixes #2130 [SVN r62683] --- include/boost/tuple/detail/tuple_basic.hpp | 138 ++++++--------------- 1 file changed, 37 insertions(+), 101 deletions(-) diff --git a/include/boost/tuple/detail/tuple_basic.hpp b/include/boost/tuple/detail/tuple_basic.hpp index 348fd80..afdb50f 100644 --- a/include/boost/tuple/detail/tuple_basic.hpp +++ b/include/boost/tuple/detail/tuple_basic.hpp @@ -86,45 +86,28 @@ namespace detail { template class generate_error; -// - cons getters -------------------------------------------------------- -// called: get_class::get(aTuple) - -template< int N > -struct get_class { - template - inline static RET get(const cons& t) - { -#if BOOST_WORKAROUND(__IBMCPP__,==600) - // vacpp 6.0 is not very consistent regarding the member template keyword - // Here it generates an error when the template keyword is used. - return get_class::get(t.tail); -#else - return get_class::BOOST_NESTED_TEMPLATE get(t.tail); -#endif - } - template - inline static RET get(cons& t) - { -#if BOOST_WORKAROUND(__IBMCPP__,==600) - return get_class::get(t.tail); -#else - return get_class::BOOST_NESTED_TEMPLATE get(t.tail); -#endif - } +template +struct drop_front { + template + struct apply { + typedef BOOST_DEDUCED_TYPENAME drop_front::BOOST_NESTED_TEMPLATE + apply next; + typedef BOOST_DEDUCED_TYPENAME next::type::tail_type type; + static const type& call(const Tuple& tup) { + return next::call(tup).tail; + } + }; }; template<> -struct get_class<0> { - template - inline static RET get(const cons& t) - { - return t.head; - } - template - inline static RET get(cons& t) - { - return t.head; - } +struct drop_front<0> { + template + struct apply { + typedef Tuple type; + static const type& call(const Tuple& tup) { + return tup; + } + }; }; } // end of namespace detail @@ -140,41 +123,23 @@ struct get_class<0> { template struct element { -private: - typedef typename T::tail_type Next; -public: - typedef typename element::type type; -}; -template -struct element<0,T> -{ - typedef typename T::head_type type; + typedef BOOST_DEDUCED_TYPENAME detail::drop_front::BOOST_NESTED_TEMPLATE + apply::type::head_type type; }; template struct element { private: - typedef typename T::tail_type Next; - typedef typename element::type unqualified_type; + typedef BOOST_DEDUCED_TYPENAME detail::drop_front::BOOST_NESTED_TEMPLATE + apply::type::head_type unqualified_type; public: #if BOOST_WORKAROUND(__BORLANDC__,<0x600) typedef const unqualified_type type; #else - typedef typename boost::add_const::type type; -#endif - -}; -template -struct element<0,const T> -{ -#if BOOST_WORKAROUND(__BORLANDC__,<0x600) - typedef const typename T::head_type type; -#else - typedef typename boost::add_const::type type; + typedef BOOST_DEDUCED_TYPENAME boost::add_const::type type; #endif }; - #else // def BOOST_NO_CV_SPECIALIZATIONS namespace detail { @@ -182,31 +147,16 @@ namespace detail { template struct element_impl { -private: - typedef typename T::tail_type Next; -public: - typedef typename element_impl::type type; + typedef BOOST_DEDUCED_TYPENAME detail::drop_front::BOOST_NESTED_TEMPLATE + apply::type::head_type type; }; template struct element_impl { -private: - typedef typename T::tail_type Next; -public: - typedef const typename element_impl::type type; -}; - -template -struct element_impl<0, T, false /* IsConst */> -{ - typedef typename T::head_type type; -}; - -template -struct element_impl<0, T, true /* IsConst */> -{ - typedef const typename T::head_type type; + typedef BOOST_DEDUCED_TYPENAME detail::drop_front::BOOST_NESTED_TEMPLATE + apply::type::head_type unqualified_type; + typedef const unqualified_type type; }; } // end of namespace detail @@ -258,17 +208,10 @@ inline typename access_traits< typename element >::type >::non_const_type get(cons& c BOOST_APPEND_EXPLICIT_TEMPLATE_NON_TYPE(int, N)) { -#if BOOST_WORKAROUND(__IBMCPP__,==600 ) - return detail::get_class:: -#else - return detail::get_class::BOOST_NESTED_TEMPLATE -#endif - get< - typename access_traits< - typename element >::type - >::non_const_type, - HT,TT - >(c); + typedef BOOST_DEDUCED_TYPENAME detail::drop_front::BOOST_NESTED_TEMPLATE + apply > impl; + typedef BOOST_DEDUCED_TYPENAME impl::type cons_element; + return const_cast(impl::call(c)).head; } // get function for const cons-lists, returns a const reference to @@ -279,17 +222,10 @@ inline typename access_traits< typename element >::type >::const_type get(const cons& c BOOST_APPEND_EXPLICIT_TEMPLATE_NON_TYPE(int, N)) { -#if BOOST_WORKAROUND(__IBMCPP__,==600) - return detail::get_class:: -#else - return detail::get_class::BOOST_NESTED_TEMPLATE -#endif - get< - typename access_traits< - typename element >::type - >::const_type, - HT,TT - >(c); + typedef BOOST_DEDUCED_TYPENAME detail::drop_front::BOOST_NESTED_TEMPLATE + apply > impl; + typedef BOOST_DEDUCED_TYPENAME impl::type cons_element; + return impl::call(c).head; } // -- the cons template -------------------------------------------------- From 7b6203747a968cfa0c1bac6d1f70b4df518a244c Mon Sep 17 00:00:00 2001 From: Steven Watanabe Date: Wed, 9 Jun 2010 19:00:56 +0000 Subject: [PATCH 20/24] Use an inline function instead of a static object for boost::tuples::ignore, avoiding problems with the ODR and Borland precompiled headers. Fixes #2656 [SVN r62684] --- include/boost/tuple/detail/tuple_basic.hpp | 159 +++++++++++++++------ 1 file changed, 113 insertions(+), 46 deletions(-) diff --git a/include/boost/tuple/detail/tuple_basic.hpp b/include/boost/tuple/detail/tuple_basic.hpp index afdb50f..42c4bb4 100644 --- a/include/boost/tuple/detail/tuple_basic.hpp +++ b/include/boost/tuple/detail/tuple_basic.hpp @@ -599,18 +599,21 @@ public: // Swallows any assignment (by Doug Gregor) namespace detail { +struct swallow_assign; +typedef void (detail::swallow_assign::*ignore_t)(); struct swallow_assign { - + swallow_assign(ignore_t(*)(ignore_t)) {} template swallow_assign const& operator=(const T&) const { return *this; } }; + } // namespace detail // "ignore" allows tuple positions to be ignored when using "tie". -detail::swallow_assign const ignore = detail::swallow_assign(); +inline detail::ignore_t ignore(detail::ignore_t) { return 0; } // --------------------------------------------------------------------------- // The call_traits for make_tuple @@ -692,6 +695,10 @@ struct make_tuple_traits >{ typedef T& type; }; +template<> +struct make_tuple_traits { + typedef detail::swallow_assign type; +}; @@ -813,71 +820,131 @@ make_tuple(const T0& t0, const T1& t1, const T2& t2, const T3& t3, return t(t0, t1, t2, t3, t4, t5, t6, t7, t8, t9); } +namespace detail { +template +struct tie_traits { + typedef T& type; +}; + +template<> +struct tie_traits { + typedef swallow_assign type; +}; + +template<> +struct tie_traits { + typedef null_type type; +}; + +template < + class T0 = void, class T1 = void, class T2 = void, + class T3 = void, class T4 = void, class T5 = void, + class T6 = void, class T7 = void, class T8 = void, + class T9 = void +> +struct tie_mapper { + typedef + tuple::type, + typename tie_traits::type, + typename tie_traits::type, + typename tie_traits::type, + typename tie_traits::type, + typename tie_traits::type, + typename tie_traits::type, + typename tie_traits::type, + typename tie_traits::type, + typename tie_traits::type> type; +}; + +} // Tie function templates ------------------------------------------------- -template -inline tuple tie(T1& t1) { - return tuple (t1); +template +inline typename detail::tie_mapper::type +tie(T0& t0) { + typedef typename detail::tie_mapper::type t; + return t(t0); } -template -inline tuple tie(T1& t1, T2& t2) { - return tuple (t1, t2); +template +inline typename detail::tie_mapper::type +tie(T0& t0, T1& t1) { + typedef typename detail::tie_mapper::type t; + return t(t0, t1); } -template -inline tuple tie(T1& t1, T2& t2, T3& t3) { - return tuple (t1, t2, t3); +template +inline typename detail::tie_mapper::type +tie(T0& t0, T1& t1, T2& t2) { + typedef typename detail::tie_mapper::type t; + return t(t0, t1, t2); } -template -inline tuple tie(T1& t1, T2& t2, T3& t3, T4& t4) { - return tuple (t1, t2, t3, t4); +template +inline typename detail::tie_mapper::type +tie(T0& t0, T1& t1, T2& t2, T3& t3) { + typedef typename detail::tie_mapper::type t; + return t(t0, t1, t2, t3); } -template -inline tuple -tie(T1& t1, T2& t2, T3& t3, T4& t4, T5& t5) { - return tuple (t1, t2, t3, t4, t5); +template +inline typename detail::tie_mapper::type +tie(T0& t0, T1& t1, T2& t2, T3& t3, + T4& t4) { + typedef typename detail::tie_mapper::type t; + return t(t0, t1, t2, t3, t4); } -template -inline tuple -tie(T1& t1, T2& t2, T3& t3, T4& t4, T5& t5, T6& t6) { - return tuple (t1, t2, t3, t4, t5, t6); +template +inline typename detail::tie_mapper::type +tie(T0& t0, T1& t1, T2& t2, T3& t3, + T4& t4, T5& t5) { + typedef typename detail::tie_mapper::type t; + return t(t0, t1, t2, t3, t4, t5); } -template -inline tuple -tie(T1& t1, T2& t2, T3& t3, T4& t4, T5& t5, T6& t6, T7& t7) { - return tuple (t1, t2, t3, t4, t5, t6, t7); +template +inline typename detail::tie_mapper::type +tie(T0& t0, T1& t1, T2& t2, T3& t3, + T4& t4, T5& t5, T6& t6) { + typedef typename detail::tie_mapper + ::type t; + return t(t0, t1, t2, t3, t4, t5, t6); } -template -inline tuple -tie(T1& t1, T2& t2, T3& t3, T4& t4, T5& t5, T6& t6, T7& t7, T8& t8) { - return tuple - (t1, t2, t3, t4, t5, t6, t7, t8); +template +inline typename detail::tie_mapper::type +tie(T0& t0, T1& t1, T2& t2, T3& t3, + T4& t4, T5& t5, T6& t6, T7& t7) { + typedef typename detail::tie_mapper + ::type t; + return t(t0, t1, t2, t3, t4, t5, t6, t7); } -template -inline tuple -tie(T1& t1, T2& t2, T3& t3, T4& t4, T5& t5, T6& t6, T7& t7, T8& t8, - T9& t9) { - return tuple - (t1, t2, t3, t4, t5, t6, t7, t8, t9); +template +inline typename detail::tie_mapper + ::type +tie(T0& t0, T1& t1, T2& t2, T3& t3, + T4& t4, T5& t5, T6& t6, T7& t7, + T8& t8) { + typedef typename detail::tie_mapper + ::type t; + return t(t0, t1, t2, t3, t4, t5, t6, t7, t8); } -template -inline tuple -tie(T1& t1, T2& t2, T3& t3, T4& t4, T5& t5, T6& t6, T7& t7, T8& t8, - T9& t9, T10& t10) { - return tuple - (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10); +template +inline typename detail::tie_mapper + ::type +tie(T0& t0, T1& t1, T2& t2, T3& t3, + T4& t4, T5& t5, T6& t6, T7& t7, + T8& t8, T9& t9) { + typedef typename detail::tie_mapper + ::type t; + return t(t0, t1, t2, t3, t4, t5, t6, t7, t8, t9); } } // end of namespace tuples From 9d64187c342eabbcf85a89520d81a224ceccca97 Mon Sep 17 00:00:00 2001 From: Steven Watanabe Date: Wed, 9 Jun 2010 19:30:35 +0000 Subject: [PATCH 21/24] Add an element-wise swap for Boost.Tuple. Fixes #1324 [SVN r62686] --- include/boost/tuple/detail/tuple_basic.hpp | 24 +++++++++++++++++++ .../detail/tuple_basic_no_partial_spec.hpp | 24 +++++++++++++++++++ test/tuple_test_bench.cpp | 21 ++++++++++++++++ 3 files changed, 69 insertions(+) diff --git a/include/boost/tuple/detail/tuple_basic.hpp b/include/boost/tuple/detail/tuple_basic.hpp index 42c4bb4..88f0d90 100644 --- a/include/boost/tuple/detail/tuple_basic.hpp +++ b/include/boost/tuple/detail/tuple_basic.hpp @@ -37,6 +37,7 @@ #include "boost/type_traits/cv_traits.hpp" #include "boost/type_traits/function_traits.hpp" +#include "boost/utility/swap.hpp" #include "boost/detail/workaround.hpp" // needed for BOOST_WORKAROUND @@ -947,6 +948,29 @@ tie(T0& t0, T1& t1, T2& t2, T3& t3, return t(t0, t1, t2, t3, t4, t5, t6, t7, t8, t9); } +template +void swap(tuple& lhs, + tuple& rhs); +inline void swap(null_type&, null_type&) {} +template +inline void swap(cons& lhs, cons& rhs) { + ::boost::swap(lhs.head, rhs.head); +} +template +inline void swap(cons& lhs, cons& rhs) { + ::boost::swap(lhs.head, rhs.head); + ::boost::tuples::swap(lhs.tail, rhs.tail); +} +template +inline void swap(tuple& lhs, + tuple& rhs) { + typedef tuple tuple_type; + typedef typename tuple_type::inherited base; + ::boost::tuples::swap(static_cast(lhs), static_cast(rhs)); +} + } // end of namespace tuples } // end of namespace boost diff --git a/include/boost/tuple/detail/tuple_basic_no_partial_spec.hpp b/include/boost/tuple/detail/tuple_basic_no_partial_spec.hpp index bb38662..7379bf8 100644 --- a/include/boost/tuple/detail/tuple_basic_no_partial_spec.hpp +++ b/include/boost/tuple/detail/tuple_basic_no_partial_spec.hpp @@ -27,6 +27,7 @@ #define BOOST_TUPLE_BASIC_NO_PARTIAL_SPEC_HPP #include "boost/type_traits.hpp" +#include "boost/utility/swap.hpp" #include #if defined BOOST_MSVC @@ -836,6 +837,29 @@ namespace tuples { detail::swallow_assign const ignore = detail::swallow_assign(); +template +void swap(tuple& lhs, + tuple& rhs); +inline void swap(null_type&, null_type&) {} +template +inline void swap(cons& lhs, cons& rhs) { + ::boost::swap(lhs.head, rhs.head); +} +template +inline void swap(cons& lhs, cons& rhs) { + ::boost::swap(lhs.head, rhs.head); + ::boost::tuples::swap(lhs.tail, rhs.tail); +} +template +inline void swap(tuple& lhs, + tuple& rhs) { + typedef tuple tuple_type; + typedef typename tuple_type::inherited base; + ::boost::tuples::swap(static_cast(lhs), static_cast(rhs)); +} + } // namespace tuples } // namespace boost #endif // BOOST_TUPLE_BASIC_NO_PARTIAL_SPEC_HPP diff --git a/test/tuple_test_bench.cpp b/test/tuple_test_bench.cpp index eec9e1c..8bf756f 100644 --- a/test/tuple_test_bench.cpp +++ b/test/tuple_test_bench.cpp @@ -445,6 +445,26 @@ void tuple_length_test() } +// ---------------------------------------------------------------------------- +// - testing swap ----------------------------------------------------------- +// ---------------------------------------------------------------------------- +void tuple_swap_test() +{ + tuple t1(1, 2.0f, 3.0), t2(4, 5.0f, 6.0); + swap(t1, t2); + BOOST_CHECK(get<0>(t1) == 4); + BOOST_CHECK(get<1>(t1) == 5.0f); + BOOST_CHECK(get<2>(t1) == 6.0); + BOOST_CHECK(get<0>(t2) == 1); + BOOST_CHECK(get<1>(t2) == 2.0f); + BOOST_CHECK(get<2>(t2) == 3.0); + + int i = 1,j = 2; + boost::tuple t3(i), t4(j); + swap(t3, t4); + BOOST_CHECK(i == 2); + BOOST_CHECK(j == 1); +} @@ -465,6 +485,7 @@ int test_main(int, char *[]) { cons_test(); const_tuple_test(); tuple_length_test(); + tuple_swap_test(); return 0; } From 9fbc9b4cc67373949cd3b135788df4b7a25bc7ec Mon Sep 17 00:00:00 2001 From: Steven Watanabe Date: Fri, 7 Jan 2011 15:22:13 +0000 Subject: [PATCH 22/24] Handle width correctly. Fixes #5046. [SVN r67751] --- include/boost/tuple/tuple_io.hpp | 39 ++++++++++++++++++++++++++++++++ test/io_test.cpp | 6 +++++ 2 files changed, 45 insertions(+) diff --git a/include/boost/tuple/tuple_io.hpp b/include/boost/tuple/tuple_io.hpp index 06a2339..c549716 100644 --- a/include/boost/tuple/tuple_io.hpp +++ b/include/boost/tuple/tuple_io.hpp @@ -29,6 +29,8 @@ #include #endif +#include + #include "boost/tuple/tuple.hpp" // This is ugly: one should be using twoargument isspace since whitspace can @@ -244,6 +246,22 @@ print(std::ostream& o, const cons& t) { } +template +inline bool handle_width(std::ostream& o, const T& t) { + std::streamsize width = o.width(); + if(width == 0) return false; + + std::ostringstream ss; + + ss.copyfmt(o); + ss.tie(0); + ss.width(0); + + ss << t; + o << ss.str(); + + return true; +} #else @@ -280,6 +298,23 @@ print(std::basic_ostream& o, const cons& t) { return print(o, t.tail); } +template +inline bool handle_width(std::basic_ostream& o, const T& t) { + std::streamsize width = o.width(); + if(width == 0) return false; + + std::basic_ostringstream ss; + + ss.copyfmt(o); + ss.tie(0); + ss.width(0); + + ss << t; + o << ss.str(); + + return true; +} + #endif // BOOST_NO_TEMPLATED_STREAMS } // namespace detail @@ -288,6 +323,7 @@ print(std::basic_ostream& o, const cons& t) { inline std::ostream& operator<<(std::ostream& o, const null_type& t) { if (!o.good() ) return o; + if (detail::handle_width(o, t)) return o; const char l = detail::format_info::get_manipulator(o, detail::format_info::open); @@ -303,6 +339,7 @@ inline std::ostream& operator<<(std::ostream& o, const null_type& t) { template inline std::ostream& operator<<(std::ostream& o, const cons& t) { if (!o.good() ) return o; + if (detail::handle_width(o, t)) return o; const char l = detail::format_info::get_manipulator(o, detail::format_info::open); @@ -325,6 +362,7 @@ inline std::basic_ostream& operator<<(std::basic_ostream& o, const null_type& t) { if (!o.good() ) return o; + if (detail::handle_width(o, t)) return o; const CharType l = detail::format_info::get_manipulator(o, detail::format_info::open); @@ -342,6 +380,7 @@ inline std::basic_ostream& operator<<(std::basic_ostream& o, const cons& t) { if (!o.good() ) return o; + if (detail::handle_width(o, t)) return o; const CharType l = detail::format_info::get_manipulator(o, detail::format_info::open); diff --git a/test/io_test.cpp b/test/io_test.cpp index 95babe3..382f8cc 100644 --- a/test/io_test.cpp +++ b/test/io_test.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #if defined BOOST_NO_STRINGSTREAM #include @@ -77,6 +78,11 @@ int test_main(int argc, char * argv[] ) { os3 << set_close(']'); os3 << make_tuple(); BOOST_CHECK (os3.str() == std::string("()[]") ); + + // check width + useThisOStringStream os4; + os4 << std::setw(10) << make_tuple(1, 2, 3); + BOOST_CHECK (os4.str() == std::string(" (1 2 3)") ); std::ofstream tmp("temp.tmp"); From 2b30eb22252a7aa3cfdfa0e09bfd2d93e4b2de07 Mon Sep 17 00:00:00 2001 From: Bryce Adelstein-Lelbach Date: Fri, 14 Jan 2011 02:35:58 +0000 Subject: [PATCH 23/24] Replacing the use of with across Boost. On Linux, GNU's libstdc++, which is the default stdlib for icc and clang, cannot parse the header in version 4.5+ (which thankfully neither compiler advises the use of yet), as it's original C++98-friendly implementation has been replaced with a gnu++0x implementation. is a portable implementation of , providing boost::detail::setfill, boost::detail::setbase, boost::detail::setw, boost::detail::setprecision, boost::detail::setiosflags and boost::detail::resetiosflags. [SVN r68140] --- test/io_test.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/io_test.cpp b/test/io_test.cpp index 382f8cc..69957d3 100644 --- a/test/io_test.cpp +++ b/test/io_test.cpp @@ -20,7 +20,7 @@ #include #include #include -#include +#include #if defined BOOST_NO_STRINGSTREAM #include @@ -81,7 +81,7 @@ int test_main(int argc, char * argv[] ) { // check width useThisOStringStream os4; - os4 << std::setw(10) << make_tuple(1, 2, 3); + os4 << boost::detail::setw(10) << make_tuple(1, 2, 3); BOOST_CHECK (os4.str() == std::string(" (1 2 3)") ); std::ofstream tmp("temp.tmp"); From f904cd5d6994fe480183dddb9e9ef380afbc979d Mon Sep 17 00:00:00 2001 From: Steven Watanabe Date: Sat, 15 Jan 2011 08:11:51 +0000 Subject: [PATCH 24/24] Revert [67111] (addition of boost/detail/iomanip.hpp) and all the commits that depend on it. ([68137], [68140], [68141], [68154], and [68165]). [SVN r68168] --- test/io_test.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/io_test.cpp b/test/io_test.cpp index 69957d3..382f8cc 100644 --- a/test/io_test.cpp +++ b/test/io_test.cpp @@ -20,7 +20,7 @@ #include #include #include -#include +#include #if defined BOOST_NO_STRINGSTREAM #include @@ -81,7 +81,7 @@ int test_main(int argc, char * argv[] ) { // check width useThisOStringStream os4; - os4 << boost::detail::setw(10) << make_tuple(1, 2, 3); + os4 << std::setw(10) << make_tuple(1, 2, 3); BOOST_CHECK (os4.str() == std::string(" (1 2 3)") ); std::ofstream tmp("temp.tmp");