Boost logo

Boost-Commit :

From: nielsdekker_at_[hidden]
Date: 2008-07-27 07:35:34


Author: niels_dekker
Date: 2008-07-27 07:35:33 EDT (Sun, 27 Jul 2008)
New Revision: 47839
URL: http://svn.boost.org/trac/boost/changeset/47839

Log:
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
Added:
   trunk/libs/utility/swap/test/specialized_in_boost_and_other.cpp (contents, props changed)
Text files modified:
   trunk/libs/utility/swap/test/Jamfile.v2 | 15 ++++++++-------
   1 files changed, 8 insertions(+), 7 deletions(-)

Modified: trunk/libs/utility/swap/test/Jamfile.v2
==============================================================================
--- trunk/libs/utility/swap/test/Jamfile.v2 (original)
+++ trunk/libs/utility/swap/test/Jamfile.v2 2008-07-27 07:35:33 EDT (Sun, 27 Jul 2008)
@@ -15,11 +15,12 @@
     [ 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 test_adl_barrier.cpp ../../../test/build//boost_test_exec_monitor/<link>static ]
- [ run swap_arrays.cpp ../../../test/build//boost_test_exec_monitor/<link>static ]
+ [ 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 specialized_in_boost_and_other.cpp ../../../test/build//boost_test_exec_monitor/<link>static ]
+ [ run test_adl_barrier.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/specialized_in_boost_and_other.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/utility/swap/test/specialized_in_boost_and_other.cpp 2008-07-27 07:35:33 EDT (Sun, 27 Jul 2008)
@@ -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 <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 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;
+}
+


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