blob: b1c043586d65c9f65683259e1a8173dc3d7764ac [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 multimap
13
14// template <class P>
15// iterator 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::multimap<int, MoveOnly> M;
28 typedef M::iterator 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 == m.begin());
32 assert(m.size() == 1);
33 assert(r->first == 2);
34 assert(r->second == 2);
35
Dan Albert1d4a1ed2016-05-25 22:36:09 -070036 r = m.insert(M::value_type(1, 1));
Marshall Clow3426a862016-01-05 19:32:41 +000037 assert(r == m.begin());
38 assert(m.size() == 2);
39 assert(r->first == 1);
40 assert(r->second == 1);
41
Dan Albert1d4a1ed2016-05-25 22:36:09 -070042 r = m.insert(M::value_type(3, 3));
Marshall Clow3426a862016-01-05 19:32:41 +000043 assert(r == prev(m.end()));
44 assert(m.size() == 3);
45 assert(r->first == 3);
46 assert(r->second == 3);
47
Dan Albert1d4a1ed2016-05-25 22:36:09 -070048 r = m.insert(M::value_type(3, 3));
Marshall Clow3426a862016-01-05 19:32:41 +000049 assert(r == prev(m.end()));
50 assert(m.size() == 4);
51 assert(r->first == 3);
52 assert(r->second == 3);
53 }
Dan Albert1d4a1ed2016-05-25 22:36:09 -070054#if __cplusplus >= 201103L
55 {
56 typedef std::multimap<int, MoveOnly, std::less<int>, min_allocator<std::pair<const int, MoveOnly>>> M;
57 typedef M::iterator R;
58 M m;
59 R r = m.insert(M::value_type(2, 2));
60 assert(r == m.begin());
61 assert(m.size() == 1);
62 assert(r->first == 2);
63 assert(r->second == 2);
64
65 r = m.insert(M::value_type(1, 1));
66 assert(r == m.begin());
67 assert(m.size() == 2);
68 assert(r->first == 1);
69 assert(r->second == 1);
70
71 r = m.insert(M::value_type(3, 3));
72 assert(r == prev(m.end()));
73 assert(m.size() == 3);
74 assert(r->first == 3);
75 assert(r->second == 3);
76
77 r = m.insert(M::value_type(3, 3));
78 assert(r == prev(m.end()));
79 assert(m.size() == 4);
80 assert(r->first == 3);
81 assert(r->second == 3);
82 }
83#endif
84#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000085}