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(const_iterator position, 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, class Pair>
do_insert_rv_test()267a9f500fSEric Fiselier void do_insert_rv_test()
275a83710eSEric Fiselier {
287a9f500fSEric Fiselier typedef Container M;
297a9f500fSEric Fiselier typedef Pair P;
307a9f500fSEric Fiselier typedef typename M::iterator R;
315a83710eSEric Fiselier M m;
325a83710eSEric Fiselier R r = m.insert(m.cend(), P(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
385a83710eSEric Fiselier r = m.insert(m.cend(), P(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
445a83710eSEric Fiselier r = m.insert(m.cend(), P(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
505a83710eSEric Fiselier r = m.insert(m.cend(), P(3, 2));
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 == 2);
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>, std::pair<int, MoveOnly> >();
607a9f500fSEric Fiselier do_insert_rv_test<std::multimap<int, MoveOnly>, std::pair<const int, MoveOnly> >();
617a9f500fSEric Fiselier
625a83710eSEric Fiselier {
635a83710eSEric Fiselier typedef std::multimap<int, MoveOnly, std::less<int>, min_allocator<std::pair<const int, MoveOnly>>> M;
645a83710eSEric Fiselier typedef std::pair<int, MoveOnly> P;
657a9f500fSEric Fiselier typedef std::pair<const int, MoveOnly> CP;
667a9f500fSEric Fiselier do_insert_rv_test<M, P>();
677a9f500fSEric Fiselier do_insert_rv_test<M, CP>();
685a83710eSEric Fiselier
695a83710eSEric Fiselier }
70afc9ff99SMarshall Clow {
71afc9ff99SMarshall Clow typedef std::multimap<int, MoveOnly> M;
72afc9ff99SMarshall Clow typedef M::iterator R;
73afc9ff99SMarshall Clow M m;
74afc9ff99SMarshall Clow R r = m.insert(m.cend(), {2, MoveOnly(2)});
75afc9ff99SMarshall Clow assert(r == m.begin());
76afc9ff99SMarshall Clow assert(m.size() == 1);
77afc9ff99SMarshall Clow assert(r->first == 2);
78afc9ff99SMarshall Clow assert(r->second == 2);
79afc9ff99SMarshall Clow
80afc9ff99SMarshall Clow r = m.insert(m.cend(), {1, MoveOnly(1)});
81afc9ff99SMarshall Clow assert(r == m.begin());
82afc9ff99SMarshall Clow assert(m.size() == 2);
83afc9ff99SMarshall Clow assert(r->first == 1);
84afc9ff99SMarshall Clow assert(r->second == 1);
85afc9ff99SMarshall Clow
86afc9ff99SMarshall Clow r = m.insert(m.cend(), {3, MoveOnly(3)});
87*3b966c1fSArthur O'Dwyer assert(r == std::prev(m.end()));
88afc9ff99SMarshall Clow assert(m.size() == 3);
89afc9ff99SMarshall Clow assert(r->first == 3);
90afc9ff99SMarshall Clow assert(r->second == 3);
91afc9ff99SMarshall Clow
92afc9ff99SMarshall Clow r = m.insert(m.cend(), {3, MoveOnly(2)});
93*3b966c1fSArthur O'Dwyer assert(r == std::prev(m.end()));
94afc9ff99SMarshall Clow assert(m.size() == 4);
95afc9ff99SMarshall Clow assert(r->first == 3);
96afc9ff99SMarshall Clow assert(r->second == 2);
97afc9ff99SMarshall Clow }
982df59c50SJF Bastien
992df59c50SJF Bastien return 0;
1005a83710eSEric Fiselier }
101