llvm-project
90 строк · 2.5 Кб
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
26int main(int, char**)27{
28{29typedef std::set<DefaultOnly> M;30typedef std::pair<M::iterator, bool> R;31M m;32assert(DefaultOnly::count == 0);33R r = m.emplace();34assert(r.second);35assert(r.first == m.begin());36assert(m.size() == 1);37assert(*m.begin() == DefaultOnly());38assert(DefaultOnly::count == 1);39
40r = m.emplace();41assert(!r.second);42assert(r.first == m.begin());43assert(m.size() == 1);44assert(*m.begin() == DefaultOnly());45assert(DefaultOnly::count == 1);46}47assert(DefaultOnly::count == 0);48{49typedef std::set<Emplaceable> M;50typedef std::pair<M::iterator, bool> R;51M m;52R r = m.emplace();53assert(r.second);54assert(r.first == m.begin());55assert(m.size() == 1);56assert(*m.begin() == Emplaceable());57r = m.emplace(2, 3.5);58assert(r.second);59assert(r.first == std::next(m.begin()));60assert(m.size() == 2);61assert(*r.first == Emplaceable(2, 3.5));62r = m.emplace(2, 3.5);63assert(!r.second);64assert(r.first == std::next(m.begin()));65assert(m.size() == 2);66assert(*r.first == Emplaceable(2, 3.5));67}68{69typedef std::set<int> M;70typedef std::pair<M::iterator, bool> R;71M m;72R r = m.emplace(M::value_type(2));73assert(r.second);74assert(r.first == m.begin());75assert(m.size() == 1);76assert(*r.first == 2);77}78{79typedef std::set<int, std::less<int>, min_allocator<int>> M;80typedef std::pair<M::iterator, bool> R;81M m;82R r = m.emplace(M::value_type(2));83assert(r.second);84assert(r.first == m.begin());85assert(m.size() == 1);86assert(*r.first == 2);87}88
89return 0;90}
91