]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/core/test/swap/array_of_array_of_int.cpp
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 an array of arrays of integers by means of boost::swap.
9 #include <boost/utility/swap.hpp>
10 #include <boost/core/lightweight_test.hpp>
11 #define BOOST_CHECK BOOST_TEST
12 #define BOOST_CHECK_EQUAL BOOST_TEST_EQ
14 #include <algorithm> //for std::copy and std::equal
15 #include <cstddef> //for std::size_t
19 const std::size_t first_dimension
= 3;
20 const std::size_t second_dimension
= 4;
21 const std::size_t number_of_elements
= first_dimension
* second_dimension
;
23 int array1
[first_dimension
][second_dimension
];
24 int array2
[first_dimension
][second_dimension
];
26 int* const ptr1
= array1
[0];
27 int* const ptr2
= array2
[0];
29 for (std::size_t i
= 0; i
< number_of_elements
; ++i
)
31 ptr1
[i
] = static_cast<int>(i
);
32 ptr2
[i
] = static_cast<int>(i
+ number_of_elements
);
35 boost::swap(array1
, array2
);
37 for (std::size_t i
= 0; i
< number_of_elements
; ++i
)
39 BOOST_CHECK_EQUAL(ptr1
[i
], static_cast<int>(i
+ number_of_elements
) );
40 BOOST_CHECK_EQUAL(ptr2
[i
], static_cast<int>(i
) );
43 return boost::report_errors();