xref: /llvm-project/libcxx/test/std/algorithms/alg.modifying.operations/alg.swap/iter_swap.pass.cpp (revision 28e0187175ceeadae61d01fcedefa15f97f454f0)
15a83710eSEric Fiselier //===----------------------------------------------------------------------===//
25a83710eSEric Fiselier //
357b08b09SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
457b08b09SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
557b08b09SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
65a83710eSEric Fiselier //
75a83710eSEric Fiselier //===----------------------------------------------------------------------===//
85a83710eSEric Fiselier 
95a83710eSEric Fiselier // <algorithm>
105a83710eSEric Fiselier 
115a83710eSEric Fiselier // template<Iterator Iter1, Iterator Iter2>
125a83710eSEric Fiselier //   requires HasSwap<Iter1::reference, Iter2::reference>
135a83710eSEric Fiselier //   void
145a83710eSEric Fiselier //   iter_swap(Iter1 a, Iter2 b);
155a83710eSEric Fiselier 
165a83710eSEric Fiselier #include <algorithm>
175a83710eSEric Fiselier #include <cassert>
185a83710eSEric Fiselier 
197fc6a556SMarshall Clow #include "test_macros.h"
207fc6a556SMarshall Clow 
21*28e01871SZoe Carver #if TEST_STD_VER > 17
test_swap_constexpr()22*28e01871SZoe Carver constexpr bool test_swap_constexpr()
23*28e01871SZoe Carver {
24*28e01871SZoe Carver     int i = 1;
25*28e01871SZoe Carver     int j = 2;
26*28e01871SZoe Carver     std::iter_swap(&i, &j);
27*28e01871SZoe Carver     return i == 2 && j == 1;
28*28e01871SZoe Carver }
29*28e01871SZoe Carver #endif // TEST_STD_VER > 17
30*28e01871SZoe Carver 
main(int,char **)312df59c50SJF Bastien int main(int, char**)
325a83710eSEric Fiselier {
335a83710eSEric Fiselier     int i = 1;
345a83710eSEric Fiselier     int j = 2;
355a83710eSEric Fiselier     std::iter_swap(&i, &j);
365a83710eSEric Fiselier     assert(i == 2);
375a83710eSEric Fiselier     assert(j == 1);
382df59c50SJF Bastien 
39*28e01871SZoe Carver #if TEST_STD_VER > 17
40*28e01871SZoe Carver     static_assert(test_swap_constexpr());
41*28e01871SZoe Carver #endif // TEST_STD_VER > 17
42*28e01871SZoe Carver 
432df59c50SJF Bastien   return 0;
445a83710eSEric Fiselier }
45