]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/core/test/swap/std_vector_of_other.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / core / test / swap / std_vector_of_other.cpp
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 // Tests swapping std::vector objects by means of boost::swap,
8 // having other::swap_test_class as vector element type.
9
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
14
15 #include <vector>
16
17 //Put test class in namespace other
18 namespace other
19 {
20 #include "./swap_test_class.hpp"
21 }
22
23 //Provide swap function in namespace other
24 namespace other
25 {
26 void swap(swap_test_class& left, swap_test_class& right)
27 {
28 left.swap(right);
29 }
30 }
31
32 int main()
33 {
34 typedef other::swap_test_class swap_test_class_type;
35 typedef std::vector<swap_test_class_type> vector_type;
36
37 const vector_type::size_type initial_size1 = 1;
38 const vector_type::size_type initial_size2 = 2;
39
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));
42
43 vector_type object1 = initial_value1;
44 vector_type object2 = initial_value2;
45
46 swap_test_class_type::reset();
47
48 boost::swap(object1,object2);
49
50 BOOST_CHECK_EQUAL(object1.size(),initial_size2);
51 BOOST_CHECK_EQUAL(object2.size(),initial_size1);
52
53 BOOST_CHECK(object1 == initial_value2);
54 BOOST_CHECK(object2 == initial_value1);
55
56 BOOST_CHECK_EQUAL(swap_test_class_type::swap_count(),0);
57 BOOST_CHECK_EQUAL(swap_test_class_type::copy_count(),0);
58
59 return boost::report_errors();
60 }
61