15a83710eSEric Fiselier //===----------------------------------------------------------------------===//
25a83710eSEric Fiselier //
357b08b09SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
457b08b09SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
557b08b09SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
65a83710eSEric Fiselier //
75a83710eSEric Fiselier //===----------------------------------------------------------------------===//
85a83710eSEric Fiselier
931cbe0f2SLouis Dionne // UNSUPPORTED: c++03
107a9f500fSEric Fiselier
115a83710eSEric Fiselier // <map>
125a83710eSEric Fiselier
135a83710eSEric Fiselier // class multimap
145a83710eSEric Fiselier
155a83710eSEric Fiselier // template <class P>
165a83710eSEric Fiselier // iterator insert(P&& p);
175a83710eSEric Fiselier
185a83710eSEric Fiselier #include <map>
195a83710eSEric Fiselier #include <cassert>
205a83710eSEric Fiselier
21949389c3SMarshall Clow #include "MoveOnly.h"
225a83710eSEric Fiselier #include "min_allocator.h"
23652a2ce1SMarshall Clow #include "test_macros.h"
245a83710eSEric Fiselier
257a9f500fSEric Fiselier template <class Container>
do_insert_rv_test()267a9f500fSEric Fiselier void do_insert_rv_test()
275a83710eSEric Fiselier {
285a83710eSEric Fiselier typedef std::multimap<int, MoveOnly> M;
297a9f500fSEric Fiselier typedef typename M::iterator R;
307a9f500fSEric Fiselier typedef typename M::value_type VT;
315a83710eSEric Fiselier M m;
327a9f500fSEric Fiselier R r = m.insert(VT(2, 2));
335a83710eSEric Fiselier assert(r == m.begin());
345a83710eSEric Fiselier assert(m.size() == 1);
355a83710eSEric Fiselier assert(r->first == 2);
365a83710eSEric Fiselier assert(r->second == 2);
375a83710eSEric Fiselier
387a9f500fSEric Fiselier r = m.insert(VT(1, 1));
395a83710eSEric Fiselier assert(r == m.begin());
405a83710eSEric Fiselier assert(m.size() == 2);
415a83710eSEric Fiselier assert(r->first == 1);
425a83710eSEric Fiselier assert(r->second == 1);
435a83710eSEric Fiselier
447a9f500fSEric Fiselier r = m.insert(VT(3, 3));
45*3b966c1fSArthur O'Dwyer assert(r == std::prev(m.end()));
465a83710eSEric Fiselier assert(m.size() == 3);
475a83710eSEric Fiselier assert(r->first == 3);
485a83710eSEric Fiselier assert(r->second == 3);
495a83710eSEric Fiselier
507a9f500fSEric Fiselier r = m.insert(VT(3, 3));
51*3b966c1fSArthur O'Dwyer assert(r == std::prev(m.end()));
525a83710eSEric Fiselier assert(m.size() == 4);
535a83710eSEric Fiselier assert(r->first == 3);
545a83710eSEric Fiselier assert(r->second == 3);
555a83710eSEric Fiselier }
567a9f500fSEric Fiselier
main(int,char **)572df59c50SJF Bastien int main(int, char**)
587a9f500fSEric Fiselier {
597a9f500fSEric Fiselier do_insert_rv_test<std::multimap<int, MoveOnly>>();
605a83710eSEric Fiselier {
615a83710eSEric Fiselier typedef std::multimap<int, MoveOnly, std::less<int>, min_allocator<std::pair<const int, MoveOnly>>> M;
627a9f500fSEric Fiselier do_insert_rv_test<M>();
635a83710eSEric Fiselier }
64afc9ff99SMarshall Clow {
65afc9ff99SMarshall Clow typedef std::multimap<int, MoveOnly> M;
66afc9ff99SMarshall Clow typedef M::iterator R;
67afc9ff99SMarshall Clow M m;
68afc9ff99SMarshall Clow R r = m.insert({2, MoveOnly(2)});
69afc9ff99SMarshall Clow assert(r == m.begin());
70afc9ff99SMarshall Clow assert(m.size() == 1);
71afc9ff99SMarshall Clow assert(r->first == 2);
72afc9ff99SMarshall Clow assert(r->second == 2);
73afc9ff99SMarshall Clow
74afc9ff99SMarshall Clow r = m.insert({1, MoveOnly(1)});
75afc9ff99SMarshall Clow assert(r == m.begin());
76afc9ff99SMarshall Clow assert(m.size() == 2);
77afc9ff99SMarshall Clow assert(r->first == 1);
78afc9ff99SMarshall Clow assert(r->second == 1);
79afc9ff99SMarshall Clow
80afc9ff99SMarshall Clow r = m.insert({3, MoveOnly(3)});
81*3b966c1fSArthur O'Dwyer assert(r == std::prev(m.end()));
82afc9ff99SMarshall Clow assert(m.size() == 3);
83afc9ff99SMarshall Clow assert(r->first == 3);
84afc9ff99SMarshall Clow assert(r->second == 3);
85afc9ff99SMarshall Clow
86afc9ff99SMarshall Clow r = m.insert({3, MoveOnly(3)});
87*3b966c1fSArthur O'Dwyer assert(r == std::prev(m.end()));
88afc9ff99SMarshall Clow assert(m.size() == 4);
89afc9ff99SMarshall Clow assert(r->first == 3);
90afc9ff99SMarshall Clow assert(r->second == 3);
91afc9ff99SMarshall Clow }
922df59c50SJF Bastien
932df59c50SJF Bastien return 0;
945a83710eSEric Fiselier }
95