Index: boost/swap.hpp =================================================================== --- boost/swap.hpp (revision 0) +++ boost/swap.hpp (revision 0) @@ -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 Property changes on: boost\swap.hpp ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Id Name: svn:eol-style + native Index: boost/utility/swap.hpp =================================================================== --- boost/utility/swap.hpp (revision 0) +++ boost/utility/swap.hpp (revision 0) @@ -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 //for std::swap +#include //for std::size_t + +namespace boost_swap_impl +{ + template + void swap_impl(T& left, T& right) + { + using std::swap;//use std::swap if argument dependent lookup fails + swap(left,right); + } + + template + 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 + void swap(T& left, T& right) + { + ::boost_swap_impl::swap_impl(left, right); + } + } + + using swap_adl_barrier::swap; +} + +#endif Property changes on: boost\utility\swap.hpp ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Id Name: svn:eol-style + native Index: libs/libraries.htm =================================================================== --- libs/libraries.htm (revision 47033) +++ libs/libraries.htm (working copy) @@ -251,6 +251,8 @@ Guzman, Hartmut Kaiser, Dan Nuffer and team.
  • string_algo - String algorithms library, from Pavol Droba.
  • +
  • swap - + Enhanced generic swap function, from Joseph Gauterin.
  • system - Operating system support, including the diagnostics support that will be part of the C++0x standard library, from Beman Dawes.
  • @@ -664,6 +666,8 @@
  • statechart - Arbitrarily complex finite state machines can be implemented in easily readable and maintainable C++ code, from Andreas Huber.
  • +
  • swap - + Enhanced generic swap function, from Joseph Gauterin.
  • system - Operating system support, including the diagnostics support that will be part of the C++0x standard library, from Beman Dawes.
  • Index: libs/maintainers.txt =================================================================== --- libs/maintainers.txt (revision 47033) +++ libs/maintainers.txt (working copy) @@ -82,6 +82,7 @@ unordered Daniel James utility utility/enable_if Jaakko Jarvi , Jeremiah Willcock +utility/swap Joseph Gauterin variant Eric Friedman wave Hartmut Kaiser xpressive Eric Niebler Index: libs/utility/index.html =================================================================== --- libs/utility/index.html (revision 47033) +++ libs/utility/index.html (working copy) @@ -24,6 +24,7 @@ iterator_adaptors
    generator iterator adaptors
    operators
    + swap
    throw_exception
    utility
    value_init

    Index: libs/utility/swap.html =================================================================== --- libs/utility/swap.html (revision 0) +++ libs/utility/swap.html (revision 0) @@ -0,0 +1,94 @@ + + + + + + Boost: Swap Documentation + + + + C++ Boost +

    Swap

    + +

    + template<class T> void swap(T& left, T& right); +

    + + +

    + The template function boost::swap 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, std::swap is used. +

    + + +

    Rationale

    +

    + The generic std::swap 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 possible1).

    +

    + 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. +

    +

    + boost::swap also supports swapping built-in arrays. Note that std::swap doesn't yet do so, but a request to add an overload of std::swap for built-in arrays has been well-received by the Library Working Group of the C++ Standards Committee2. +

    + + +

    Exception Safety

    +

    + boost::swap provides the same exception guarantee as the underlying swap function used, with one exception; for an array of type T[n], where n > 1 and the underlying swap function for T provides the strong exception guarantee, boost::swap provides only the basic exception guarantee. +

    + + +

    Requirements

    +

    Either:

    +
      +
    • T must be assignable
    • +
    • T must be copy constructible
    • +
    +

    Or:

    +
      +
    • A function with the signature swap(T&,T&) is available via argument dependent lookup
    • +
    +

    Or:

    +
      +
    • A template specialization of std::swap exists for T
    • +
    +

    Or:

    +
      +
    • T is a built-in array of swappable elements
    • +
    + + + +

    Portability

    +

    + Several older compilers do not support argument dependent lookup – on these compilers boost::swap will call std::swap, ignoring any specialized swap functions that could be found as a result of argument dependent lookup. +

    + + +

    Credits

    +
      +
    • + Niels Dekker - for implementing and documenting support for built-in arrays +
    • +
    • + Joseph Gauterin - for the initial idea, implementation, tests, and documentation +
    • +
    • + Steven Wanatabe - for the idea to use a barrier namespace, enabling the function to have the name 'swap' without introducing ambiguity or infinite recursion +
    • +
    + + +
    +

    [1]Scott Meyers, Effective C++ Third Edition, Item 25: "Consider support for a non-throwing swap"

    +

    [2]LWG issue 809 (std::swap should be overloaded for array types)

    + + +
    +

    Revised: 3 July 2008

    +

    + 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>.) +

    + + + \ No newline at end of file Property changes on: libs\utility\swap.html ___________________________________________________________________ Name: svn:mime-type + text/html Name: svn:keywords + Id Name: svn:eol-style + native Index: libs/utility/swap/test/lib_header_1.cpp =================================================================== --- libs/utility/swap/test/lib_header_1.cpp (revision 0) +++ libs/utility/swap/test/lib_header_1.cpp (revision 0) @@ -0,0 +1,9 @@ +// 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 Property changes on: libs\utility\swap\test\lib_header_1.cpp ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Id Name: svn:eol-style + native Index: libs/utility/swap/test/lib_header_2.cpp =================================================================== --- libs/utility/swap/test/lib_header_2.cpp (revision 0) +++ libs/utility/swap/test/lib_header_2.cpp (revision 0) @@ -0,0 +1,10 @@ +// 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 +#include Property changes on: libs\utility\swap\test\lib_header_2.cpp ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Id Name: svn:eol-style + native Index: libs/utility/swap/test/mixed_headers_1.cpp =================================================================== --- libs/utility/swap/test/mixed_headers_1.cpp (revision 0) +++ libs/utility/swap/test/mixed_headers_1.cpp (revision 0) @@ -0,0 +1,10 @@ +// 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 +#include Property changes on: libs\utility\swap\test\mixed_headers_1.cpp ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Id Name: svn:eol-style + native Index: libs/utility/swap/test/mixed_headers_2.cpp =================================================================== --- libs/utility/swap/test/mixed_headers_2.cpp (revision 0) +++ libs/utility/swap/test/mixed_headers_2.cpp (revision 0) @@ -0,0 +1,10 @@ +// 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 +#include Property changes on: libs\utility\swap\test\mixed_headers_2.cpp ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Id Name: svn:eol-style + native Index: libs/utility/swap/test/specialized_in_global.cpp =================================================================== --- libs/utility/swap/test/specialized_in_global.cpp (revision 0) +++ libs/utility/swap/test/specialized_in_global.cpp (revision 0) @@ -0,0 +1,30 @@ +// 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 +#define BOOST_INCLUDE_MAIN +#include + +//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; +} \ No newline at end of file Property changes on: libs\utility\swap\test\specialized_in_global.cpp ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Id Name: svn:eol-style + native Index: libs/utility/swap/test/specialized_in_other.cpp =================================================================== --- libs/utility/swap/test/specialized_in_other.cpp (revision 0) +++ libs/utility/swap/test/specialized_in_other.cpp (revision 0) @@ -0,0 +1,36 @@ +// 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 +#define BOOST_INCLUDE_MAIN +#include + +//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; +} \ No newline at end of file Property changes on: libs\utility\swap\test\specialized_in_other.cpp ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Id Name: svn:eol-style + native Index: libs/utility/swap/test/swap_test_class.hpp =================================================================== --- libs/utility/swap/test/swap_test_class.hpp (revision 0) +++ libs/utility/swap/test/swap_test_class.hpp (revision 0) @@ -0,0 +1,85 @@ +// 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 + Property changes on: libs\utility\swap\test\swap_test_class.hpp ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Id Name: svn:eol-style + native Index: libs/utility/swap/test/primitive.cpp =================================================================== --- libs/utility/swap/test/primitive.cpp (revision 0) +++ libs/utility/swap/test/primitive.cpp (revision 0) @@ -0,0 +1,22 @@ +// 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 +#define BOOST_INCLUDE_MAIN +#include + +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; +} \ No newline at end of file Property changes on: libs\utility\swap\test\primitive.cpp ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Id Name: svn:eol-style + native Index: libs/utility/swap/test/specialized_in_boost.cpp =================================================================== --- libs/utility/swap/test/specialized_in_boost.cpp (revision 0) +++ libs/utility/swap/test/specialized_in_boost.cpp (revision 0) @@ -0,0 +1,36 @@ +// 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 +#define BOOST_INCLUDE_MAIN +#include + +//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; +} \ No newline at end of file Property changes on: libs\utility\swap\test\specialized_in_boost.cpp ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Id Name: svn:eol-style + native Index: libs/utility/swap/test/root_header_1.cpp =================================================================== --- libs/utility/swap/test/root_header_1.cpp (revision 0) +++ libs/utility/swap/test/root_header_1.cpp (revision 0) @@ -0,0 +1,9 @@ +// 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 Property changes on: libs\utility\swap\test\root_header_1.cpp ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Id Name: svn:eol-style + native Index: libs/utility/swap/test/swap_arrays.cpp =================================================================== --- libs/utility/swap/test/swap_arrays.cpp (revision 0) +++ libs/utility/swap/test/swap_arrays.cpp (revision 0) @@ -0,0 +1,39 @@ +// 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 +#define BOOST_INCLUDE_MAIN +#include + +//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; +} Property changes on: libs\utility\swap\test\swap_arrays.cpp ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Id Name: svn:eol-style + native Index: libs/utility/swap/test/Jamfile.v2 =================================================================== --- libs/utility/swap/test/Jamfile.v2 (revision 0) +++ libs/utility/swap/test/Jamfile.v2 (revision 0) @@ -0,0 +1,26 @@ +# 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/static ] + [ run specialized_in_boost.cpp ../../../test/build//boost_test_exec_monitor/static ] + [ run specialized_in_global.cpp ../../../test/build//boost_test_exec_monitor/static ] + [ run specialized_in_other.cpp ../../../test/build//boost_test_exec_monitor/static ] + [ run specialized_in_std.cpp ../../../test/build//boost_test_exec_monitor/static ] + [ run swap_arrays.cpp ../../../test/build//boost_test_exec_monitor/static ] + ; + + Property changes on: libs\utility\swap\test\Jamfile.v2 ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Id Name: svn:eol-style + native Index: libs/utility/swap/test/root_header_2.cpp =================================================================== --- libs/utility/swap/test/root_header_2.cpp (revision 0) +++ libs/utility/swap/test/root_header_2.cpp (revision 0) @@ -0,0 +1,10 @@ +// 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 +#include Property changes on: libs\utility\swap\test\root_header_2.cpp ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Id Name: svn:eol-style + native Index: libs/utility/swap/test/specialized_in_std.cpp =================================================================== --- libs/utility/swap/test/specialized_in_std.cpp (revision 0) +++ libs/utility/swap/test/specialized_in_std.cpp (revision 0) @@ -0,0 +1,35 @@ +// 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 +#define BOOST_INCLUDE_MAIN +#include + +//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; +} \ No newline at end of file Property changes on: libs\utility\swap\test\specialized_in_std.cpp ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Id Name: svn:eol-style + native Index: libs/utility/swap/test/Jamfile.v2 =================================================================== --- libs/utility/swap/test/Jamfile.v2 (revision 0) +++ libs/utility/swap/test/Jamfile.v2 (revision 0) @@ -0,0 +1,26 @@ +# 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/static ] + [ run specialized_in_boost.cpp ../../../test/build//boost_test_exec_monitor/static ] + [ run specialized_in_global.cpp ../../../test/build//boost_test_exec_monitor/static ] + [ run specialized_in_other.cpp ../../../test/build//boost_test_exec_monitor/static ] + [ run specialized_in_std.cpp ../../../test/build//boost_test_exec_monitor/static ] + [ run swap_arrays.cpp ../../../test/build//boost_test_exec_monitor/static ] + ; + + Property changes on: libs\utility\swap\test\Jamfile.v2 ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Id Name: svn:eol-style + native Index: libs/utility/swap/test/lib_header_1.cpp =================================================================== --- libs/utility/swap/test/lib_header_1.cpp (revision 0) +++ libs/utility/swap/test/lib_header_1.cpp (revision 0) @@ -0,0 +1,9 @@ +// 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 Property changes on: libs\utility\swap\test\lib_header_1.cpp ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Id Name: svn:eol-style + native Index: libs/utility/swap/test/lib_header_2.cpp =================================================================== --- libs/utility/swap/test/lib_header_2.cpp (revision 0) +++ libs/utility/swap/test/lib_header_2.cpp (revision 0) @@ -0,0 +1,10 @@ +// 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 +#include Property changes on: libs\utility\swap\test\lib_header_2.cpp ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Id Name: svn:eol-style + native Index: libs/utility/swap/test/mixed_headers_1.cpp =================================================================== --- libs/utility/swap/test/mixed_headers_1.cpp (revision 0) +++ libs/utility/swap/test/mixed_headers_1.cpp (revision 0) @@ -0,0 +1,10 @@ +// 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 +#include Property changes on: libs\utility\swap\test\mixed_headers_1.cpp ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Id Name: svn:eol-style + native Index: libs/utility/swap/test/mixed_headers_2.cpp =================================================================== --- libs/utility/swap/test/mixed_headers_2.cpp (revision 0) +++ libs/utility/swap/test/mixed_headers_2.cpp (revision 0) @@ -0,0 +1,10 @@ +// 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 +#include Property changes on: libs\utility\swap\test\mixed_headers_2.cpp ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Id Name: svn:eol-style + native Index: libs/utility/swap/test/primitive.cpp =================================================================== --- libs/utility/swap/test/primitive.cpp (revision 0) +++ libs/utility/swap/test/primitive.cpp (revision 0) @@ -0,0 +1,22 @@ +// 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 +#define BOOST_INCLUDE_MAIN +#include + +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; +} \ No newline at end of file Property changes on: libs\utility\swap\test\primitive.cpp ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Id Name: svn:eol-style + native Index: libs/utility/swap/test/root_header_1.cpp =================================================================== --- libs/utility/swap/test/root_header_1.cpp (revision 0) +++ libs/utility/swap/test/root_header_1.cpp (revision 0) @@ -0,0 +1,9 @@ +// 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 Property changes on: libs\utility\swap\test\root_header_1.cpp ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Id Name: svn:eol-style + native Index: libs/utility/swap/test/root_header_2.cpp =================================================================== --- libs/utility/swap/test/root_header_2.cpp (revision 0) +++ libs/utility/swap/test/root_header_2.cpp (revision 0) @@ -0,0 +1,10 @@ +// 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 +#include Property changes on: libs\utility\swap\test\root_header_2.cpp ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Id Name: svn:eol-style + native Index: libs/utility/swap/test/specialized_in_boost.cpp =================================================================== --- libs/utility/swap/test/specialized_in_boost.cpp (revision 0) +++ libs/utility/swap/test/specialized_in_boost.cpp (revision 0) @@ -0,0 +1,36 @@ +// 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 +#define BOOST_INCLUDE_MAIN +#include + +//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; +} \ No newline at end of file Property changes on: libs\utility\swap\test\specialized_in_boost.cpp ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Id Name: svn:eol-style + native Index: libs/utility/swap/test/specialized_in_global.cpp =================================================================== --- libs/utility/swap/test/specialized_in_global.cpp (revision 0) +++ libs/utility/swap/test/specialized_in_global.cpp (revision 0) @@ -0,0 +1,30 @@ +// 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 +#define BOOST_INCLUDE_MAIN +#include + +//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; +} \ No newline at end of file Property changes on: libs\utility\swap\test\specialized_in_global.cpp ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Id Name: svn:eol-style + native Index: libs/utility/swap/test/specialized_in_other.cpp =================================================================== --- libs/utility/swap/test/specialized_in_other.cpp (revision 0) +++ libs/utility/swap/test/specialized_in_other.cpp (revision 0) @@ -0,0 +1,36 @@ +// 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 +#define BOOST_INCLUDE_MAIN +#include + +//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; +} \ No newline at end of file Property changes on: libs\utility\swap\test\specialized_in_other.cpp ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Id Name: svn:eol-style + native Index: libs/utility/swap/test/specialized_in_std.cpp =================================================================== --- libs/utility/swap/test/specialized_in_std.cpp (revision 0) +++ libs/utility/swap/test/specialized_in_std.cpp (revision 0) @@ -0,0 +1,35 @@ +// 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 +#define BOOST_INCLUDE_MAIN +#include + +//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; +} \ No newline at end of file Property changes on: libs\utility\swap\test\specialized_in_std.cpp ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Id Name: svn:eol-style + native Index: libs/utility/swap/test/swap_arrays.cpp =================================================================== --- libs/utility/swap/test/swap_arrays.cpp (revision 0) +++ libs/utility/swap/test/swap_arrays.cpp (revision 0) @@ -0,0 +1,39 @@ +// 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 +#define BOOST_INCLUDE_MAIN +#include + +//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; +} Property changes on: libs\utility\swap\test\swap_arrays.cpp ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Id Name: svn:eol-style + native Index: libs/utility/swap/test/swap_test_class.hpp =================================================================== --- libs/utility/swap/test/swap_test_class.hpp (revision 0) +++ libs/utility/swap/test/swap_test_class.hpp (revision 0) @@ -0,0 +1,85 @@ +// 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 + Property changes on: libs\utility\swap\test\swap_test_class.hpp ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Id Name: svn:eol-style + native Index: status/Jamfile.v2 =================================================================== --- status/Jamfile.v2 (revision 47033) +++ status/Jamfile.v2 (working copy) @@ -112,6 +112,7 @@ spirit/test # test-suite spirit_v2 statechart/test # test-suite statechart static_assert # test-suite static_assert + static_assert # test-suite static_assert system/test # test-suite system test/test # test-suite test thread/test # test-suite thread @@ -125,6 +126,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