blob: fdabf02a81d53c458200e0c92dd778030e246748 [file] [log] [blame]
Howard Hinnant3e519522010-05-11 19:42:16 +00001//===----------------------------------------------------------------------===//
2//
Chandler Carruth57b08b02019-01-19 10:56:40 +00003// 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
Howard Hinnant3e519522010-05-11 19:42:16 +00006//
7//===----------------------------------------------------------------------===//
8
Eric Fiselier922940b2017-04-18 20:58:03 +00009// UNSUPPORTED: c++98, c++03
10
Howard Hinnant3e519522010-05-11 19:42:16 +000011// <set>
12
13// class set
14
15// template <class... Args>
16// pair<iterator, bool> emplace(Args&&... args);
17
18#include <set>
19#include <cassert>
20
21#include "../../Emplaceable.h"
Marshall Clowa26fcc72013-12-02 17:00:56 +000022#include "DefaultOnly.h"
Marshall Clowe34f6f62013-11-26 20:58:02 +000023#include "min_allocator.h"
Howard Hinnant3e519522010-05-11 19:42:16 +000024
25int main()
26{
Howard Hinnant3e519522010-05-11 19:42:16 +000027 {
28 typedef std::set<DefaultOnly> M;
29 typedef std::pair<M::iterator, bool> R;
30 M m;
31 assert(DefaultOnly::count == 0);
32 R r = m.emplace();
33 assert(r.second);
34 assert(r.first == m.begin());
35 assert(m.size() == 1);
36 assert(*m.begin() == DefaultOnly());
37 assert(DefaultOnly::count == 1);
38
39 r = m.emplace();
40 assert(!r.second);
41 assert(r.first == m.begin());
42 assert(m.size() == 1);
43 assert(*m.begin() == DefaultOnly());
44 assert(DefaultOnly::count == 1);
45 }
46 assert(DefaultOnly::count == 0);
47 {
48 typedef std::set<Emplaceable> M;
49 typedef std::pair<M::iterator, bool> R;
50 M m;
51 R r = m.emplace();
52 assert(r.second);
53 assert(r.first == m.begin());
54 assert(m.size() == 1);
55 assert(*m.begin() == Emplaceable());
56 r = m.emplace(2, 3.5);
57 assert(r.second);
58 assert(r.first == next(m.begin()));
59 assert(m.size() == 2);
60 assert(*r.first == Emplaceable(2, 3.5));
61 r = m.emplace(2, 3.5);
62 assert(!r.second);
63 assert(r.first == next(m.begin()));
64 assert(m.size() == 2);
65 assert(*r.first == Emplaceable(2, 3.5));
66 }
67 {
68 typedef std::set<int> M;
69 typedef std::pair<M::iterator, bool> R;
70 M m;
71 R r = m.emplace(M::value_type(2));
72 assert(r.second);
73 assert(r.first == m.begin());
74 assert(m.size() == 1);
75 assert(*r.first == 2);
76 }
Howard Hinnant07d3ecc2013-06-19 21:29:40 +000077 {
78 typedef std::set<int, std::less<int>, min_allocator<int>> M;
79 typedef std::pair<M::iterator, bool> R;
80 M m;
81 R r = m.emplace(M::value_type(2));
82 assert(r.second);
83 assert(r.first == m.begin());
84 assert(m.size() == 1);
85 assert(*r.first == 2);
86 }
Howard Hinnant3e519522010-05-11 19:42:16 +000087}