2010-05-11 21:42:16 +02:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2010-05-11 23:36:01 +02:00
|
|
|
// The LLVM Compiler Infrastructure
|
2010-05-11 21:42:16 +02:00
|
|
|
//
|
2010-11-16 23:09:02 +01:00
|
|
|
// This file is dual licensed under the MIT and the University of Illinois Open
|
|
|
|
// Source Licenses. See LICENSE.TXT for details.
|
2010-05-11 21:42:16 +02:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
// test move
|
|
|
|
|
|
|
|
#include <utility>
|
|
|
|
#include <cassert>
|
|
|
|
|
|
|
|
int copy_ctor = 0;
|
|
|
|
int move_ctor = 0;
|
|
|
|
|
|
|
|
class A
|
|
|
|
{
|
2010-09-05 01:28:19 +02:00
|
|
|
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2010-05-11 21:42:16 +02:00
|
|
|
#else
|
|
|
|
#endif
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2010-09-05 01:28:19 +02:00
|
|
|
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2010-05-11 21:42:16 +02:00
|
|
|
A(const A&) {++copy_ctor;}
|
|
|
|
A& operator=(const A&);
|
|
|
|
|
|
|
|
A(A&&) {++move_ctor;}
|
|
|
|
A& operator=(A&&);
|
2010-09-05 01:28:19 +02:00
|
|
|
#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2010-05-11 21:42:16 +02:00
|
|
|
A(const A&) {++copy_ctor;}
|
|
|
|
A& operator=(A&);
|
|
|
|
|
|
|
|
operator std::__rv<A> () {return std::__rv<A>(*this);}
|
|
|
|
A(std::__rv<A>) {++move_ctor;}
|
2010-09-05 01:28:19 +02:00
|
|
|
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2010-05-11 21:42:16 +02:00
|
|
|
|
|
|
|
A() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
A source() {return A();}
|
|
|
|
const A csource() {return A();}
|
|
|
|
|
|
|
|
void test(A) {}
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
A a;
|
|
|
|
const A ca = A();
|
|
|
|
|
|
|
|
assert(copy_ctor == 0);
|
|
|
|
assert(move_ctor == 0);
|
|
|
|
|
|
|
|
A a2 = a;
|
|
|
|
assert(copy_ctor == 1);
|
|
|
|
assert(move_ctor == 0);
|
|
|
|
|
|
|
|
A a3 = std::move(a);
|
|
|
|
assert(copy_ctor == 1);
|
|
|
|
assert(move_ctor == 1);
|
|
|
|
|
|
|
|
A a4 = ca;
|
|
|
|
assert(copy_ctor == 2);
|
|
|
|
assert(move_ctor == 1);
|
|
|
|
|
|
|
|
A a5 = std::move(ca);
|
|
|
|
assert(copy_ctor == 3);
|
|
|
|
assert(move_ctor == 1);
|
|
|
|
}
|