array_of_int.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  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. // Tests swapping an array of integers by means of boost::swap.
  7. #include <boost/utility/swap.hpp>
  8. #include <boost/core/lightweight_test.hpp>
  9. #define BOOST_CHECK BOOST_TEST
  10. #define BOOST_CHECK_EQUAL BOOST_TEST_EQ
  11. #include <algorithm> //for std::copy and std::equal
  12. #include <cstddef> //for std::size_t
  13. int main()
  14. {
  15. const std::size_t array_size = 3;
  16. const int initial_array1[array_size] = { 1, 2, 3 };
  17. const int initial_array2[array_size] = { 4, 5, 6 };
  18. int array1[array_size];
  19. int array2[array_size];
  20. std::copy(initial_array1, initial_array1 + array_size, array1);
  21. std::copy(initial_array2, initial_array2 + array_size, array2);
  22. boost::swap(array1, array2);
  23. BOOST_CHECK(std::equal(array1, array1 + array_size, initial_array2));
  24. BOOST_CHECK(std::equal(array2, array2 + array_size, initial_array1));
  25. return boost::report_errors();
  26. }