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(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
26int main(int, char**) {
27 {
28 typedef std::multiset<DefaultOnly> M;
29 typedef M::iterator R;
30 M m;
31 assert(DefaultOnly::count == 0);
32 R r = m.emplace();
33 assert(r == m.begin());
34 assert(m.size() == 1);
35 assert(*m.begin() == DefaultOnly());
36 assert(DefaultOnly::count == 1);
37
38 r = m.emplace();
39 assert(r == std::next(m.begin()));
40 assert(m.size() == 2);
41 assert(*m.begin() == DefaultOnly());
42 assert(DefaultOnly::count == 2);
43 }
44 assert(DefaultOnly::count == 0);
45 {
46 typedef std::multiset<Emplaceable> M;
47 typedef M::iterator R;
48 M m;
49 R r = m.emplace();
50 assert(r == m.begin());
51 assert(m.size() == 1);
52 assert(*m.begin() == Emplaceable());
53 r = m.emplace(2, 3.5);
54 assert(r == std::next(m.begin()));
55 assert(m.size() == 2);
56 assert(*r == Emplaceable(2, 3.5));
57 r = m.emplace(2, 3.5);
58 assert(r == std::next(m.begin(), 2));
59 assert(m.size() == 3);
60 assert(*r == Emplaceable(2, 3.5));
61 }
62 {
63 typedef std::multiset<int> M;
64 typedef M::iterator R;
65 M m;
66 R r = m.emplace(args: M::value_type(2));
67 assert(r == m.begin());
68 assert(m.size() == 1);
69 assert(*r == 2);
70 }
71 {
72 typedef std::multiset<int, std::less<int>, min_allocator<int>> M;
73 typedef M::iterator R;
74 M m;
75 R r = m.emplace(M::value_type(2));
76 assert(r == m.begin());
77 assert(m.size() == 1);
78 assert(*r == 2);
79 }
80
81 return 0;
82}
83

source code of libcxx/test/std/containers/associative/multiset/emplace.pass.cpp