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 {
27 typedef std::set<MoveOnly> M;
28 typedef std::pair<M::iterator, bool> R;
29 M m;
30 R r = m.insert(M::value_type(2));
31 assert(r.second);
32 assert(r.first == m.begin());
33 assert(m.size() == 1);
34 assert(*r.first == 2);
35
36 r = m.insert(M::value_type(1));
37 assert(r.second);
38 assert(r.first == m.begin());
39 assert(m.size() == 2);
40 assert(*r.first == 1);
41
42 r = m.insert(M::value_type(3));
43 assert(r.second);
44 assert(r.first == std::prev(m.end()));
45 assert(m.size() == 3);
46 assert(*r.first == 3);
47
48 r = m.insert(M::value_type(3));
49 assert(!r.second);
50 assert(r.first == std::prev(m.end()));
51 assert(m.size() == 3);
52 assert(*r.first == 3);
53 }
54 {
55 typedef std::set<MoveOnly, std::less<MoveOnly>, min_allocator<MoveOnly>> M;
56 typedef std::pair<M::iterator, bool> R;
57 M m;
58 R r = m.insert(M::value_type(2));
59 assert(r.second);
60 assert(r.first == m.begin());
61 assert(m.size() == 1);
62 assert(*r.first == 2);
63
64 r = m.insert(M::value_type(1));
65 assert(r.second);
66 assert(r.first == m.begin());
67 assert(m.size() == 2);
68 assert(*r.first == 1);
69
70 r = m.insert(M::value_type(3));
71 assert(r.second);
72 assert(r.first == std::prev(m.end()));
73 assert(m.size() == 3);
74 assert(*r.first == 3);
75
76 r = m.insert(M::value_type(3));
77 assert(!r.second);
78 assert(r.first == std::prev(m.end()));
79 assert(m.size() == 3);
80 assert(*r.first == 3);
81 }
82
83 return 0;
84}
85

source code of libcxx/test/std/containers/associative/set/insert_rv.pass.cpp