llvm-project/libcxx/test/std/containers/associative/set/set.cons/move.pass.cpp

108 lines
2.9 KiB
C++
Raw Normal View History

2010-05-12 03:42:16 +08:00
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
2010-05-12 03:42:16 +08:00
//
2010-11-17 06:09:02 +08:00
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
2010-05-12 03:42:16 +08:00
//
//===----------------------------------------------------------------------===//
// <set>
// class set
// set(set&& s);
#include <set>
#include <cassert>
#include "../../../test_compare.h"
#include "test_allocator.h"
#include "min_allocator.h"
2010-05-12 03:42:16 +08:00
int main()
{
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2010-05-12 03:42:16 +08:00
{
typedef int V;
typedef test_compare<std::less<int> > C;
typedef test_allocator<V> A;
std::set<int, C, A> mo(C(5), A(7));
std::set<int, C, A> m = std::move(mo);
assert(m.get_allocator() == A(7));
assert(m.key_comp() == C(5));
assert(m.size() == 0);
assert(distance(m.begin(), m.end()) == 0);
2010-05-12 03:42:16 +08:00
assert(mo.get_allocator() == A(7));
assert(mo.key_comp() == C(5));
assert(mo.size() == 0);
assert(distance(mo.begin(), mo.end()) == 0);
}
{
typedef int V;
V ar[] =
{
1,
1,
1,
2,
2,
2,
3,
3,
3
};
typedef test_compare<std::less<int> > C;
typedef test_allocator<V> A;
std::set<int, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A(7));
std::set<int, C, A> m = std::move(mo);
assert(m.get_allocator() == A(7));
assert(m.key_comp() == C(5));
assert(m.size() == 3);
assert(distance(m.begin(), m.end()) == 3);
assert(*m.begin() == 1);
assert(*next(m.begin()) == 2);
assert(*next(m.begin(), 2) == 3);
2010-05-12 03:42:16 +08:00
assert(mo.get_allocator() == A(7));
assert(mo.key_comp() == C(5));
assert(mo.size() == 0);
assert(distance(mo.begin(), mo.end()) == 0);
}
#if TEST_STD_VER >= 11
{
typedef int V;
V ar[] =
{
1,
1,
1,
2,
2,
2,
3,
3,
3
};
typedef test_compare<std::less<int> > C;
typedef min_allocator<V> A;
std::set<int, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A());
std::set<int, C, A> m = std::move(mo);
assert(m.get_allocator() == A());
assert(m.key_comp() == C(5));
assert(m.size() == 3);
assert(distance(m.begin(), m.end()) == 3);
assert(*m.begin() == 1);
assert(*next(m.begin()) == 2);
assert(*next(m.begin(), 2) == 3);
assert(mo.get_allocator() == A());
assert(mo.key_comp() == C(5));
assert(mo.size() == 0);
assert(distance(mo.begin(), mo.end()) == 0);
}
#endif
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2010-05-12 03:42:16 +08:00
}