summaryrefslogtreecommitdiffstats
path: root/libcxx/test/std/containers/sequences/array/array.special/swap.pass.cpp
diff options
context:
space:
mode:
authorEric Fiselier <eric@efcs.ca>2016-04-21 23:38:59 +0000
committerEric Fiselier <eric@efcs.ca>2016-04-21 23:38:59 +0000
commitf07dd8d0a925dd8cbde7bb6198c1ba92446110ea (patch)
tree581032748ea2b3640d2e7f033f2e651eb67416bd /libcxx/test/std/containers/sequences/array/array.special/swap.pass.cpp
parentc89755e4cbad7a46d747f3b2d49c50a80855a801 (diff)
downloadbcm5719-llvm-f07dd8d0a925dd8cbde7bb6198c1ba92446110ea.tar.gz
bcm5719-llvm-f07dd8d0a925dd8cbde7bb6198c1ba92446110ea.zip
Add is_swappable/is_nothrow_swappable traits
llvm-svn: 267079
Diffstat (limited to 'libcxx/test/std/containers/sequences/array/array.special/swap.pass.cpp')
-rw-r--r--libcxx/test/std/containers/sequences/array/array.special/swap.pass.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/libcxx/test/std/containers/sequences/array/array.special/swap.pass.cpp b/libcxx/test/std/containers/sequences/array/array.special/swap.pass.cpp
index c1b0b235ab3..d8532d7ba7f 100644
--- a/libcxx/test/std/containers/sequences/array/array.special/swap.pass.cpp
+++ b/libcxx/test/std/containers/sequences/array/array.special/swap.pass.cpp
@@ -14,10 +14,28 @@
#include <array>
#include <cassert>
+#include "test_macros.h"
// std::array is explicitly allowed to be initialized with A a = { init-list };.
// Disable the missing braces warning for this reason.
#include "disable_missing_braces_warning.h"
+struct NonSwappable {
+ NonSwappable() {}
+private:
+ NonSwappable(NonSwappable const&);
+ NonSwappable& operator=(NonSwappable const&);
+};
+
+template <class Tp>
+decltype(swap(std::declval<Tp>(), std::declval<Tp>()))
+can_swap_imp(int);
+
+template <class Tp>
+std::false_type can_swap_imp(...);
+
+template <class Tp>
+struct can_swap : std::is_same<decltype(can_swap_imp<Tp>(0)), void> {};
+
int main()
{
{
@@ -44,4 +62,17 @@ int main()
assert(c1.size() == 0);
assert(c2.size() == 0);
}
+ {
+ typedef NonSwappable T;
+ typedef std::array<T, 42> C1;
+ typedef std::array<T, 0> C0;
+ static_assert(!can_swap<C1&>::value, "");
+ static_assert(can_swap<C0&>::value, "");
+ C0 l = {};
+ C0 r = {};
+ swap(l, r);
+#if TEST_STD_VER >= 11
+ static_assert(noexcept(swap(l, r)), "");
+#endif
+ }
}
OpenPOWER on IntegriCloud