|
Boost-Commit : |
From: joseph.gauterin_at_[hidden]
Date: 2008-07-05 07:16:40
Author: joseph.gauterin
Date: 2008-07-05 07:16:38 EDT (Sat, 05 Jul 2008)
New Revision: 47093
URL: http://svn.boost.org/trac/boost/changeset/47093
Log:
Moved utility\swap to the trunk, as discussed in trac issue #2056.
Added:
trunk/boost/swap.hpp (contents, props changed)
trunk/boost/utility/swap.hpp (contents, props changed)
trunk/libs/utility/swap/
trunk/libs/utility/swap.html (contents, props changed)
trunk/libs/utility/swap/test/
trunk/libs/utility/swap/test/Jamfile.v2 (contents, props changed)
trunk/libs/utility/swap/test/lib_header_1.cpp (contents, props changed)
trunk/libs/utility/swap/test/lib_header_2.cpp (contents, props changed)
trunk/libs/utility/swap/test/mixed_headers_1.cpp (contents, props changed)
trunk/libs/utility/swap/test/mixed_headers_2.cpp (contents, props changed)
trunk/libs/utility/swap/test/primitive.cpp (contents, props changed)
trunk/libs/utility/swap/test/root_header_1.cpp (contents, props changed)
trunk/libs/utility/swap/test/root_header_2.cpp (contents, props changed)
trunk/libs/utility/swap/test/specialized_in_boost.cpp (contents, props changed)
trunk/libs/utility/swap/test/specialized_in_global.cpp (contents, props changed)
trunk/libs/utility/swap/test/specialized_in_other.cpp (contents, props changed)
trunk/libs/utility/swap/test/specialized_in_std.cpp (contents, props changed)
trunk/libs/utility/swap/test/swap_arrays.cpp (contents, props changed)
trunk/libs/utility/swap/test/swap_test_class.hpp (contents, props changed)
Text files modified:
trunk/libs/libraries.htm | 4 ++++
trunk/libs/maintainers.txt | 2 ++
trunk/libs/utility/index.html | 1 +
trunk/status/Jamfile.v2 | 1 +
4 files changed, 8 insertions(+), 0 deletions(-)
Added: trunk/boost/swap.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/swap.hpp 2008-07-05 07:16:38 EDT (Sat, 05 Jul 2008)
@@ -0,0 +1,12 @@
+// Copyright (C) 2007 Joseph Gauterin
+//
+// Distributed under the Boost Software License, Version 1.0. (See
+// accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef BOOST_SWAP_HPP
+#define BOOST_SWAP_HPP
+
+#include "./utility/swap.hpp"
+
+#endif
Added: trunk/boost/utility/swap.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/utility/swap.hpp 2008-07-05 07:16:38 EDT (Sat, 05 Jul 2008)
@@ -0,0 +1,51 @@
+// Copyright (C) 2007, 2008 Steven Watanabe, Joseph Gauterin
+//
+// Distributed under the Boost Software License, Version 1.0. (See
+// accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+// For more information, see http://www.boost.org
+//
+// Update:
+// 29 June 2008 (Added support for built-in arrays.) Niels Dekker
+
+
+#ifndef BOOST_UTILITY_SWAP_HPP
+#define BOOST_UTILITY_SWAP_HPP
+
+#include <algorithm> //for std::swap
+#include <cstddef> //for std::size_t
+
+namespace boost_swap_impl
+{
+ template<class T>
+ void swap_impl(T& left, T& right)
+ {
+ using std::swap;//use std::swap if argument dependent lookup fails
+ swap(left,right);
+ }
+
+ template<class T, std::size_t N>
+ void swap_impl(T (& left)[N], T (& right)[N])
+ {
+ for (std::size_t i = 0; i < N; ++i)
+ {
+ ::boost_swap_impl::swap_impl(left[i], right[i]);
+ }
+ }
+}
+
+namespace boost
+{
+ namespace swap_adl_barrier
+ {
+ template<class T>
+ void swap(T& left, T& right)
+ {
+ ::boost_swap_impl::swap_impl(left, right);
+ }
+ }
+
+ using swap_adl_barrier::swap;
+}
+
+#endif
Modified: trunk/libs/libraries.htm
==============================================================================
--- trunk/libs/libraries.htm (original)
+++ trunk/libs/libraries.htm 2008-07-05 07:16:38 EDT (Sat, 05 Jul 2008)
@@ -251,6 +251,8 @@
Guzman, Hartmut Kaiser, Dan Nuffer and team.</li>
<li>string_algo -
String algorithms library, from Pavol Droba.</li>
+ <li>swap -
+ Enhanced generic swap function, from Joseph Gauterin.</li>
<li>system - Operating system support,
including the diagnostics support that will be part of the C++0x standard
library, from Beman Dawes.</li>
@@ -664,6 +666,8 @@
<li>statechart - Arbitrarily
complex finite state machines can be implemented in easily readable and
maintainable C++ code, from Andreas Huber.</li>
+ <li>swap -
+ Enhanced generic swap function, from Joseph Gauterin.</li>
<li>system - Operating
system support, including the diagnostics support that will be part of the
C++0x standard library, from Beman Dawes.</li>
Modified: trunk/libs/maintainers.txt
==============================================================================
--- trunk/libs/maintainers.txt (original)
+++ trunk/libs/maintainers.txt 2008-07-05 07:16:38 EDT (Sat, 05 Jul 2008)
@@ -82,7 +82,9 @@
unordered Daniel James <daniel_james -at- fmail.co.uk>
utility
utility/enable_if Jaakko Jarvi <jarvi -at- cs.tamu.edu>, Jeremiah Willcock <jewillco -at- osl.iu.edu>
+utility/swap Joseph Gauterin <joseph.gauterin -at- googlemail.com>
variant Eric Friedman <ericbrandon -at- gmail.com>
wave Hartmut Kaiser <hartmut.kaiser -at- gmail.com>
xpressive Eric Niebler <eric -at- boost-consulting.com>
+
Modified: trunk/libs/utility/index.html
==============================================================================
--- trunk/libs/utility/index.html (original)
+++ trunk/libs/utility/index.html 2008-07-05 07:16:38 EDT (Sat, 05 Jul 2008)
@@ -24,6 +24,7 @@
<a href="iterator_adaptors.htm">iterator_adaptors</a><br>
<a href="generator_iterator.htm">generator iterator adaptors</a><br>
<a href="operators.htm">operators</a><br>
+ swap<br>
<a href="throw_exception.html">throw_exception</a><br>
<a href="utility.htm">utility</a><br>
<a href="value_init.htm">value_init</a></p>
Added: trunk/libs/utility/swap.html
==============================================================================
--- (empty file)
+++ trunk/libs/utility/swap.html 2008-07-05 07:16:38 EDT (Sat, 05 Jul 2008)
@@ -0,0 +1,94 @@
+?<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+ <title>Boost: Swap Documentation</title>
+ </head>
+ <body>
+ <!-- Page header -->
+ <img src="../../boost.png" alt="C++ Boost" align="middle" width="277" height="86"/>
+ <h1>Swap</h1>
+
+ <p>
+ <tt>template<class T> void swap(T& <em>left</em>, T& <em>right</em>);</tt>
+ </p>
+
+ <!-- Intoduction -->
+ <p>
+ The template function <tt>boost::swap</tt> allows the values of two variables to be swapped, using argument dependent lookup to select a specialized swap function if available. If no specialized swap function is available, <tt>std::swap</tt> is used.
+ </p>
+
+ <!-- Rationale -->
+ <h2>Rationale</h2>
+ <p>
+ The generic <tt>std::swap</tt> function requires that the elements to be swapped are assignable and copy constructible. It is usually implemented using one copy construction and two assignments - this is often both unnecessarily restrictive and unnecessarily slow. In addition, where the generic swap implementation provides only the basic guarantee, specialized swap functions are often able to provide the no-throw exception guarantee (and it is considered best practice to do so where possible<sup>1</sup>).</p>
+ <p>
+ The alternative to using argument dependent lookup in this situation is to provide a template specialization of std::swap for every type that requires a specialized swap. Although this is legal C++, no Boost libraries use this method, whereas many Boost libraries provide specialized swap functions in their own namespaces.
+ </p>
+ <p>
+ <tt>boost::swap</tt> also supports swapping built-in arrays. Note that <tt>std::swap</tt> doesn't yet do so, but a request to add an overload of <tt>std::swap</tt> for built-in arrays has been well-received by the Library Working Group of the C++ Standards Committee<sup>2</sup>.
+ </p>
+
+ <!-- Exception Safety -->
+ <h2>Exception Safety</h2>
+ <p>
+ <tt>boost::swap</tt> provides the same exception guarantee as the underlying swap function used, with one exception; for an array of type <tt>T[n]</tt>, where <tt>n > 1</tt> and the underlying swap function for <tt>T</tt> provides the strong exception guarantee, <tt>boost::swap</tt> provides only the basic exception guarantee.
+ </p>
+
+ <!-- Requirements -->
+ <h2>Requirements</h2>
+ <p>Either:</p>
+ <ul>
+ <li>T must be assignable</li>
+ <li>T must be copy constructible</li>
+ </ul>
+ <p>Or:</p>
+ <ul>
+ <li>A function with the signature <tt>swap(T&,T&)</tt> is available via argument dependent lookup</li>
+ </ul>
+ <p>Or:</p>
+ <ul>
+ <li>A template specialization of std::swap exists for T</li>
+ </ul>
+ <p>Or:</p>
+ <ul>
+ <li>T is a built-in array of swappable elements</li>
+ </ul>
+
+
+ <!-- Portability -->
+ <h2>Portability</h2>
+ <p>
+ Several older compilers do not support argument dependent lookup on these compilers <tt>boost::swap</tt> will call <tt>std::swap</tt>, ignoring any specialized swap functions that could be found as a result of argument dependent lookup.
+ </p>
+
+ <!-- Credits -->
+ <h2>Credits</h2>
+ <ul>
+ <li>
+ <em>Niels Dekker</em> - for implementing and documenting support for built-in arrays
+ </li>
+ <li>
+ <em><a href="mailto:Joseph.Gauterin_at_[hidden]">Joseph Gauterin</a></em> - for the initial idea, implementation, tests, and documentation
+ </li>
+ <li>
+ <em>Steven Wanatabe</em> - for the idea to use a barrier namespace, enabling the function to have the name '<tt>swap</tt>' without introducing ambiguity or infinite recursion
+ </li>
+ </ul>
+
+ <!-- References -->
+ <hr/>
+ <p><sup><a id="ref1"/>[1]</sup>Scott Meyers, Effective C++ Third Edition, Item 25: "Consider support for a non-throwing swap"</p>
+ <p><sup><a id="ref2"/>[2]</sup>LWG issue 809 (std::swap should be overloaded for array types)</p>
+
+ <!-- Copyright info -->
+ <hr/>
+ <p>Revised: 3 July 2008</p>
+ <p>
+ Copyright 2007, 2008 Joseph Gauterin. Use, modification, and distribution are subject to the Boost Software License, Version 1.0.
+ (See accompanying file LICENSE_1_0.txt or a copy at <http://www.boost.org/LICENSE_1_0.txt>.)
+ </p>
+
+ </body>
+</html>
Added: trunk/libs/utility/swap/test/Jamfile.v2
==============================================================================
--- (empty file)
+++ trunk/libs/utility/swap/test/Jamfile.v2 2008-07-05 07:16:38 EDT (Sat, 05 Jul 2008)
@@ -0,0 +1,53 @@
+# Copyright (c) 2007, 2008 Joseph Gauterin
+#
+# Distributed under the Boost Software License, Version 1.0.
+# (See accompanying file LICENSE_1_0.txt or copy at
+# http://www.boost.org/LICENSE_1_0.txt)
+
+# bring in rules for testing
+import testing ;
+
+test-suite utility/swap
+ :
+ [ compile root_header_1.cpp ]
+ [ compile root_header_2.cpp ]
+ [ compile lib_header_1.cpp ]
+ [ compile lib_header_2.cpp ]
+ [ compile mixed_headers_1.cpp ]
+ [ compile mixed_headers_2.cpp ]
+ [ run primitive.cpp ../../../test/build//boost_test_exec_monitor/<link>static ]
+ [ run specialized_in_boost.cpp ../../../test/build//boost_test_exec_monitor/<link>static ]
+ [ run specialized_in_global.cpp ../../../test/build//boost_test_exec_monitor/<link>static ]
+ [ run specialized_in_other.cpp ../../../test/build//boost_test_exec_monitor/<link>static ]
+ [ run specialized_in_std.cpp ../../../test/build//boost_test_exec_monitor/<link>static ]
+ [ run swap_arrays.cpp ../../../test/build//boost_test_exec_monitor/<link>static ]
+ ;
+
+
+# Copyright (c) 2007, 2008 Joseph Gauterin
+#
+# Distributed under the Boost Software License, Version 1.0.
+# (See accompanying file LICENSE_1_0.txt or copy at
+# http://www.boost.org/LICENSE_1_0.txt)
+
+# bring in rules for testing
+import testing ;
+
+test-suite utility/swap
+ :
+ [ compile root_header_1.cpp ]
+ [ compile root_header_2.cpp ]
+ [ compile lib_header_1.cpp ]
+ [ compile lib_header_2.cpp ]
+ [ compile mixed_headers_1.cpp ]
+ [ compile mixed_headers_2.cpp ]
+ [ run primitive.cpp ../../../test/build//boost_test_exec_monitor/<link>static ]
+ [ run specialized_in_boost.cpp ../../../test/build//boost_test_exec_monitor/<link>static ]
+ [ run specialized_in_global.cpp ../../../test/build//boost_test_exec_monitor/<link>static ]
+ [ run specialized_in_other.cpp ../../../test/build//boost_test_exec_monitor/<link>static ]
+ [ run specialized_in_std.cpp ../../../test/build//boost_test_exec_monitor/<link>static ]
+ [ run swap_arrays.cpp ../../../test/build//boost_test_exec_monitor/<link>static ]
+ ;
+
+
+
Added: trunk/libs/utility/swap/test/lib_header_1.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/utility/swap/test/lib_header_1.cpp 2008-07-05 07:16:38 EDT (Sat, 05 Jul 2008)
@@ -0,0 +1,18 @@
+// Copyright (c) 2007 Joseph Gauterin
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+// Tests that the swap header compiles as a standalone translation unit
+
+#include <boost/utility/swap.hpp>
+// Copyright (c) 2007 Joseph Gauterin
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+// Tests that the swap header compiles as a standalone translation unit
+
+#include <boost/utility/swap.hpp>
Added: trunk/libs/utility/swap/test/lib_header_2.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/utility/swap/test/lib_header_2.cpp 2008-07-05 07:16:38 EDT (Sat, 05 Jul 2008)
@@ -0,0 +1,20 @@
+// Copyright (c) 2007 Joseph Gauterin
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+// Tests that the swap header include guards work correctly
+
+#include <boost/utility/swap.hpp>
+#include <boost/utility/swap.hpp>
+// Copyright (c) 2007 Joseph Gauterin
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+// Tests that the swap header include guards work correctly
+
+#include <boost/utility/swap.hpp>
+#include <boost/utility/swap.hpp>
Added: trunk/libs/utility/swap/test/mixed_headers_1.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/utility/swap/test/mixed_headers_1.cpp 2008-07-05 07:16:38 EDT (Sat, 05 Jul 2008)
@@ -0,0 +1,20 @@
+// Copyright (c) 2007 Joseph Gauterin
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+// Tests that the swap headers work when both are included
+
+#include <boost/swap.hpp>
+#include <boost/utility/swap.hpp>
+// Copyright (c) 2007 Joseph Gauterin
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+// Tests that the swap headers work when both are included
+
+#include <boost/swap.hpp>
+#include <boost/utility/swap.hpp>
Added: trunk/libs/utility/swap/test/mixed_headers_2.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/utility/swap/test/mixed_headers_2.cpp 2008-07-05 07:16:38 EDT (Sat, 05 Jul 2008)
@@ -0,0 +1,20 @@
+// Copyright (c) 2007 Joseph Gauterin
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+// Tests that the swap headers work when both are included
+
+#include <boost/utility/swap.hpp>
+#include <boost/swap.hpp>
+// Copyright (c) 2007 Joseph Gauterin
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+// Tests that the swap headers work when both are included
+
+#include <boost/utility/swap.hpp>
+#include <boost/swap.hpp>
Added: trunk/libs/utility/swap/test/primitive.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/utility/swap/test/primitive.cpp 2008-07-05 07:16:38 EDT (Sat, 05 Jul 2008)
@@ -0,0 +1,44 @@
+// Copyright (c) 2007 Joseph Gauterin
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#include <boost/utility/swap.hpp>
+#define BOOST_INCLUDE_MAIN
+#include <boost/test/test_tools.hpp>
+
+int test_main(int, char*[])
+{
+ int object1 = 1;
+ int object2 = 2;
+
+ boost::swap(object1,object2);
+
+ BOOST_CHECK_EQUAL(object1,2);
+ BOOST_CHECK_EQUAL(object2,1);
+
+ return 0;
+}
+// Copyright (c) 2007 Joseph Gauterin
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#include <boost/utility/swap.hpp>
+#define BOOST_INCLUDE_MAIN
+#include <boost/test/test_tools.hpp>
+
+int test_main(int, char*[])
+{
+ int object1 = 1;
+ int object2 = 2;
+
+ boost::swap(object1,object2);
+
+ BOOST_CHECK_EQUAL(object1,2);
+ BOOST_CHECK_EQUAL(object2,1);
+
+ return 0;
+}
Added: trunk/libs/utility/swap/test/root_header_1.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/utility/swap/test/root_header_1.cpp 2008-07-05 07:16:38 EDT (Sat, 05 Jul 2008)
@@ -0,0 +1,18 @@
+// Copyright (c) 2007 Joseph Gauterin
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+// Tests that the swap header compiles as a standalone translation unit
+
+#include <boost/swap.hpp>
+// Copyright (c) 2007 Joseph Gauterin
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+// Tests that the swap header compiles as a standalone translation unit
+
+#include <boost/swap.hpp>
Added: trunk/libs/utility/swap/test/root_header_2.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/utility/swap/test/root_header_2.cpp 2008-07-05 07:16:38 EDT (Sat, 05 Jul 2008)
@@ -0,0 +1,20 @@
+// Copyright (c) 2007 Joseph Gauterin
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+// Tests that the swap header include guards work correctly
+
+#include <boost/swap.hpp>
+#include <boost/swap.hpp>
+// Copyright (c) 2007 Joseph Gauterin
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+// Tests that the swap header include guards work correctly
+
+#include <boost/swap.hpp>
+#include <boost/swap.hpp>
Added: trunk/libs/utility/swap/test/specialized_in_boost.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/utility/swap/test/specialized_in_boost.cpp 2008-07-05 07:16:38 EDT (Sat, 05 Jul 2008)
@@ -0,0 +1,72 @@
+// Copyright (c) 2007 Joseph Gauterin
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#include <boost/utility/swap.hpp>
+#define BOOST_INCLUDE_MAIN
+#include <boost/test/test_tools.hpp>
+
+//Put test class in namespace boost
+namespace boost
+{
+ #include "./swap_test_class.hpp"
+}
+
+//Provide swap function in namespace boost
+namespace boost
+{
+ void swap(swap_test_class& left, swap_test_class& right)
+ {
+ left.swap(right);
+ }
+}
+
+int test_main(int, char*[])
+{
+ boost::swap_test_class object1;
+ boost::swap_test_class object2;
+ boost::swap(object1,object2);
+
+ BOOST_CHECK_EQUAL(boost::swap_test_class::swap_count(),1);
+ BOOST_CHECK_EQUAL(boost::swap_test_class::copy_count(),0);
+
+ return 0;
+}
+// Copyright (c) 2007 Joseph Gauterin
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#include <boost/utility/swap.hpp>
+#define BOOST_INCLUDE_MAIN
+#include <boost/test/test_tools.hpp>
+
+//Put test class in namespace boost
+namespace boost
+{
+ #include "./swap_test_class.hpp"
+}
+
+//Provide swap function in namespace boost
+namespace boost
+{
+ void swap(swap_test_class& left, swap_test_class& right)
+ {
+ left.swap(right);
+ }
+}
+
+int test_main(int, char*[])
+{
+ boost::swap_test_class object1;
+ boost::swap_test_class object2;
+ boost::swap(object1,object2);
+
+ BOOST_CHECK_EQUAL(boost::swap_test_class::swap_count(),1);
+ BOOST_CHECK_EQUAL(boost::swap_test_class::copy_count(),0);
+
+ return 0;
+}
Added: trunk/libs/utility/swap/test/specialized_in_global.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/utility/swap/test/specialized_in_global.cpp 2008-07-05 07:16:38 EDT (Sat, 05 Jul 2008)
@@ -0,0 +1,60 @@
+// Copyright (c) 2007 Joseph Gauterin
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#include <boost/utility/swap.hpp>
+#define BOOST_INCLUDE_MAIN
+#include <boost/test/test_tools.hpp>
+
+//Put test class in the global namespace
+#include "./swap_test_class.hpp"
+
+//Provide swap function in gloabl namespace
+void swap(swap_test_class& left, swap_test_class& right)
+{
+ left.swap(right);
+}
+
+int test_main(int, char*[])
+{
+ swap_test_class object1;
+ swap_test_class object2;
+ boost::swap(object1,object2);
+
+ BOOST_CHECK_EQUAL(swap_test_class::swap_count(),1);
+ BOOST_CHECK_EQUAL(swap_test_class::copy_count(),0);
+
+ return 0;
+}
+// Copyright (c) 2007 Joseph Gauterin
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#include <boost/utility/swap.hpp>
+#define BOOST_INCLUDE_MAIN
+#include <boost/test/test_tools.hpp>
+
+//Put test class in the global namespace
+#include "./swap_test_class.hpp"
+
+//Provide swap function in gloabl namespace
+void swap(swap_test_class& left, swap_test_class& right)
+{
+ left.swap(right);
+}
+
+int test_main(int, char*[])
+{
+ swap_test_class object1;
+ swap_test_class object2;
+ boost::swap(object1,object2);
+
+ BOOST_CHECK_EQUAL(swap_test_class::swap_count(),1);
+ BOOST_CHECK_EQUAL(swap_test_class::copy_count(),0);
+
+ return 0;
+}
Added: trunk/libs/utility/swap/test/specialized_in_other.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/utility/swap/test/specialized_in_other.cpp 2008-07-05 07:16:38 EDT (Sat, 05 Jul 2008)
@@ -0,0 +1,72 @@
+// Copyright (c) 2007 Joseph Gauterin
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#include <boost/utility/swap.hpp>
+#define BOOST_INCLUDE_MAIN
+#include <boost/test/test_tools.hpp>
+
+//Put test class in namespace other
+namespace other
+{
+ #include "./swap_test_class.hpp"
+}
+
+//Provide swap function in namespace other
+namespace other
+{
+ void swap(swap_test_class& left, swap_test_class& right)
+ {
+ left.swap(right);
+ }
+}
+
+int test_main(int, char*[])
+{
+ other::swap_test_class object1;
+ other::swap_test_class object2;
+ boost::swap(object1,object2);
+
+ BOOST_CHECK_EQUAL(other::swap_test_class::swap_count(),1);
+ BOOST_CHECK_EQUAL(other::swap_test_class::copy_count(),0);
+
+ return 0;
+}
+// Copyright (c) 2007 Joseph Gauterin
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#include <boost/utility/swap.hpp>
+#define BOOST_INCLUDE_MAIN
+#include <boost/test/test_tools.hpp>
+
+//Put test class in namespace other
+namespace other
+{
+ #include "./swap_test_class.hpp"
+}
+
+//Provide swap function in namespace other
+namespace other
+{
+ void swap(swap_test_class& left, swap_test_class& right)
+ {
+ left.swap(right);
+ }
+}
+
+int test_main(int, char*[])
+{
+ other::swap_test_class object1;
+ other::swap_test_class object2;
+ boost::swap(object1,object2);
+
+ BOOST_CHECK_EQUAL(other::swap_test_class::swap_count(),1);
+ BOOST_CHECK_EQUAL(other::swap_test_class::copy_count(),0);
+
+ return 0;
+}
Added: trunk/libs/utility/swap/test/specialized_in_std.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/utility/swap/test/specialized_in_std.cpp 2008-07-05 07:16:38 EDT (Sat, 05 Jul 2008)
@@ -0,0 +1,70 @@
+// Copyright (c) 2007 Joseph Gauterin
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#include <boost/utility/swap.hpp>
+#define BOOST_INCLUDE_MAIN
+#include <boost/test/test_tools.hpp>
+
+//Put test class in the global namespace
+#include "./swap_test_class.hpp"
+
+
+//Provide swap function in namespace std
+namespace std
+{
+ template <>
+ void swap(swap_test_class& left, swap_test_class& right)
+ {
+ left.swap(right);
+ }
+}
+
+int test_main(int, char*[])
+{
+ swap_test_class object1;
+ swap_test_class object2;
+ boost::swap(object1,object2);
+
+ BOOST_CHECK_EQUAL(swap_test_class::swap_count(),1);
+ BOOST_CHECK_EQUAL(swap_test_class::copy_count(),0);
+
+ return 0;
+}
+// Copyright (c) 2007 Joseph Gauterin
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#include <boost/utility/swap.hpp>
+#define BOOST_INCLUDE_MAIN
+#include <boost/test/test_tools.hpp>
+
+//Put test class in the global namespace
+#include "./swap_test_class.hpp"
+
+
+//Provide swap function in namespace std
+namespace std
+{
+ template <>
+ void swap(swap_test_class& left, swap_test_class& right)
+ {
+ left.swap(right);
+ }
+}
+
+int test_main(int, char*[])
+{
+ swap_test_class object1;
+ swap_test_class object2;
+ boost::swap(object1,object2);
+
+ BOOST_CHECK_EQUAL(swap_test_class::swap_count(),1);
+ BOOST_CHECK_EQUAL(swap_test_class::copy_count(),0);
+
+ return 0;
+}
Added: trunk/libs/utility/swap/test/swap_arrays.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/utility/swap/test/swap_arrays.cpp 2008-07-05 07:16:38 EDT (Sat, 05 Jul 2008)
@@ -0,0 +1,78 @@
+// Copyright (c) 2008 Joseph Gauterin, Niels Dekker
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#include <boost/utility/swap.hpp>
+#define BOOST_INCLUDE_MAIN
+#include <boost/test/test_tools.hpp>
+
+//Put test class in the global namespace
+#include "./swap_test_class.hpp"
+
+
+int test_main(int, char*[])
+{
+ const std::size_t dimension = 7;
+
+ swap_test_class array1[dimension];
+ swap_test_class array2[dimension];
+ boost::swap(array1, array2);
+
+ BOOST_CHECK_EQUAL(swap_test_class::swap_count(), dimension);
+ BOOST_CHECK_EQUAL(swap_test_class::copy_count(), 0);
+
+ swap_test_class::reset();
+
+ const std::size_t firstDimension = 3;
+ const std::size_t secondDimension = 4;
+
+ swap_test_class two_d_array1[firstDimension][secondDimension];
+ swap_test_class two_d_array2[firstDimension][secondDimension];
+ boost::swap(two_d_array1, two_d_array1);
+
+ BOOST_CHECK_EQUAL(swap_test_class::swap_count(), firstDimension*secondDimension);
+ BOOST_CHECK_EQUAL(swap_test_class::copy_count(), 0);
+
+ return 0;
+}
+// Copyright (c) 2008 Joseph Gauterin, Niels Dekker
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#include <boost/utility/swap.hpp>
+#define BOOST_INCLUDE_MAIN
+#include <boost/test/test_tools.hpp>
+
+//Put test class in the global namespace
+#include "./swap_test_class.hpp"
+
+
+int test_main(int, char*[])
+{
+ const std::size_t dimension = 7;
+
+ swap_test_class array1[dimension];
+ swap_test_class array2[dimension];
+ boost::swap(array1, array2);
+
+ BOOST_CHECK_EQUAL(swap_test_class::swap_count(), dimension);
+ BOOST_CHECK_EQUAL(swap_test_class::copy_count(), 0);
+
+ swap_test_class::reset();
+
+ const std::size_t firstDimension = 3;
+ const std::size_t secondDimension = 4;
+
+ swap_test_class two_d_array1[firstDimension][secondDimension];
+ swap_test_class two_d_array2[firstDimension][secondDimension];
+ boost::swap(two_d_array1, two_d_array1);
+
+ BOOST_CHECK_EQUAL(swap_test_class::swap_count(), firstDimension*secondDimension);
+ BOOST_CHECK_EQUAL(swap_test_class::copy_count(), 0);
+
+ return 0;
+}
Added: trunk/libs/utility/swap/test/swap_test_class.hpp
==============================================================================
--- (empty file)
+++ trunk/libs/utility/swap/test/swap_test_class.hpp 2008-07-05 07:16:38 EDT (Sat, 05 Jul 2008)
@@ -0,0 +1,171 @@
+// Copyright (c) 2007 Joseph Gauterin
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+// Tests that the swap header compiles as a standalone translation unit
+
+#ifndef BOOST_UTILITY_SWAP_TEST_CLASS_HPP
+#define BOOST_UTILITY_SWAP_TEST_CLASS_HPP
+
+
+class swap_test_class
+{
+public:
+ swap_test_class()
+ {
+ ++constructCount();
+ }
+
+ ~swap_test_class()
+ {
+ ++destructCount();
+ }
+
+ swap_test_class(const swap_test_class&)
+ {
+ ++copyCount();
+ ++destructCount();
+ }
+
+ swap_test_class& operator=(const swap_test_class&)
+ {
+ ++copyCount();
+ return *this;
+ }
+
+ void swap(swap_test_class& other)
+ {
+ ++swapCount();
+ }
+
+
+ static unsigned int swap_count(){ return swapCount(); }
+ static unsigned int copy_count(){ return copyCount(); }
+ static unsigned int construct_count(){ return constructCount(); }
+ static unsigned int destruct_count(){ return destructCount(); }
+
+ static void reset()
+ {
+ swapCount() = 0;
+ copyCount() = 0;
+ constructCount() = 0;
+ destructCount() = 0;
+ }
+
+private:
+ static unsigned int& swapCount()
+ {
+ static unsigned int value = 0;
+ return value;
+ }
+
+ static unsigned int& copyCount()
+ {
+ static unsigned int value = 0;
+ return value;
+ }
+
+ static unsigned int& constructCount()
+ {
+ static unsigned int value = 0;
+ return value;
+ }
+
+ static unsigned int& destructCount()
+ {
+ static unsigned int value = 0;
+ return value;
+ }
+
+};
+
+#endif
+
+// Copyright (c) 2007 Joseph Gauterin
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+// Tests that the swap header compiles as a standalone translation unit
+
+#ifndef BOOST_UTILITY_SWAP_TEST_CLASS_HPP
+#define BOOST_UTILITY_SWAP_TEST_CLASS_HPP
+
+
+class swap_test_class
+{
+public:
+ swap_test_class()
+ {
+ ++constructCount();
+ }
+
+ ~swap_test_class()
+ {
+ ++destructCount();
+ }
+
+ swap_test_class(const swap_test_class&)
+ {
+ ++copyCount();
+ ++destructCount();
+ }
+
+ swap_test_class& operator=(const swap_test_class&)
+ {
+ ++copyCount();
+ return *this;
+ }
+
+ void swap(swap_test_class& other)
+ {
+ ++swapCount();
+ }
+
+
+ static unsigned int swap_count(){ return swapCount(); }
+ static unsigned int copy_count(){ return copyCount(); }
+ static unsigned int construct_count(){ return constructCount(); }
+ static unsigned int destruct_count(){ return destructCount(); }
+
+ static void reset()
+ {
+ swapCount() = 0;
+ copyCount() = 0;
+ constructCount() = 0;
+ destructCount() = 0;
+ }
+
+private:
+ static unsigned int& swapCount()
+ {
+ static unsigned int value = 0;
+ return value;
+ }
+
+ static unsigned int& copyCount()
+ {
+ static unsigned int value = 0;
+ return value;
+ }
+
+ static unsigned int& constructCount()
+ {
+ static unsigned int value = 0;
+ return value;
+ }
+
+ static unsigned int& destructCount()
+ {
+ static unsigned int value = 0;
+ return value;
+ }
+
+};
+
+#endif
+
+
Modified: trunk/status/Jamfile.v2
==============================================================================
--- trunk/status/Jamfile.v2 (original)
+++ trunk/status/Jamfile.v2 2008-07-05 07:16:38 EDT (Sat, 05 Jul 2008)
@@ -125,6 +125,7 @@
unordered/test/unordered # test-suite unordered
unordered/test/exception # test-suite unordered-exception
utility/enable_if/test # test-suite utility/enable_if
+ utility/swap/test # test-suite utility/swap
utility/test # test-suite utility
variant/test # test-suite variant
wave/test/build # test-suite wave
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk