llvm-project
99 строк · 2.6 Кб
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9// UNSUPPORTED: c++03
10
11// <map>
12
13// class map
14
15// template <class P>
16// iterator insert(const_iterator position, P&& p);
17
18#include <map>19#include <cassert>20
21#include "MoveOnly.h"22#include "min_allocator.h"23#include "test_macros.h"24
25template <class Container, class Pair>26void do_insert_iter_rv_test()27{
28typedef Container M;29typedef Pair P;30typedef typename M::iterator R;31M m;32R r = m.insert(m.end(), P(2, 2));33assert(r == m.begin());34assert(m.size() == 1);35assert(r->first == 2);36assert(r->second == 2);37
38r = m.insert(m.end(), P(1, 1));39assert(r == m.begin());40assert(m.size() == 2);41assert(r->first == 1);42assert(r->second == 1);43
44r = m.insert(m.end(), P(3, 3));45assert(r == std::prev(m.end()));46assert(m.size() == 3);47assert(r->first == 3);48assert(r->second == 3);49
50r = m.insert(m.end(), P(3, 4));51assert(r == std::prev(m.end()));52assert(m.size() == 3);53assert(r->first == 3);54assert(r->second == 3);55}
56int main(int, char**)57{
58do_insert_iter_rv_test<std::map<int, MoveOnly>, std::pair<int, MoveOnly>>();59do_insert_iter_rv_test<std::map<int, MoveOnly>, std::pair<const int, MoveOnly>>();60
61{62typedef std::map<int, MoveOnly, std::less<int>, min_allocator<std::pair<const int, MoveOnly>>> M;63typedef std::pair<int, MoveOnly> P;64typedef std::pair<const int, MoveOnly> CP;65do_insert_iter_rv_test<M, P>();66do_insert_iter_rv_test<M, CP>();67}68{69typedef std::map<int, MoveOnly> M;70typedef M::iterator R;71M m;72R r = m.insert(m.end(), {2, MoveOnly(2)});73assert(r == m.begin());74assert(m.size() == 1);75assert(r->first == 2);76assert(r->second == 2);77
78r = m.insert(m.end(), {1, MoveOnly(1)});79assert(r == m.begin());80assert(m.size() == 2);81assert(r->first == 1);82assert(r->second == 1);83
84r = m.insert(m.end(), {3, MoveOnly(3)});85assert(r == std::prev(m.end()));86assert(m.size() == 3);87assert(r->first == 3);88assert(r->second == 3);89
90r = m.insert(m.end(), {3, MoveOnly(3)});91assert(r == std::prev(m.end()));92assert(m.size() == 3);93assert(r->first == 3);94assert(r->second == 3);95}96
97
98return 0;99}
100