llvm-project

Форк
0
160 строк · 6.2 Кб
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... Args>
16
//   iterator emplace_hint(const_iterator position, Args&&... args);
17

18
#include <map>
19
#include <cassert>
20

21
#include "test_macros.h"
22
#include "../../../Emplaceable.h"
23
#include "DefaultOnly.h"
24
#include "min_allocator.h"
25

26
int main(int, char**)
27
{
28
    {
29
        typedef std::map<int, DefaultOnly> M;
30
        typedef M::iterator R;
31
        M m;
32
        assert(DefaultOnly::count == 0);
33
        R r = m.emplace_hint(m.end());
34
        assert(r == m.begin());
35
        assert(m.size() == 1);
36
        assert(m.begin()->first == 0);
37
        assert(m.begin()->second == DefaultOnly());
38
        assert(DefaultOnly::count == 1);
39
        r = m.emplace_hint(m.end(), std::piecewise_construct,
40
                                       std::forward_as_tuple(1),
41
                                       std::forward_as_tuple());
42
        assert(r == std::next(m.begin()));
43
        assert(m.size() == 2);
44
        assert(std::next(m.begin())->first == 1);
45
        assert(std::next(m.begin())->second == DefaultOnly());
46
        assert(DefaultOnly::count == 2);
47
        r = m.emplace_hint(m.end(), std::piecewise_construct,
48
                                       std::forward_as_tuple(1),
49
                                       std::forward_as_tuple());
50
        assert(r == std::next(m.begin()));
51
        assert(m.size() == 2);
52
        assert(std::next(m.begin())->first == 1);
53
        assert(std::next(m.begin())->second == DefaultOnly());
54
        assert(DefaultOnly::count == 2);
55
    }
56
    assert(DefaultOnly::count == 0);
57
    {
58
        typedef std::map<int, Emplaceable> M;
59
        typedef M::iterator R;
60
        M m;
61
        R r = m.emplace_hint(m.end(), std::piecewise_construct,
62
                                       std::forward_as_tuple(2),
63
                                       std::forward_as_tuple());
64
        assert(r == m.begin());
65
        assert(m.size() == 1);
66
        assert(m.begin()->first == 2);
67
        assert(m.begin()->second == Emplaceable());
68
        r = m.emplace_hint(m.end(), std::piecewise_construct,
69
                                    std::forward_as_tuple(1),
70
                                    std::forward_as_tuple(2, 3.5));
71
        assert(r == m.begin());
72
        assert(m.size() == 2);
73
        assert(m.begin()->first == 1);
74
        assert(m.begin()->second == Emplaceable(2, 3.5));
75
        r = m.emplace_hint(m.end(), std::piecewise_construct,
76
                                    std::forward_as_tuple(1),
77
                                    std::forward_as_tuple(2, 3.5));
78
        assert(r == m.begin());
79
        assert(m.size() == 2);
80
        assert(m.begin()->first == 1);
81
        assert(m.begin()->second == Emplaceable(2, 3.5));
82
    }
83
    {
84
        typedef std::map<int, double> M;
85
        typedef M::iterator R;
86
        M m;
87
        R r = m.emplace_hint(m.end(), M::value_type(2, 3.5));
88
        assert(r == m.begin());
89
        assert(m.size() == 1);
90
        assert(m.begin()->first == 2);
91
        assert(m.begin()->second == 3.5);
92
    }
93
    {
94
        typedef std::map<int, DefaultOnly, std::less<int>, min_allocator<std::pair<const int, DefaultOnly>>> M;
95
        typedef M::iterator R;
96
        M m;
97
        assert(DefaultOnly::count == 0);
98
        R r = m.emplace_hint(m.end());
99
        assert(r == m.begin());
100
        assert(m.size() == 1);
101
        assert(m.begin()->first == 0);
102
        assert(m.begin()->second == DefaultOnly());
103
        assert(DefaultOnly::count == 1);
104
        r = m.emplace_hint(m.end(), std::piecewise_construct,
105
                                       std::forward_as_tuple(1),
106
                                       std::forward_as_tuple());
107
        assert(r == std::next(m.begin()));
108
        assert(m.size() == 2);
109
        assert(std::next(m.begin())->first == 1);
110
        assert(std::next(m.begin())->second == DefaultOnly());
111
        assert(DefaultOnly::count == 2);
112
        r = m.emplace_hint(m.end(), std::piecewise_construct,
113
                                       std::forward_as_tuple(1),
114
                                       std::forward_as_tuple());
115
        assert(r == std::next(m.begin()));
116
        assert(m.size() == 2);
117
        assert(std::next(m.begin())->first == 1);
118
        assert(std::next(m.begin())->second == DefaultOnly());
119
        assert(DefaultOnly::count == 2);
120
    }
121
    assert(DefaultOnly::count == 0);
122
    {
123
        typedef std::map<int, Emplaceable, std::less<int>, min_allocator<std::pair<const int, Emplaceable>>> M;
124
        typedef M::iterator R;
125
        M m;
126
        R r = m.emplace_hint(m.end(), std::piecewise_construct,
127
                                       std::forward_as_tuple(2),
128
                                       std::forward_as_tuple());
129
        assert(r == m.begin());
130
        assert(m.size() == 1);
131
        assert(m.begin()->first == 2);
132
        assert(m.begin()->second == Emplaceable());
133
        r = m.emplace_hint(m.end(), std::piecewise_construct,
134
                                    std::forward_as_tuple(1),
135
                                    std::forward_as_tuple(2, 3.5));
136
        assert(r == m.begin());
137
        assert(m.size() == 2);
138
        assert(m.begin()->first == 1);
139
        assert(m.begin()->second == Emplaceable(2, 3.5));
140
        r = m.emplace_hint(m.end(), std::piecewise_construct,
141
                                    std::forward_as_tuple(1),
142
                                    std::forward_as_tuple(2, 3.5));
143
        assert(r == m.begin());
144
        assert(m.size() == 2);
145
        assert(m.begin()->first == 1);
146
        assert(m.begin()->second == Emplaceable(2, 3.5));
147
    }
148
    {
149
        typedef std::map<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M;
150
        typedef M::iterator R;
151
        M m;
152
        R r = m.emplace_hint(m.end(), M::value_type(2, 3.5));
153
        assert(r == m.begin());
154
        assert(m.size() == 1);
155
        assert(m.begin()->first == 2);
156
        assert(m.begin()->second == 3.5);
157
    }
158

159
  return 0;
160
}
161

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.