blob: bee5b930e5d715a7465b4d2ae729a1fe4f46ccd0 [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
Louis Dionne31cbe0f2020-06-01 10:38:23 -04009// UNSUPPORTED: c++03
Eric Fiselier922940b2017-04-18 20:58:03 +000010
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
Marshall Clow7fc6a552019-05-31 18:35:30 +000021#include "test_macros.h"
Howard Hinnant3e519522010-05-11 19:42:16 +000022#include "../../Emplaceable.h"
Marshall Clowa26fcc72013-12-02 17:00:56 +000023#include "DefaultOnly.h"
Marshall Clowe34f6f62013-11-26 20:58:02 +000024#include "min_allocator.h"
Howard Hinnant3e519522010-05-11 19:42:16 +000025
JF Bastien2df59c52019-02-04 20:31:13 +000026int main(int, char**)
Howard Hinnant3e519522010-05-11 19:42:16 +000027{
Howard Hinnant3e519522010-05-11 19:42:16 +000028 {
29 typedef std::set<DefaultOnly> M;
30 typedef std::pair<M::iterator, bool> R;
31 M m;
32 assert(DefaultOnly::count == 0);
33 R r = m.emplace();
34 assert(r.second);
35 assert(r.first == m.begin());
36 assert(m.size() == 1);
37 assert(*m.begin() == DefaultOnly());
38 assert(DefaultOnly::count == 1);
39
40 r = m.emplace();
41 assert(!r.second);
42 assert(r.first == m.begin());
43 assert(m.size() == 1);
44 assert(*m.begin() == DefaultOnly());
45 assert(DefaultOnly::count == 1);
46 }
47 assert(DefaultOnly::count == 0);
48 {
49 typedef std::set<Emplaceable> M;
50 typedef std::pair<M::iterator, bool> R;
51 M m;
52 R r = m.emplace();
53 assert(r.second);
54 assert(r.first == m.begin());
55 assert(m.size() == 1);
56 assert(*m.begin() == Emplaceable());
57 r = m.emplace(2, 3.5);
58 assert(r.second);
59 assert(r.first == next(m.begin()));
60 assert(m.size() == 2);
61 assert(*r.first == Emplaceable(2, 3.5));
62 r = m.emplace(2, 3.5);
63 assert(!r.second);
64 assert(r.first == next(m.begin()));
65 assert(m.size() == 2);
66 assert(*r.first == Emplaceable(2, 3.5));
67 }
68 {
69 typedef std::set<int> M;
70 typedef std::pair<M::iterator, bool> R;
71 M m;
72 R r = m.emplace(M::value_type(2));
73 assert(r.second);
74 assert(r.first == m.begin());
75 assert(m.size() == 1);
76 assert(*r.first == 2);
77 }
Howard Hinnant07d3ecc2013-06-19 21:29:40 +000078 {
79 typedef std::set<int, std::less<int>, min_allocator<int>> M;
80 typedef std::pair<M::iterator, bool> R;
81 M m;
82 R r = m.emplace(M::value_type(2));
83 assert(r.second);
84 assert(r.first == m.begin());
85 assert(m.size() == 1);
86 assert(*r.first == 2);
87 }
JF Bastien2df59c52019-02-04 20:31:13 +000088
89 return 0;
Howard Hinnant3e519522010-05-11 19:42:16 +000090}