1 // Copyright (c) 2008 Joseph Gauterin, Niels Dekker
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)
7 // Tests swapping std::vector objects by means of boost::swap,
8 // having other::swap_test_class as vector element type.
10 #include <boost/utility/swap.hpp>
11 #include <boost/core/lightweight_test.hpp>
12 #define BOOST_CHECK BOOST_TEST
13 #define BOOST_CHECK_EQUAL BOOST_TEST_EQ
17 //Put test class in namespace other
20 #include "./swap_test_class.hpp"
23 //Provide swap function in namespace other
26 void swap(swap_test_class
& left
, swap_test_class
& right
)
34 typedef other::swap_test_class swap_test_class_type
;
35 typedef std::vector
<swap_test_class_type
> vector_type
;
37 const vector_type::size_type initial_size1
= 1;
38 const vector_type::size_type initial_size2
= 2;
40 const vector_type
initial_value1(initial_size1
, swap_test_class_type(1));
41 const vector_type
initial_value2(initial_size2
, swap_test_class_type(2));
43 vector_type object1
= initial_value1
;
44 vector_type object2
= initial_value2
;
46 swap_test_class_type::reset();
48 boost::swap(object1
,object2
);
50 BOOST_CHECK_EQUAL(object1
.size(),initial_size2
);
51 BOOST_CHECK_EQUAL(object2
.size(),initial_size1
);
53 BOOST_CHECK(object1
== initial_value2
);
54 BOOST_CHECK(object2
== initial_value1
);
56 BOOST_CHECK_EQUAL(swap_test_class_type::swap_count(),0);
57 BOOST_CHECK_EQUAL(swap_test_class_type::copy_count(),0);
59 return boost::report_errors();