blob: 42b41fd7b867452718718e4954b845ba672c9757 [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// iterator insert(const_iterator position, 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"
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000022
23int 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;
Dan Albert1d4a1ed2016-05-25 22:36:09 -070028 typedef std::pair<int, MoveOnly> P;
Marshall Clow3426a862016-01-05 19:32:41 +000029 typedef M::iterator R;
30 M m;
Dan Albert1d4a1ed2016-05-25 22:36:09 -070031 R r = m.insert(m.end(), P(2, 2));
Marshall Clow3426a862016-01-05 19:32:41 +000032 assert(r == m.begin());
33 assert(m.size() == 1);
34 assert(r->first == 2);
35 assert(r->second == 2);
36
Dan Albert1d4a1ed2016-05-25 22:36:09 -070037 r = m.insert(m.end(), P(1, 1));
Marshall Clow3426a862016-01-05 19:32:41 +000038 assert(r == m.begin());
39 assert(m.size() == 2);
40 assert(r->first == 1);
41 assert(r->second == 1);
42
Dan Albert1d4a1ed2016-05-25 22:36:09 -070043 r = m.insert(m.end(), P(3, 3));
Marshall Clow3426a862016-01-05 19:32:41 +000044 assert(r == prev(m.end()));
45 assert(m.size() == 3);
46 assert(r->first == 3);
47 assert(r->second == 3);
48
Dan Albert1d4a1ed2016-05-25 22:36:09 -070049 r = m.insert(m.end(), P(3, 3));
Marshall Clow3426a862016-01-05 19:32:41 +000050 assert(r == prev(m.end()));
51 assert(m.size() == 3);
52 assert(r->first == 3);
53 assert(r->second == 3);
54 }
Dan Albert1d4a1ed2016-05-25 22:36:09 -070055#if __cplusplus >= 201103L
56 {
57 typedef std::map<int, MoveOnly, std::less<int>, min_allocator<std::pair<const int, MoveOnly>>> M;
58 typedef std::pair<int, MoveOnly> P;
59 typedef M::iterator R;
60 M m;
61 R r = m.insert(m.end(), P(2, 2));
62 assert(r == m.begin());
63 assert(m.size() == 1);
64 assert(r->first == 2);
65 assert(r->second == 2);
Eric Fiselier91a15652016-04-18 01:40:45 +000066
Dan Albert1d4a1ed2016-05-25 22:36:09 -070067 r = m.insert(m.end(), P(1, 1));
68 assert(r == m.begin());
69 assert(m.size() == 2);
70 assert(r->first == 1);
71 assert(r->second == 1);
72
73 r = m.insert(m.end(), P(3, 3));
74 assert(r == prev(m.end()));
75 assert(m.size() == 3);
76 assert(r->first == 3);
77 assert(r->second == 3);
78
79 r = m.insert(m.end(), P(3, 3));
80 assert(r == prev(m.end()));
81 assert(m.size() == 3);
82 assert(r->first == 3);
83 assert(r->second == 3);
84 }
85#endif
86#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000087}