diff --git a/enable_if/test/constructors.cpp b/enable_if/test/constructors.cpp
index 889133d..0d465de 100644
--- a/enable_if/test/constructors.cpp
+++ b/enable_if/test/constructors.cpp
@@ -6,7 +6,7 @@
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
-// Authors: Jaakko Järvi (jajarvi at osl.iu.edu)
+// Authors: Jaakko Jarvi (jajarvi at osl.iu.edu)
// Jeremiah Willcock (jewillco at osl.iu.edu)
// Andrew Lumsdaine (lums at osl.iu.edu)
diff --git a/enable_if/test/dummy_arg_disambiguation.cpp b/enable_if/test/dummy_arg_disambiguation.cpp
index 90275e9..60dfdfd 100644
--- a/enable_if/test/dummy_arg_disambiguation.cpp
+++ b/enable_if/test/dummy_arg_disambiguation.cpp
@@ -6,7 +6,7 @@
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
-// Authors: Jaakko Järvi (jajarvi at osl.iu.edu)
+// Authors: Jaakko Jarvi (jajarvi at osl.iu.edu)
// Jeremiah Willcock (jewillco at osl.iu.edu)
// Andrew Lumsdaine (lums at osl.iu.edu)
diff --git a/enable_if/test/lazy.cpp b/enable_if/test/lazy.cpp
index 117ec41..f04111e 100644
--- a/enable_if/test/lazy.cpp
+++ b/enable_if/test/lazy.cpp
@@ -6,7 +6,7 @@
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
-// Authors: Jaakko Järvi (jajarvi at osl.iu.edu)
+// Authors: Jaakko Jarvi (jajarvi at osl.iu.edu)
// Jeremiah Willcock (jewillco at osl.iu.edu)
// Andrew Lumsdaine (lums at osl.iu.edu)
diff --git a/enable_if/test/lazy_test.cpp b/enable_if/test/lazy_test.cpp
index 10bb60c..9ec5324 100644
--- a/enable_if/test/lazy_test.cpp
+++ b/enable_if/test/lazy_test.cpp
@@ -6,7 +6,7 @@
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
-// Authors: Jaakko Järvi (jajarvi at osl.iu.edu)
+// Authors: Jaakko Jarvi (jajarvi at osl.iu.edu)
// Jeremiah Willcock (jewillco at osl.iu.edu)
// Andrew Lumsdaine (lums at osl.iu.edu)
diff --git a/enable_if/test/member_templates.cpp b/enable_if/test/member_templates.cpp
index f7c00a0..55e2d80 100644
--- a/enable_if/test/member_templates.cpp
+++ b/enable_if/test/member_templates.cpp
@@ -6,7 +6,7 @@
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
-// Authors: Jaakko Järvi (jajarvi at osl.iu.edu)
+// Authors: Jaakko Jarvi (jajarvi at osl.iu.edu)
// Jeremiah Willcock (jewillco at osl.iu.edu)
// Andrew Lumsdaine (lums at osl.iu.edu)
diff --git a/enable_if/test/namespace_disambiguation.cpp b/enable_if/test/namespace_disambiguation.cpp
index a53d3a7..45d4f0a 100644
--- a/enable_if/test/namespace_disambiguation.cpp
+++ b/enable_if/test/namespace_disambiguation.cpp
@@ -6,7 +6,7 @@
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
-// Authors: Jaakko Järvi (jajarvi at osl.iu.edu)
+// Authors: Jaakko Jarvi (jajarvi at osl.iu.edu)
// Jeremiah Willcock (jewillco at osl.iu.edu)
// Andrew Lumsdaine (lums at osl.iu.edu)
diff --git a/enable_if/test/no_disambiguation.cpp b/enable_if/test/no_disambiguation.cpp
index 122d600..e2416ed 100644
--- a/enable_if/test/no_disambiguation.cpp
+++ b/enable_if/test/no_disambiguation.cpp
@@ -6,7 +6,7 @@
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
-// Authors: Jaakko Järvi (jajarvi at osl.iu.edu)
+// Authors: Jaakko Jarvi (jajarvi at osl.iu.edu)
// Jeremiah Willcock (jewillco at osl.iu.edu)
// Andrew Lumsdaine (lums at osl.iu.edu)
diff --git a/enable_if/test/partial_specializations.cpp b/enable_if/test/partial_specializations.cpp
index 5c322ae..1d4db99 100644
--- a/enable_if/test/partial_specializations.cpp
+++ b/enable_if/test/partial_specializations.cpp
@@ -6,7 +6,7 @@
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
-// Authors: Jaakko Järvi (jajarvi at osl.iu.edu)
+// Authors: Jaakko Jarvi (jajarvi at osl.iu.edu)
// Jeremiah Willcock (jewillco at osl.iu.edu)
// Andrew Lumsdaine (lums at osl.iu.edu)
diff --git a/include/boost/exception.hpp b/include/boost/exception.hpp
index aca1409..d805002 100644
--- a/include/boost/exception.hpp
+++ b/include/boost/exception.hpp
@@ -6,6 +6,12 @@
#ifndef UUID_1D94A7C6054E11DB9804B622A1EF5492
#define UUID_1D94A7C6054E11DB9804B622A1EF5492
+#include
+#include
+#include
+#include
+#include
+#include
#include
#include
#include
diff --git a/include/boost/ref.hpp b/include/boost/ref.hpp
index ab09ae7..9c996ab 100644
--- a/include/boost/ref.hpp
+++ b/include/boost/ref.hpp
@@ -15,7 +15,7 @@
//
// ref.hpp - ref/cref, useful helper functions
//
-// 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, 2002 Peter Dimov
// Copyright (C) 2002 David Abrahams
//
@@ -173,6 +173,12 @@ class unwrap_reference
# endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
+template inline typename unwrap_reference::type&
+unwrap_ref(T& t)
+{
+ return t;
+}
+
} // namespace boost
#endif // #ifndef BOOST_REF_HPP_INCLUDED
diff --git a/include/boost/utility/enable_if.hpp b/include/boost/utility/enable_if.hpp
index d77d108..d292c6a 100644
--- a/include/boost/utility/enable_if.hpp
+++ b/include/boost/utility/enable_if.hpp
@@ -6,7 +6,7 @@
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
-// Authors: Jaakko Järvi (jajarvi at osl.iu.edu)
+// Authors: Jaakko Jarvi (jajarvi at osl.iu.edu)
// Jeremiah Willcock (jewillco at osl.iu.edu)
// Andrew Lumsdaine (lums at osl.iu.edu)
diff --git a/index.html b/index.html
index 7605aef..5af6f75 100644
--- a/index.html
+++ b/index.html
@@ -24,12 +24,13 @@
iterator_adaptors
generator iterator adaptors
operators
+ swap
throw_exception
utility
value_init
- © Copyright Beman Dawes, 2001
+ © Copyright Beman Dawes, 2001
Distributed under the Boost Software License, Version 1.0. (See
accompanying file
LICENSE_1_0.txt or copy at
diff --git a/ref_test.cpp b/ref_test.cpp
index 63fc9e5..d4237b4 100644
--- a/ref_test.cpp
+++ b/ref_test.cpp
@@ -68,11 +68,54 @@ struct ref_wrapper
}
};
+struct copy_counter {
+ static int count_;
+ copy_counter(copy_counter const& other) {
+ ++count_;
+ }
+ copy_counter() {}
+ static void reset() { count_ = 0; }
+ static int count() { return copy_counter::count_; }
+};
+
+int copy_counter::count_ = 0;
+
} // namespace unnamed
+template
+void do_unwrap(T t) {
+
+ /* typename unwrap_reference::type& lt = */
+ unwrap_ref(t);
+
+}
+
+void unwrap_test() {
+
+ int i = 3;
+ const int ci = 2;
+
+ do_unwrap(i);
+ do_unwrap(ci);
+ do_unwrap(ref(i));
+ do_unwrap(cref(ci));
+ do_unwrap(ref(ci));
+
+ copy_counter cc;
+ BOOST_CHECK(cc.count() == 0);
+
+ do_unwrap(cc);
+ do_unwrap(ref(cc));
+ do_unwrap(cref(cc));
+
+ BOOST_CHECK(cc.count() == 1);
+ BOOST_CHECK(unwrap_ref(ref(cc)).count() == 1);
+}
+
int test_main(int, char * [])
{
ref_wrapper::test(1);
ref_wrapper::test(1);
+ unwrap_test();
return 0;
}
diff --git a/swap/test/Jamfile.v2 b/swap/test/Jamfile.v2
new file mode 100644
index 0000000..7071837
--- /dev/null
+++ b/swap/test/Jamfile.v2
@@ -0,0 +1,33 @@
+# 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 specialized_in_boost_and_other.cpp ../../../test/build//boost_test_exec_monitor/ static ]
+ [ run std_bitset.cpp ../../../test/build//boost_test_exec_monitor/ static ]
+ [ run std_dateorder.cpp ../../../test/build//boost_test_exec_monitor/ static ]
+ [ run std_string.cpp ../../../test/build//boost_test_exec_monitor/ static ]
+ [ run std_typeinfo_ptr.cpp ../../../test/build//boost_test_exec_monitor/ static ]
+ [ run std_vector_of_boost.cpp ../../../test/build//boost_test_exec_monitor/ static ]
+ [ run std_vector_of_global.cpp ../../../test/build//boost_test_exec_monitor/ static ]
+ [ run std_vector_of_other.cpp ../../../test/build//boost_test_exec_monitor/ static ]
+ [ run no_ambiguity_in_boost.cpp ../../../test/build//boost_test_exec_monitor/ static ]
+ [ run swap_arrays.cpp ../../../test/build//boost_test_exec_monitor/ static ]
+ ;
diff --git a/swap/test/lib_header_1.cpp b/swap/test/lib_header_1.cpp
new file mode 100644
index 0000000..923dea6
--- /dev/null
+++ b/swap/test/lib_header_1.cpp
@@ -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 compiles as a standalone translation unit
+
+#include
+
diff --git a/swap/test/lib_header_2.cpp b/swap/test/lib_header_2.cpp
new file mode 100644
index 0000000..e88909d
--- /dev/null
+++ b/swap/test/lib_header_2.cpp
@@ -0,0 +1,11 @@
+// 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
+
diff --git a/swap/test/mixed_headers_1.cpp b/swap/test/mixed_headers_1.cpp
new file mode 100644
index 0000000..cdb9fe5
--- /dev/null
+++ b/swap/test/mixed_headers_1.cpp
@@ -0,0 +1,11 @@
+// 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
+
diff --git a/swap/test/mixed_headers_2.cpp b/swap/test/mixed_headers_2.cpp
new file mode 100644
index 0000000..94e9d87
--- /dev/null
+++ b/swap/test/mixed_headers_2.cpp
@@ -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)
+
+// Tests that the swap headers work when both are included
+
+#include
+#include
+
+
diff --git a/swap/test/no_ambiguity_in_boost.cpp b/swap/test/no_ambiguity_in_boost.cpp
new file mode 100644
index 0000000..17fe9d6
--- /dev/null
+++ b/swap/test/no_ambiguity_in_boost.cpp
@@ -0,0 +1,37 @@
+// 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)
+
+// boost::swap internally does an unqualified function call to swap.
+// This could have led to ambiguity or infinite recursion, when the
+// objects to be swapped would themselves be from the boost namespace.
+// If so, boost::swap itself might be found by argument dependent lookup.
+// The implementation of boost::swap resolves this issue by giving
+// boost::swap two template argumetns, thereby making it less specialized
+// than std::swap.
+
+#include
+#define BOOST_INCLUDE_MAIN
+#include
+
+//Put test class in namespace boost
+namespace boost
+{
+ #include "./swap_test_class.hpp"
+}
+
+
+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(),0);
+ BOOST_CHECK_EQUAL(boost::swap_test_class::copy_count(),3);
+
+ return 0;
+}
+
diff --git a/swap/test/primitive.cpp b/swap/test/primitive.cpp
new file mode 100644
index 0000000..380edb3
--- /dev/null
+++ b/swap/test/primitive.cpp
@@ -0,0 +1,23 @@
+// 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;
+}
+
diff --git a/swap/test/root_header_1.cpp b/swap/test/root_header_1.cpp
new file mode 100644
index 0000000..575d2cb
--- /dev/null
+++ b/swap/test/root_header_1.cpp
@@ -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 compiles as a standalone translation unit
+
+#include
+
diff --git a/swap/test/root_header_2.cpp b/swap/test/root_header_2.cpp
new file mode 100644
index 0000000..d26b3a6
--- /dev/null
+++ b/swap/test/root_header_2.cpp
@@ -0,0 +1,11 @@
+// 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
+
diff --git a/swap/test/specialized_in_boost.cpp b/swap/test/specialized_in_boost.cpp
new file mode 100644
index 0000000..55ac390
--- /dev/null
+++ b/swap/test/specialized_in_boost.cpp
@@ -0,0 +1,37 @@
+// 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;
+}
+
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..9adc5c0
--- /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 instances of a class from a namespace other than boost are
+// properly swapped, when both boost and the other namespace have a custom
+// swap function for that 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 compiler versions, 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;
+}
+
diff --git a/swap/test/specialized_in_global.cpp b/swap/test/specialized_in_global.cpp
new file mode 100644
index 0000000..f76754f
--- /dev/null
+++ b/swap/test/specialized_in_global.cpp
@@ -0,0 +1,31 @@
+// 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;
+}
+
diff --git a/swap/test/specialized_in_other.cpp b/swap/test/specialized_in_other.cpp
new file mode 100644
index 0000000..c3071f5
--- /dev/null
+++ b/swap/test/specialized_in_other.cpp
@@ -0,0 +1,37 @@
+// 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;
+}
+
diff --git a/swap/test/specialized_in_std.cpp b/swap/test/specialized_in_std.cpp
new file mode 100644
index 0000000..641aa82
--- /dev/null
+++ b/swap/test/specialized_in_std.cpp
@@ -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 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;
+}
+
diff --git a/swap/test/std_bitset.cpp b/swap/test/std_bitset.cpp
new file mode 100644
index 0000000..4b9fbae
--- /dev/null
+++ b/swap/test/std_bitset.cpp
@@ -0,0 +1,33 @@
+// 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 swapping std::bitset objects by means of boost::swap.
+// Unlike most other Standard C++ Library template classes,
+// std::bitset does not have its own std::swap overload.
+
+#include
+#define BOOST_INCLUDE_MAIN
+#include
+
+#include
+
+int test_main(int, char*[])
+{
+ typedef std::bitset<8> bitset_type;
+ const bitset_type initial_value1 = 1ul;
+ const bitset_type initial_value2 = 2ul;
+
+ bitset_type object1 = initial_value1;
+ bitset_type object2 = initial_value2;
+
+ boost::swap(object1,object2);
+
+ BOOST_CHECK_EQUAL(object1,initial_value2);
+ BOOST_CHECK_EQUAL(object2,initial_value1);
+
+ return 0;
+}
+
diff --git a/swap/test/std_dateorder.cpp b/swap/test/std_dateorder.cpp
new file mode 100644
index 0000000..b593f6f
--- /dev/null
+++ b/swap/test/std_dateorder.cpp
@@ -0,0 +1,32 @@
+// 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 swapping std::time_base::dateorder objects by means of boost::swap.
+// std::time_base::dateorder is an enumerated type. It does not have an
+// std::swap overload or template specialization.
+
+#include
+#define BOOST_INCLUDE_MAIN
+#include
+
+#include
+
+int test_main(int, char*[])
+{
+ const std::time_base::dateorder initial_value1 = std::time_base::dmy;
+ const std::time_base::dateorder initial_value2 = std::time_base::mdy;
+
+ std::time_base::dateorder object1 = initial_value1;
+ std::time_base::dateorder object2 = initial_value2;
+
+ boost::swap(object1,object2);
+
+ BOOST_CHECK_EQUAL(object1,initial_value2);
+ BOOST_CHECK_EQUAL(object2,initial_value1);
+
+ return 0;
+}
+
diff --git a/swap/test/std_string.cpp b/swap/test/std_string.cpp
new file mode 100644
index 0000000..b7d3d4d
--- /dev/null
+++ b/swap/test/std_string.cpp
@@ -0,0 +1,31 @@
+// 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 swapping std::string objects by means of boost::swap.
+// std::string has its own std::swap overload.
+
+#include
+#define BOOST_INCLUDE_MAIN
+#include
+
+#include
+
+int test_main(int, char*[])
+{
+ const std::string initial_value1 = "one";
+ const std::string initial_value2 = "two";
+
+ std::string object1 = initial_value1;
+ std::string object2 = initial_value2;
+
+ boost::swap(object1,object2);
+
+ BOOST_CHECK_EQUAL(object1,initial_value2);
+ BOOST_CHECK_EQUAL(object2,initial_value1);
+
+ return 0;
+}
+
diff --git a/swap/test/std_typeinfo_ptr.cpp b/swap/test/std_typeinfo_ptr.cpp
new file mode 100644
index 0000000..38e293a
--- /dev/null
+++ b/swap/test/std_typeinfo_ptr.cpp
@@ -0,0 +1,32 @@
+// 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 swapping std::type_info pointers by means of boost::swap.
+// There is no std::swap overload or template specialization
+// for std::type_info pointers.
+
+#include
+#define BOOST_INCLUDE_MAIN
+#include
+
+#include
+
+int test_main(int, char*[])
+{
+ const std::type_info * const initial_value1 = 0;
+ const std::type_info * const initial_value2 = &typeid(double);
+
+ const std::type_info * ptr1 = initial_value1;
+ const std::type_info * ptr2 = initial_value2;
+
+ boost::swap(ptr1,ptr2);
+
+ BOOST_CHECK_EQUAL(ptr1,initial_value2);
+ BOOST_CHECK_EQUAL(ptr2,initial_value1);
+
+ return 0;
+}
+
diff --git a/swap/test/std_vector_of_boost.cpp b/swap/test/std_vector_of_boost.cpp
new file mode 100644
index 0000000..f9c3888
--- /dev/null
+++ b/swap/test/std_vector_of_boost.cpp
@@ -0,0 +1,54 @@
+// 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 swapping std::vector objects by means of boost::swap,
+// having boost::swap_test_class as vector element type.
+
+#include
+#define BOOST_INCLUDE_MAIN
+#include
+
+#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*[])
+{
+ typedef boost::swap_test_class swap_test_class_type;
+ typedef std::vector vector_type;
+
+ const vector_type::size_type initial_size1 = 1;
+ const vector_type::size_type initial_size2 = 2;
+
+ vector_type object1(initial_size1);
+ vector_type object2(initial_size2);
+
+ swap_test_class_type::reset();
+
+ boost::swap(object1,object2);
+
+ BOOST_CHECK_EQUAL(object1.size(),initial_size2);
+ BOOST_CHECK_EQUAL(object2.size(),initial_size1);
+
+ BOOST_CHECK_EQUAL(swap_test_class_type::swap_count(),0);
+ BOOST_CHECK_EQUAL(swap_test_class_type::copy_count(),0);
+
+ return 0;
+}
+
diff --git a/swap/test/std_vector_of_global.cpp b/swap/test/std_vector_of_global.cpp
new file mode 100644
index 0000000..ef6b52b
--- /dev/null
+++ b/swap/test/std_vector_of_global.cpp
@@ -0,0 +1,47 @@
+// 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 swapping std::vector objects by means of boost::swap,
+// having ::swap_test_class as vector element type.
+
+#include
+#define BOOST_INCLUDE_MAIN
+#include
+
+#include
+
+//Put test class in the global namespace
+#include "./swap_test_class.hpp"
+
+//Provide swap function in the global namespace
+void swap(swap_test_class& left, swap_test_class& right)
+{
+ left.swap(right);
+}
+
+int test_main(int, char*[])
+{
+ typedef std::vector vector_type;
+
+ const vector_type::size_type initial_size1 = 1;
+ const vector_type::size_type initial_size2 = 2;
+
+ vector_type object1(initial_size1);
+ vector_type object2(initial_size2);
+
+ swap_test_class::reset();
+
+ boost::swap(object1,object2);
+
+ BOOST_CHECK_EQUAL(object1.size(),initial_size2);
+ BOOST_CHECK_EQUAL(object2.size(),initial_size1);
+
+ BOOST_CHECK_EQUAL(swap_test_class::swap_count(),0);
+ BOOST_CHECK_EQUAL(swap_test_class::copy_count(),0);
+
+ return 0;
+}
+
diff --git a/swap/test/std_vector_of_other.cpp b/swap/test/std_vector_of_other.cpp
new file mode 100644
index 0000000..3834269
--- /dev/null
+++ b/swap/test/std_vector_of_other.cpp
@@ -0,0 +1,54 @@
+// 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 swapping std::vector objects by means of boost::swap,
+// having other::swap_test_class as vector element type.
+
+#include
+#define BOOST_INCLUDE_MAIN
+#include
+
+#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*[])
+{
+ typedef other::swap_test_class swap_test_class_type;
+ typedef std::vector vector_type;
+
+ const vector_type::size_type initial_size1 = 1;
+ const vector_type::size_type initial_size2 = 2;
+
+ vector_type object1(initial_size1);
+ vector_type object2(initial_size2);
+
+ swap_test_class_type::reset();
+
+ boost::swap(object1,object2);
+
+ BOOST_CHECK_EQUAL(object1.size(),initial_size2);
+ BOOST_CHECK_EQUAL(object2.size(),initial_size1);
+
+ BOOST_CHECK_EQUAL(swap_test_class_type::swap_count(),0);
+ BOOST_CHECK_EQUAL(swap_test_class_type::copy_count(),0);
+
+ return 0;
+}
+
diff --git a/swap/test/swap_arrays.cpp b/swap/test/swap_arrays.cpp
new file mode 100644
index 0000000..79c6d68
--- /dev/null
+++ b/swap/test/swap_arrays.cpp
@@ -0,0 +1,59 @@
+// 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"
+
+//Provide swap function in both the namespace of swap_test_class
+//(which is the global namespace), and the std namespace.
+//It's common to provide a swap function for a class in both
+//namespaces. Scott Meyers recommends doing so: Effective C++,
+//Third Edition, item 25, "Consider support for a non-throwing swap".
+void swap(swap_test_class& left, swap_test_class& right)
+{
+ left.swap(right);
+}
+
+namespace std
+{
+ template <>
+ void swap(swap_test_class& left, swap_test_class& right)
+ {
+ left.swap(right);
+ }
+}
+
+
+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_array2);
+
+ BOOST_CHECK_EQUAL(swap_test_class::swap_count(), firstDimension*secondDimension);
+ BOOST_CHECK_EQUAL(swap_test_class::copy_count(), 0);
+
+ return 0;
+}
+
diff --git a/swap/test/swap_test_class.hpp b/swap/test/swap_test_class.hpp
new file mode 100644
index 0000000..aa68444
--- /dev/null
+++ b/swap/test/swap_test_class.hpp
@@ -0,0 +1,84 @@
+// 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)
+
+// Tests class used by the Boost.Swap tests
+
+#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