llvm-project
68 строк · 1.5 Кб
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// pair<iterator, bool> insert(const value_type& v);
14
15#include <set>
16#include <cassert>
17
18#include "test_macros.h"
19#include "min_allocator.h"
20
21template<class Container>
22void do_insert_cv_test()
23{
24typedef Container M;
25typedef std::pair<typename M::iterator, bool> R;
26typedef typename M::value_type VT;
27M m;
28
29const VT v1(2);
30R r = m.insert(v1);
31assert(r.second);
32assert(r.first == m.begin());
33assert(m.size() == 1);
34assert(*r.first == 2);
35
36const VT v2(1);
37r = m.insert(v2);
38assert(r.second);
39assert(r.first == m.begin());
40assert(m.size() == 2);
41assert(*r.first == 1);
42
43const VT v3(3);
44r = m.insert(v3);
45assert(r.second);
46assert(r.first == std::prev(m.end()));
47assert(m.size() == 3);
48assert(*r.first == 3);
49
50r = m.insert(v3);
51assert(!r.second);
52assert(r.first == std::prev(m.end()));
53assert(m.size() == 3);
54assert(*r.first == 3);
55}
56
57int main(int, char**)
58{
59do_insert_cv_test<std::set<int> >();
60#if TEST_STD_VER >= 11
61{
62typedef std::set<int, std::less<int>, min_allocator<int>> M;
63do_insert_cv_test<M>();
64}
65#endif
66
67return 0;
68}
69