llvm-project
73 строки · 1.8 Кб
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// <map>
10
11// class map
12
13// pair<iterator, bool> insert(const value_type& v);
14
15#include <map>
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, 2.5);
30R r = m.insert(v1);
31assert(r.second);
32assert(r.first == m.begin());
33assert(m.size() == 1);
34assert(r.first->first == 2);
35assert(r.first->second == 2.5);
36
37const VT v2(1, 1.5);
38r = m.insert(v2);
39assert(r.second);
40assert(r.first == m.begin());
41assert(m.size() == 2);
42assert(r.first->first == 1);
43assert(r.first->second == 1.5);
44
45const VT v3(3, 3.5);
46r = m.insert(v3);
47assert(r.second);
48assert(r.first == std::prev(m.end()));
49assert(m.size() == 3);
50assert(r.first->first == 3);
51assert(r.first->second == 3.5);
52
53const VT v4(3, 4.5);
54r = m.insert(v4);
55assert(!r.second);
56assert(r.first == std::prev(m.end()));
57assert(m.size() == 3);
58assert(r.first->first == 3);
59assert(r.first->second == 3.5);
60}
61
62int main(int, char**)
63{
64do_insert_cv_test<std::map<int, double> >();
65#if TEST_STD_VER >= 11
66{
67typedef std::map<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M;
68do_insert_cv_test<M>();
69}
70#endif
71
72return 0;
73}
74