llvm-project
84 строки · 2.2 Кб
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// pair<iterator, bool> insert(value_type&& v);
16
17#include <set>18#include <cassert>19
20#include "test_macros.h"21#include "MoveOnly.h"22#include "min_allocator.h"23
24int main(int, char**)25{
26{27typedef std::set<MoveOnly> M;28typedef std::pair<M::iterator, bool> R;29M m;30R r = m.insert(M::value_type(2));31assert(r.second);32assert(r.first == m.begin());33assert(m.size() == 1);34assert(*r.first == 2);35
36r = m.insert(M::value_type(1));37assert(r.second);38assert(r.first == m.begin());39assert(m.size() == 2);40assert(*r.first == 1);41
42r = m.insert(M::value_type(3));43assert(r.second);44assert(r.first == std::prev(m.end()));45assert(m.size() == 3);46assert(*r.first == 3);47
48r = m.insert(M::value_type(3));49assert(!r.second);50assert(r.first == std::prev(m.end()));51assert(m.size() == 3);52assert(*r.first == 3);53}54{55typedef std::set<MoveOnly, std::less<MoveOnly>, min_allocator<MoveOnly>> M;56typedef std::pair<M::iterator, bool> R;57M m;58R r = m.insert(M::value_type(2));59assert(r.second);60assert(r.first == m.begin());61assert(m.size() == 1);62assert(*r.first == 2);63
64r = m.insert(M::value_type(1));65assert(r.second);66assert(r.first == m.begin());67assert(m.size() == 2);68assert(*r.first == 1);69
70r = m.insert(M::value_type(3));71assert(r.second);72assert(r.first == std::prev(m.end()));73assert(m.size() == 3);74assert(*r.first == 3);75
76r = m.insert(M::value_type(3));77assert(!r.second);78assert(r.first == std::prev(m.end()));79assert(m.size() == 3);80assert(*r.first == 3);81}82
83return 0;84}
85