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 // <set>
12 
13 // class multiset
14 
15 // template <class... Args>
16 //   iterator emplace_hint(const_iterator position, Args&&... args);
17 
18 #include <set>
19 #include <cassert>
20 
21 #include "test_macros.h"
22 #include "../../Emplaceable.h"
23 #include "DefaultOnly.h"
24 #include "min_allocator.h"
25 
main(int,char **)26 int main(int, char**)
27 {
28     {
29         typedef std::multiset<DefaultOnly> M;
30         typedef M::iterator R;
31         M m;
32         assert(DefaultOnly::count == 0);
33         R r = m.emplace_hint(m.cend());
34         assert(r == m.begin());
35         assert(m.size() == 1);
36         assert(*m.begin() == DefaultOnly());
37         assert(DefaultOnly::count == 1);
38 
39         r = m.emplace_hint(m.cbegin());
40         assert(r == m.begin());
41         assert(m.size() == 2);
42         assert(*m.begin() == DefaultOnly());
43         assert(DefaultOnly::count == 2);
44     }
45     assert(DefaultOnly::count == 0);
46     {
47         typedef std::multiset<Emplaceable> M;
48         typedef M::iterator R;
49         M m;
50         R r = m.emplace_hint(m.cend());
51         assert(r == m.begin());
52         assert(m.size() == 1);
53         assert(*m.begin() == Emplaceable());
54         r = m.emplace_hint(m.cend(), 2, 3.5);
55         assert(r == next(m.begin()));
56         assert(m.size() == 2);
57         assert(*r == Emplaceable(2, 3.5));
58         r = m.emplace_hint(m.cbegin(), 2, 3.5);
59         assert(r == next(m.begin()));
60         assert(m.size() == 3);
61         assert(*r == Emplaceable(2, 3.5));
62     }
63     {
64         typedef std::multiset<int> M;
65         typedef M::iterator R;
66         M m;
67         R r = m.emplace_hint(m.cend(), M::value_type(2));
68         assert(r == m.begin());
69         assert(m.size() == 1);
70         assert(*r == 2);
71     }
72     {
73         typedef std::multiset<int, std::less<int>, min_allocator<int>> M;
74         typedef M::iterator R;
75         M m;
76         R r = m.emplace_hint(m.cend(), M::value_type(2));
77         assert(r == m.begin());
78         assert(m.size() == 1);
79         assert(*r == 2);
80     }
81 
82   return 0;
83 }
84