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<class T> |
| 13 | // requires MoveAssignable<T> && MoveConstructible<T> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 14 | // void |
| 15 | // swap(T& a, T& b); |
| 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 = 1; |
| 27 | int j = 2; |
| 28 | std::swap(i, j); |
| 29 | assert(i == 2); |
| 30 | assert(j == 1); |
| 31 | } |
| 32 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame^] | 33 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 34 | |
| 35 | void |
| 36 | test1() |
| 37 | { |
| 38 | std::unique_ptr<int> i(new int(1)); |
| 39 | std::unique_ptr<int> j(new int(2)); |
| 40 | std::swap(i, j); |
| 41 | assert(*i == 2); |
| 42 | assert(*j == 1); |
| 43 | } |
| 44 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame^] | 45 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 46 | |
| 47 | int main() |
| 48 | { |
| 49 | test(); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame^] | 50 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 51 | test1(); |
| 52 | #endif |
| 53 | } |