llvm-project
111 строк · 2.9 Кб
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9// <set>
10
11// class set
12
13// set& operator=(const set& s);
14
15#include <set>
16#include <cassert>
17
18#include "test_macros.h"
19#include "../../../test_compare.h"
20#include "test_allocator.h"
21
22int main(int, char**)
23{
24{
25typedef int V;
26V ar[] =
27{
281,
291,
301,
312,
322,
332,
343,
353,
363
37};
38typedef test_less<int> C;
39typedef test_allocator<V> A;
40std::set<int, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A(2));
41std::set<int, C, A> m(ar, ar+sizeof(ar)/sizeof(ar[0])/2, C(3), A(7));
42m = mo;
43assert(m.get_allocator() == A(7));
44assert(m.key_comp() == C(5));
45assert(m.size() == 3);
46assert(std::distance(m.begin(), m.end()) == 3);
47assert(*m.begin() == 1);
48assert(*std::next(m.begin()) == 2);
49assert(*std::next(m.begin(), 2) == 3);
50
51assert(mo.get_allocator() == A(2));
52assert(mo.key_comp() == C(5));
53assert(mo.size() == 3);
54assert(std::distance(mo.begin(), mo.end()) == 3);
55assert(*mo.begin() == 1);
56assert(*std::next(mo.begin()) == 2);
57assert(*std::next(mo.begin(), 2) == 3);
58}
59{
60typedef int V;
61const V ar[] =
62{
631,
642,
653
66};
67std::set<int> m(ar, ar+sizeof(ar)/sizeof(ar[0]));
68std::set<int> *p = &m;
69m = *p;
70
71assert(m.size() == 3);
72assert(std::equal(m.begin(), m.end(), ar));
73}
74{
75typedef int V;
76V ar[] =
77{
781,
791,
801,
812,
822,
832,
843,
853,
863
87};
88typedef test_less<int> C;
89typedef other_allocator<V> A;
90std::set<int, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A(2));
91std::set<int, C, A> m(ar, ar+sizeof(ar)/sizeof(ar[0])/2, C(3), A(7));
92m = mo;
93assert(m.get_allocator() == A(2));
94assert(m.key_comp() == C(5));
95assert(m.size() == 3);
96assert(std::distance(m.begin(), m.end()) == 3);
97assert(*m.begin() == 1);
98assert(*std::next(m.begin()) == 2);
99assert(*std::next(m.begin(), 2) == 3);
100
101assert(mo.get_allocator() == A(2));
102assert(mo.key_comp() == C(5));
103assert(mo.size() == 3);
104assert(std::distance(mo.begin(), mo.end()) == 3);
105assert(*mo.begin() == 1);
106assert(*std::next(mo.begin()) == 2);
107assert(*std::next(mo.begin(), 2) == 3);
108}
109
110return 0;
111}
112