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 --- .../std/utilities/utility/utility.swap/swap.pass.cpp | 14 ++++++++++++++ .../utilities/utility/utility.swap/swap_array.pass.cpp | 18 ++++++++++++++++++ 2 files changed, 32 insertions(+) (limited to 'libcxx/test/std/utilities') diff --git a/libcxx/test/std/utilities/utility/utility.swap/swap.pass.cpp b/libcxx/test/std/utilities/utility/utility.swap/swap.pass.cpp index f52af4cb896..c9146ee7637 100644 --- a/libcxx/test/std/utilities/utility/utility.swap/swap.pass.cpp +++ b/libcxx/test/std/utilities/utility/utility.swap/swap.pass.cpp @@ -62,6 +62,16 @@ constexpr bool can_swap() { } #endif +#if TEST_STD_VER > 17 +constexpr bool test_swap_constexpr() +{ + int i = 1; + int j = 2; + std::swap(i, j); + return i == 2 && j == 1; +} +#endif // TEST_STD_VER > 17 + int main(int, char**) { @@ -100,5 +110,9 @@ int main(int, char**) } #endif +#if TEST_STD_VER > 17 + static_assert(test_swap_constexpr()); +#endif // TEST_STD_VER > 17 + return 0; } diff --git a/libcxx/test/std/utilities/utility/utility.swap/swap_array.pass.cpp b/libcxx/test/std/utilities/utility/utility.swap/swap_array.pass.cpp index 015e85a0135..512505b78f0 100644 --- a/libcxx/test/std/utilities/utility/utility.swap/swap_array.pass.cpp +++ b/libcxx/test/std/utilities/utility/utility.swap/swap_array.pass.cpp @@ -53,6 +53,20 @@ constexpr bool can_swap() { } #endif +#if TEST_STD_VER > 17 +constexpr bool test_swap_constexpr() +{ + int i[3] = {1, 2, 3}; + int j[3] = {4, 5, 6}; + std::swap(i, 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**) { @@ -98,5 +112,9 @@ int main(int, char**) } #endif +#if TEST_STD_VER > 17 + static_assert(test_swap_constexpr()); +#endif // TEST_STD_VER > 17 + return 0; } -- cgit v1.2.3