1//===----------------------------------------------------------------------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is dual licensed under the MIT and the University of Illinois Open 6// Source Licenses. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9 10// <utility> 11 12// template<class T> 13// requires MoveAssignable<T> && MoveConstructible<T> 14// void 15// swap(T& a, T& b); 16 17#include <utility> 18#include <cassert> 19#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 20#include <memory> 21#endif 22 23void 24test() 25{ 26 int i = 1; 27 int j = 2; 28 std::swap(i, j); 29 assert(i == 2); 30 assert(j == 1); 31} 32 33#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 34 35void 36test1() 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 45#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 46 47int main() 48{ 49 test(); 50#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 51 test1(); 52#endif 53} 54