summaryrefslogtreecommitdiffstats
path: root/libcxx/test/std/algorithms/alg.modifying.operations/alg.swap
diff options
context:
space:
mode:
authorMarshall Clow <mclow.lists@gmail.com>2015-01-06 19:20:49 +0000
committerMarshall Clow <mclow.lists@gmail.com>2015-01-06 19:20:49 +0000
commitd632356aa311d4c5e3ac5edb30b3cbe51aa69f48 (patch)
tree1a6aee5addcb63c374a7f2a5930ffb42fb2571eb /libcxx/test/std/algorithms/alg.modifying.operations/alg.swap
parent8646421daae1d4668db6fc8c5d8b4c02906abd0f (diff)
downloadbcm5719-llvm-d632356aa311d4c5e3ac5edb30b3cbe51aa69f48.tar.gz
bcm5719-llvm-d632356aa311d4c5e3ac5edb30b3cbe51aa69f48.zip
Fix PR 22106; make std::swap work for multi-dimensional arrays. Thanks to Peter Griess for the report and suggested fix
llvm-svn: 225285
Diffstat (limited to 'libcxx/test/std/algorithms/alg.modifying.operations/alg.swap')
-rw-r--r--libcxx/test/std/algorithms/alg.modifying.operations/alg.swap/swap_ranges.pass.cpp49
1 files changed, 49 insertions, 0 deletions
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 24fc47eafc7..e12c69b4b62 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
@@ -62,6 +62,53 @@ test1()
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+void test2()
+{
+ {
+ int src[2][2] = {{0, 1}, {2, 3}};
+ decltype(src) dest = {{9, 8}, {7, 6}};
+
+ std::swap(src, dest);
+
+ assert ( src[0][0] == 9 );
+ assert ( src[0][1] == 8 );
+ assert ( src[1][0] == 7 );
+ assert ( src[1][1] == 6 );
+
+ assert ( dest[0][0] == 0 );
+ assert ( dest[0][1] == 1 );
+ assert ( dest[1][0] == 2 );
+ assert ( dest[1][1] == 3 );
+ }
+
+ {
+ int src[3][3] = {{0, 1, 2}, {3, 4, 5}, {6, 7, 8}};
+ decltype(src) dest = {{9, 8, 7}, {6, 5, 4}, {3, 2, 1}};
+
+ std::swap(src, dest);
+
+ assert ( src[0][0] == 9 );
+ assert ( src[0][1] == 8 );
+ assert ( src[0][2] == 7 );
+ assert ( src[1][0] == 6 );
+ assert ( src[1][1] == 5 );
+ assert ( src[1][2] == 4 );
+ assert ( src[2][0] == 3 );
+ assert ( src[2][1] == 2 );
+ assert ( src[2][2] == 1 );
+
+ assert ( dest[0][0] == 0 );
+ assert ( dest[0][1] == 1 );
+ assert ( dest[0][2] == 2 );
+ assert ( dest[1][0] == 3 );
+ assert ( dest[1][1] == 4 );
+ assert ( dest[1][2] == 5 );
+ assert ( dest[2][0] == 6 );
+ assert ( dest[2][1] == 7 );
+ assert ( dest[2][2] == 8 );
+ }
+}
+
int main()
{
test<forward_iterator<int*>, forward_iterator<int*> >();
@@ -107,4 +154,6 @@ int main()
test1<std::unique_ptr<int>*, std::unique_ptr<int>*>();
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
+ test2();
}
OpenPOWER on IntegriCloud