| 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 an array of integers by means of boost::core::invoke_swap. |
| 8 | |
| 9 | #include <boost/core/invoke_swap.hpp> |
| 10 | #include <boost/core/lightweight_test.hpp> |
| 11 | #define BOOST_CHECK BOOST_TEST |
| 12 | #define BOOST_CHECK_EQUAL BOOST_TEST_EQ |
| 13 | |
| 14 | #include <algorithm> //for std::copy and std::equal |
| 15 | #include <cstddef> //for std::size_t |
| 16 | |
| 17 | |
| 18 | int main() |
| 19 | { |
| 20 | const std::size_t array_size = 3; |
| 21 | const int initial_array1[array_size] = { 1, 2, 3 }; |
| 22 | const int initial_array2[array_size] = { 4, 5, 6 }; |
| 23 | |
| 24 | int array1[array_size]; |
| 25 | int array2[array_size]; |
| 26 | |
| 27 | std::copy(first: initial_array1, last: initial_array1 + array_size, result: array1); |
| 28 | std::copy(first: initial_array2, last: initial_array2 + array_size, result: array2); |
| 29 | |
| 30 | boost::core::invoke_swap(left&: array1, right&: array2); |
| 31 | |
| 32 | BOOST_CHECK(std::equal(array1, array1 + array_size, initial_array2)); |
| 33 | BOOST_CHECK(std::equal(array2, array2 + array_size, initial_array1)); |
| 34 | |
| 35 | return boost::report_errors(); |
| 36 | } |
| 37 | |