| 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 set |
| 14 |
|
| 15 |
// template <class... Args> |
| 16 |
// pair<iterator, bool> 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 |
|
| 26 |
int main(int, char**) |
| 27 |
{ |
| 28 |
{ |
| 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 == std::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 == std::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 |
} |
| 78 |
{ |
| 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 |
} |
| 88 |
|
| 89 |
return 0; |
| 90 |
} |