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, c++11, c++14, c++17, c++20
10
11// <flat_set>
12
13// iterator upper_bound(const key_type& k);
14// const_iterator upper_bound(const key_type& k) const;
15
16#include <cassert>
17#include <deque>
18#include <flat_set>
19#include <functional>
20#include <utility>
21
22#include "MinSequenceContainer.h"
23#include "test_macros.h"
24#include "min_allocator.h"
25
26template <class KeyContainer>
27void test_one() {
28 using Key = typename KeyContainer::value_type;
29 {
30 using M = std::flat_multiset<Key, std::less<>, KeyContainer>;
31 M m = {1, 1, 2, 2, 4, 4, 5, 5, 8, 8};
32 ASSERT_SAME_TYPE(decltype(m.upper_bound(0)), typename M::iterator);
33 ASSERT_SAME_TYPE(decltype(std::as_const(m).upper_bound(0)), typename M::const_iterator);
34 assert(m.upper_bound(0) == m.begin());
35 assert(m.upper_bound(1) == m.begin() + 2);
36 assert(m.upper_bound(2) == m.begin() + 4);
37 assert(m.upper_bound(3) == m.begin() + 4);
38 assert(m.upper_bound(4) == m.begin() + 6);
39 assert(m.upper_bound(5) == m.begin() + 8);
40 assert(m.upper_bound(6) == m.begin() + 8);
41 assert(std::as_const(m).upper_bound(7) == m.begin() + 8);
42 assert(std::as_const(m).upper_bound(8) == m.end());
43 assert(std::as_const(m).upper_bound(9) == m.end());
44 }
45
46 {
47 using M = std::flat_multiset<Key, std::greater<int>, KeyContainer>;
48 M m = {1, 1, 1, 1, 2, 2, 4, 4, 4, 5, 5, 5, 5, 5, 8, 8};
49 ASSERT_SAME_TYPE(decltype(m.upper_bound(0)), typename M::iterator);
50 ASSERT_SAME_TYPE(decltype(std::as_const(m).upper_bound(0)), typename M::const_iterator);
51 assert(m.upper_bound(0) == m.end());
52 assert(m.upper_bound(1) == m.end());
53 assert(m.upper_bound(2) == m.begin() + 12);
54 assert(m.upper_bound(3) == m.begin() + 10);
55 assert(m.upper_bound(4) == m.begin() + 10);
56 assert(m.upper_bound(5) == m.begin() + 7);
57 assert(m.upper_bound(6) == m.begin() + 2);
58 assert(m.upper_bound(7) == m.begin() + 2);
59 assert(std::as_const(m).upper_bound(8) == m.begin() + 2);
60 assert(std::as_const(m).upper_bound(9) == m.begin());
61 }
62 {
63 // empty
64 using M = std::flat_multiset<Key, std::less<>, KeyContainer>;
65 M m;
66 assert(m.upper_bound(0) == m.end());
67 }
68}
69
70void test() {
71 test_one<std::vector<int>>();
72 test_one<std::deque<int>>();
73 test_one<MinSequenceContainer<int>>();
74 test_one<std::vector<int, min_allocator<int>>>();
75}
76
77int main(int, char**) {
78 test();
79
80 return 0;
81}
82

source code of libcxx/test/std/containers/container.adaptors/flat.multiset/flat.multiset.operations/upper_bound.pass.cpp