• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2008 Joseph Gauterin, Niels Dekker
2 //
3 // Distributed under the Boost Software License, Version 1.0.
4 // (See accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
6 
7 // boost::swap internally does an unqualified function call to swap.
8 // This could have led to ambiguity or infinite recursion, when the
9 // objects to be swapped would themselves be from the boost namespace.
10 // If so, boost::swap itself might be found by argument dependent lookup.
11 // The implementation of boost::swap resolves this issue by giving
12 // boost::swap two template argumetns, thereby making it less specialized
13 // than std::swap.
14 
15 #include <boost/utility/swap.hpp>
16 #include <boost/core/lightweight_test.hpp>
17 #define BOOST_CHECK BOOST_TEST
18 #define BOOST_CHECK_EQUAL BOOST_TEST_EQ
19 
20 //Put test class in namespace boost
21 namespace boost
22 {
23   #include "./swap_test_class.hpp"
24 }
25 
26 
main()27 int main()
28 {
29   const boost::swap_test_class initial_value1(1);
30   const boost::swap_test_class initial_value2(2);
31 
32   boost::swap_test_class object1 = initial_value1;
33   boost::swap_test_class object2 = initial_value2;
34 
35   boost::swap_test_class::reset();
36   boost::swap(object1,object2);
37 
38   BOOST_CHECK(object1 == initial_value2);
39   BOOST_CHECK(object2 == initial_value1);
40   BOOST_CHECK_EQUAL(boost::swap_test_class::swap_count(),0);
41   BOOST_CHECK_EQUAL(boost::swap_test_class::copy_count(),3);
42 
43   return boost::report_errors();
44 }
45 
46