blob: a9d3277e6d94778c75c196056a03b9badb6e6faa [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001//===----------------------------------------------------------------------===//
2//
Howard Hinnantf5256e12010-05-11 21:36:01 +00003// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00005// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00007//
8//===----------------------------------------------------------------------===//
9
10// <map>
11
12// class map
13
14// template <class P>
15// pair<iterator, bool> insert(P&& p);
16
17#include <map>
18#include <cassert>
19
Marshall Clowdf00d5e2015-01-28 21:22:53 +000020#include "MoveOnly.h"
Marshall Clow061d0cc2013-11-26 20:58:02 +000021#include "min_allocator.h"
Eric Fiselier91a15652016-04-18 01:40:45 +000022
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000023int main()
24{
Dan Albert1d4a1ed2016-05-25 22:36:09 -070025#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Marshall Clow3426a862016-01-05 19:32:41 +000026 {
27 typedef std::map<int, MoveOnly> M;
28 typedef std::pair<M::iterator, bool> R;
29 M m;
Dan Albert1d4a1ed2016-05-25 22:36:09 -070030 R r = m.insert(M::value_type(2, 2));
Marshall Clow3426a862016-01-05 19:32:41 +000031 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);
36
Dan Albert1d4a1ed2016-05-25 22:36:09 -070037 r = m.insert(M::value_type(1, 1));
Marshall Clow3426a862016-01-05 19:32:41 +000038 assert(r.second);
39 assert(r.first == m.begin());
40 assert(m.size() == 2);
41 assert(r.first->first == 1);
42 assert(r.first->second == 1);
43
Dan Albert1d4a1ed2016-05-25 22:36:09 -070044 r = m.insert(M::value_type(3, 3));
Marshall Clow3426a862016-01-05 19:32:41 +000045 assert(r.second);
46 assert(r.first == prev(m.end()));
47 assert(m.size() == 3);
48 assert(r.first->first == 3);
49 assert(r.first->second == 3);
50
Dan Albert1d4a1ed2016-05-25 22:36:09 -070051 r = m.insert(M::value_type(3, 3));
Marshall Clow3426a862016-01-05 19:32:41 +000052 assert(!r.second);
53 assert(r.first == prev(m.end()));
54 assert(m.size() == 3);
55 assert(r.first->first == 3);
56 assert(r.first->second == 3);
57 }
Dan Albert1d4a1ed2016-05-25 22:36:09 -070058#if __cplusplus >= 201103L
59 {
60 typedef std::map<int, MoveOnly, std::less<int>, min_allocator<std::pair<const int, MoveOnly>>> M;
61 typedef std::pair<M::iterator, bool> R;
62 M m;
63 R r = m.insert(M::value_type(2, 2));
64 assert(r.second);
65 assert(r.first == m.begin());
66 assert(m.size() == 1);
67 assert(r.first->first == 2);
68 assert(r.first->second == 2);
69
70 r = m.insert(M::value_type(1, 1));
71 assert(r.second);
72 assert(r.first == m.begin());
73 assert(m.size() == 2);
74 assert(r.first->first == 1);
75 assert(r.first->second == 1);
76
77 r = m.insert(M::value_type(3, 3));
78 assert(r.second);
79 assert(r.first == prev(m.end()));
80 assert(m.size() == 3);
81 assert(r.first->first == 3);
82 assert(r.first->second == 3);
83
84 r = m.insert(M::value_type(3, 3));
85 assert(!r.second);
86 assert(r.first == prev(m.end()));
87 assert(m.size() == 3);
88 assert(r.first->first == 3);
89 assert(r.first->second == 3);
90 }
91#endif
92#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000093}