From 3fd0ea6e7527118e0ea948b56f54140ed85422ba Mon Sep 17 00:00:00 2001 From: Niels Dekker Date: Sun, 27 Jul 2008 11:35:33 +0000 Subject: [PATCH] Added specialized_in_boost_and_other to swap/test, as discussed at "[boost] [swap] End-user allowed to add overloads to boost namespace?", http://lists.boost.org/Archives/boost/2008/07/140327.php [SVN r47839] --- swap/test/Jamfile.v2 | 15 +++--- swap/test/specialized_in_boost_and_other.cpp | 56 ++++++++++++++++++++ 2 files changed, 64 insertions(+), 7 deletions(-) create mode 100644 swap/test/specialized_in_boost_and_other.cpp diff --git a/swap/test/Jamfile.v2 b/swap/test/Jamfile.v2 index d648de2..abce519 100644 --- a/swap/test/Jamfile.v2 +++ b/swap/test/Jamfile.v2 @@ -15,11 +15,12 @@ test-suite utility/swap [ 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 test_adl_barrier.cpp ../../../test/build//boost_test_exec_monitor/static ] - [ run swap_arrays.cpp ../../../test/build//boost_test_exec_monitor/static ] + [ 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 specialized_in_boost_and_other.cpp ../../../test/build//boost_test_exec_monitor/static ] + [ run test_adl_barrier.cpp ../../../test/build//boost_test_exec_monitor/static ] + [ run swap_arrays.cpp ../../../test/build//boost_test_exec_monitor/static ] ; diff --git a/swap/test/specialized_in_boost_and_other.cpp b/swap/test/specialized_in_boost_and_other.cpp new file mode 100644 index 0000000..fc76251 --- /dev/null +++ b/swap/test/specialized_in_boost_and_other.cpp @@ -0,0 +1,56 @@ +// 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) + +// Tests whether two object in a namespace other than boost are properly +// swapped, when both boost and the other namespace have a custom swap function +// for their class. Note that it shouldn't be necessary for a class in an other +// namespace to have a custom swap function in boost, because the boost::swap +// utility should find the swap function in the other namespace, by argument +// dependent lookup (ADL). Unfortunately ADL isn't fully implemented by some +// specific compilers, including Intel C++ 8.1, MSVC 7.1, and Borland 5.9.3. +// Users of those compilers might consider adding a swap overload to the boost +// namespace. + +#include +#define BOOST_INCLUDE_MAIN +#include + +//Put test class in namespace other +namespace other +{ + #include "./swap_test_class.hpp" +} + +//Provide swap function in namespace boost +namespace boost +{ + void swap(::other::swap_test_class& left, ::other::swap_test_class& right) + { + left.swap(right); + } +} + +//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; +} +