From 64a0e0cb205cb12abb3f608f31c548706790511a Mon Sep 17 00:00:00 2001 From: Niels Dekker Date: Sun, 20 Jul 2008 12:13:33 +0000 Subject: [PATCH] Added swap_test_class swap functions to test/swap_arrays.cpp. My fault, they should have been there already! [SVN r47628] --- swap/test/swap_arrays.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/swap/test/swap_arrays.cpp b/swap/test/swap_arrays.cpp index 6689db7..154ae30 100644 --- a/swap/test/swap_arrays.cpp +++ b/swap/test/swap_arrays.cpp @@ -11,6 +11,25 @@ //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: Effectice 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*[]) {