Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
Howard Hinnant | f5256e1 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | // <utility> |
| 11 | |
Howard Hinnant | c52f43e | 2010-08-22 00:59:46 +0000 | [diff] [blame] | 12 | // template<ValueType T, size_t N> |
| 13 | // requires Swappable<T> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 14 | // void |
| 15 | // swap(T (&a)[N], T (&b)[N]); |
| 16 | |
| 17 | #include <utility> |
| 18 | #include <cassert> |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame^] | 19 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 20 | #include <memory> |
| 21 | #endif |
| 22 | |
| 23 | void |
| 24 | test() |
| 25 | { |
| 26 | int i[3] = {1, 2, 3}; |
| 27 | int j[3] = {4, 5, 6}; |
| 28 | std::swap(i, j); |
| 29 | assert(i[0] == 4); |
| 30 | assert(i[1] == 5); |
| 31 | assert(i[2] == 6); |
| 32 | assert(j[0] == 1); |
| 33 | assert(j[1] == 2); |
| 34 | assert(j[2] == 3); |
| 35 | } |
| 36 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame^] | 37 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 38 | |
| 39 | void |
| 40 | test1() |
| 41 | { |
| 42 | std::unique_ptr<int> i[3]; |
| 43 | for (int k = 0; k < 3; ++k) |
| 44 | i[k].reset(new int(k+1)); |
| 45 | std::unique_ptr<int> j[3]; |
| 46 | for (int k = 0; k < 3; ++k) |
| 47 | j[k].reset(new int(k+4)); |
| 48 | std::swap(i, j); |
| 49 | assert(*i[0] == 4); |
| 50 | assert(*i[1] == 5); |
| 51 | assert(*i[2] == 6); |
| 52 | assert(*j[0] == 1); |
| 53 | assert(*j[1] == 2); |
| 54 | assert(*j[2] == 3); |
| 55 | } |
| 56 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame^] | 57 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 58 | |
| 59 | int main() |
| 60 | { |
| 61 | test(); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame^] | 62 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 63 | test1(); |
| 64 | #endif |
| 65 | } |