You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
libcxx_old/test/std/containers/associative/set/set.special/member_swap.pass.cpp

180 lines
3.3 KiB
C++

//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <set>
// class set
// void swap(set& m);
#include <set>
#include <cassert>
#include "test_macros.h"
#include "min_allocator.h"
int main(int, char**)
{
{
typedef int V;
typedef std::set<int> M;
{
M m1;
M m2;
M m1_save = m1;
M m2_save = m2;
m1.swap(m2);
assert(m1 == m2_save);
assert(m2 == m1_save);
}
{
V ar2[] =
{
5,
6,
7,
8,
9,
10,
11,
12
};
M m1;
M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0]));
M m1_save = m1;
M m2_save = m2;
m1.swap(m2);
assert(m1 == m2_save);
assert(m2 == m1_save);
}
{
V ar1[] =
{
1,
2,
3,
4
};
M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0]));
M m2;
M m1_save = m1;
M m2_save = m2;
m1.swap(m2);
assert(m1 == m2_save);
assert(m2 == m1_save);
}
{
V ar1[] =
{
1,
2,
3,
4
};
V ar2[] =
{
5,
6,
7,
8,
9,
10,
11,
12
};
M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0]));
M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0]));
M m1_save = m1;
M m2_save = m2;
m1.swap(m2);
assert(m1 == m2_save);
assert(m2 == m1_save);
}
}
#if TEST_STD_VER >= 11
{
typedef int V;
typedef std::set<int, std::less<int>, min_allocator<int>> M;
{
M m1;
M m2;
M m1_save = m1;
M m2_save = m2;
m1.swap(m2);
assert(m1 == m2_save);
assert(m2 == m1_save);
}
{
V ar2[] =
{
5,
6,
7,
8,
9,
10,
11,
12
};
M m1;
M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0]));
M m1_save = m1;
M m2_save = m2;
m1.swap(m2);
assert(m1 == m2_save);
assert(m2 == m1_save);
}
{
V ar1[] =
{
1,
2,
3,
4
};
M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0]));
M m2;
M m1_save = m1;
M m2_save = m2;
m1.swap(m2);
assert(m1 == m2_save);
assert(m2 == m1_save);
}
{
V ar1[] =
{
1,
2,
3,
4
};
V ar2[] =
{
5,
6,
7,
8,
9,
10,
11,
12
};
M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0]));
M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0]));
M m1_save = m1;
M m2_save = m2;
m1.swap(m2);
assert(m1 == m2_save);
assert(m2 == m1_save);
}
}
#endif
return 0;
}