[libcxx] r225285 - Fix PR 22106; make std::swap work for multi-dimensional arrays. Thanks to Peter Griess for the report and suggested fix
Marshall Clow
mclow.lists at gmail.com
Tue Jan 6 11:20:49 PST 2015
Author: marshall
Date: Tue Jan 6 13:20:49 2015
New Revision: 225285
URL: http://llvm.org/viewvc/llvm-project?rev=225285&view=rev
Log:
Fix PR 22106; make std::swap work for multi-dimensional arrays. Thanks to Peter Griess for the report and suggested fix
Modified:
libcxx/trunk/include/utility
libcxx/trunk/test/std/algorithms/alg.modifying.operations/alg.swap/swap_ranges.pass.cpp
Modified: libcxx/trunk/include/utility
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/utility?rev=225285&r1=225284&r2=225285&view=diff
==============================================================================
--- libcxx/trunk/include/utility (original)
+++ libcxx/trunk/include/utility Tue Jan 6 13:20:49 2015
@@ -202,6 +202,10 @@ operator>=(const _Tp& __x, const _Tp& __
// swap_ranges
+// forward
+template<class _Tp, size_t _Np>
+void swap(_Tp (&__a)[_Np], _Tp (&__b)[_Np]) _NOEXCEPT_(__is_nothrow_swappable<_Tp>::value);
+
template <class _ForwardIterator1, class _ForwardIterator2>
inline _LIBCPP_INLINE_VISIBILITY
_ForwardIterator2
Modified: libcxx/trunk/test/std/algorithms/alg.modifying.operations/alg.swap/swap_ranges.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/algorithms/alg.modifying.operations/alg.swap/swap_ranges.pass.cpp?rev=225285&r1=225284&r2=225285&view=diff
==============================================================================
--- libcxx/trunk/test/std/algorithms/alg.modifying.operations/alg.swap/swap_ranges.pass.cpp (original)
+++ libcxx/trunk/test/std/algorithms/alg.modifying.operations/alg.swap/swap_ranges.pass.cpp Tue Jan 6 13:20:49 2015
@@ -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();
}
More information about the cfe-commits
mailing list