From 28e0187175ceeadae61d01fcedefa15f97f454f0 Mon Sep 17 00:00:00 2001 From: Zoe Carver Date: Fri, 5 Jul 2019 20:13:34 +0000 Subject: This patch makes swap functions constexpr. Both swap overloads, swap_ranges and iter_swap are updated (with tests). llvm-svn: 365238 --- .../alg.swap/iter_swap.pass.cpp | 14 ++++++++++++++ .../alg.swap/swap_ranges.pass.cpp | 19 +++++++++++++++++++ 2 files changed, 33 insertions(+) (limited to 'libcxx/test/std/algorithms/alg.modifying.operations') diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.swap/iter_swap.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.swap/iter_swap.pass.cpp index 2fbd905e5be..b3a9f5fc259 100644 --- a/libcxx/test/std/algorithms/alg.modifying.operations/alg.swap/iter_swap.pass.cpp +++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.swap/iter_swap.pass.cpp @@ -18,6 +18,16 @@ #include "test_macros.h" +#if TEST_STD_VER > 17 +constexpr bool test_swap_constexpr() +{ + int i = 1; + int j = 2; + std::iter_swap(&i, &j); + return i == 2 && j == 1; +} +#endif // TEST_STD_VER > 17 + int main(int, char**) { int i = 1; @@ -26,5 +36,9 @@ int main(int, char**) assert(i == 2); assert(j == 1); +#if TEST_STD_VER > 17 + static_assert(test_swap_constexpr()); +#endif // TEST_STD_VER > 17 + return 0; } diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.swap/swap_ranges.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.swap/swap_ranges.pass.cpp index a47bbd24d95..51671a060d6 100644 --- a/libcxx/test/std/algorithms/alg.modifying.operations/alg.swap/swap_ranges.pass.cpp +++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.swap/swap_ranges.pass.cpp @@ -105,6 +105,21 @@ void test2() } } +#if TEST_STD_VER > 17 +constexpr bool test_swap_constexpr() +{ + int i[3] = {1, 2, 3}; + int j[3] = {4, 5, 6}; + std::swap_ranges(i, i+3, j); + return i[0] == 4 && + i[1] == 5 && + i[2] == 6 && + j[0] == 1 && + j[1] == 2 && + j[2] == 3; +} +#endif // TEST_STD_VER > 17 + int main(int, char**) { test, forward_iterator >(); @@ -149,6 +164,10 @@ int main(int, char**) test1*, std::unique_ptr*>(); #endif // TEST_STD_VER >= 11 +#if TEST_STD_VER > 17 + static_assert(test_swap_constexpr()); +#endif // TEST_STD_VER > 17 + test2(); return 0; -- cgit v1.2.3