//===----------------------------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // template // requires HasSwap // Iter2 // swap_ranges(Iter1 first1, Iter1 last1, Iter2 first2); #include #include #include #include #include #include #include "test_macros.h" #include "test_iterators.h" #include "type_algorithms.h" struct TestPtr { template TEST_CONSTEXPR_CXX20 void operator()() { types::for_each(types::forward_iterator_list(), TestImpl()); } template struct TestImpl { template TEST_CONSTEXPR_CXX20 void operator()() { int a[] = {1, 2, 3}; int b[] = {4, 5, 6}; Iter2 r = std::swap_ranges(Iter1(a), Iter1(a + 3), Iter2(b)); assert(base(r) == b + 3); assert(a[0] == 4 && a[1] == 5 && a[2] == 6); assert(b[0] == 1 && b[1] == 2 && b[2] == 3); } }; }; #if TEST_STD_VER >= 11 struct TestUniquePtr { template TEST_CONSTEXPR_CXX23 void operator()() { types::for_each(types::forward_iterator_list*>(), TestImpl()); } template struct TestImpl { template TEST_CONSTEXPR_CXX23 void operator()() { std::unique_ptr a[3]; for (int k = 0; k < 3; ++k) a[k].reset(new int(k + 1)); std::unique_ptr b[3]; for (int k = 0; k < 3; ++k) b[k].reset(new int(k + 4)); Iter2 r = std::swap_ranges(Iter1(a), Iter1(a + 3), Iter2(b)); assert(base(r) == b + 3); assert(*a[0] == 4 && *a[1] == 5 && *a[2] == 6); assert(*b[0] == 1 && *b[1] == 2 && *b[2] == 3); } }; }; #endif template