Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / containers / associative / map / map.modifiers / insert_cv.pass.cpp
bloba2436440f194725739fe0f46b48994b862b1e2a4
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 //===----------------------------------------------------------------------===//
9 // <map>
11 // class map
13 // pair<iterator, bool> insert(const value_type& v);
15 #include <map>
16 #include <cassert>
18 #include "test_macros.h"
19 #include "min_allocator.h"
21 template <class Container>
22 void do_insert_cv_test()
24 typedef Container M;
25 typedef std::pair<typename M::iterator, bool> R;
26 typedef typename M::value_type VT;
27 M m;
29 const VT v1(2, 2.5);
30 R r = m.insert(v1);
31 assert(r.second);
32 assert(r.first == m.begin());
33 assert(m.size() == 1);
34 assert(r.first->first == 2);
35 assert(r.first->second == 2.5);
37 const VT v2(1, 1.5);
38 r = m.insert(v2);
39 assert(r.second);
40 assert(r.first == m.begin());
41 assert(m.size() == 2);
42 assert(r.first->first == 1);
43 assert(r.first->second == 1.5);
45 const VT v3(3, 3.5);
46 r = m.insert(v3);
47 assert(r.second);
48 assert(r.first == std::prev(m.end()));
49 assert(m.size() == 3);
50 assert(r.first->first == 3);
51 assert(r.first->second == 3.5);
53 const VT v4(3, 4.5);
54 r = m.insert(v4);
55 assert(!r.second);
56 assert(r.first == std::prev(m.end()));
57 assert(m.size() == 3);
58 assert(r.first->first == 3);
59 assert(r.first->second == 3.5);
62 int main(int, char**)
64 do_insert_cv_test<std::map<int, double> >();
65 #if TEST_STD_VER >= 11
67 typedef std::map<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M;
68 do_insert_cv_test<M>();
70 #endif
72 return 0;