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_map>
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_map>
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, class ValueContainer>
27void test() {
28 using Key = typename KeyContainer::value_type;
29 using Value = typename ValueContainer::value_type;
30 {
31 using M = std::flat_map<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
32 M m = {{1, 'a'}, {2, 'b'}, {4, 'd'}, {5, 'e'}, {8, 'h'}};
33 ASSERT_SAME_TYPE(decltype(m.upper_bound(0)), typename M::iterator);
34 ASSERT_SAME_TYPE(decltype(std::as_const(m).upper_bound(0)), typename M::const_iterator);
35 assert(m.upper_bound(0) == m.begin());
36 assert(m.upper_bound(1) == m.begin() + 1);
37 assert(m.upper_bound(2) == m.begin() + 2);
38 assert(m.upper_bound(3) == m.begin() + 2);
39 assert(m.upper_bound(4) == m.begin() + 3);
40 assert(m.upper_bound(5) == m.begin() + 4);
41 assert(m.upper_bound(6) == m.begin() + 4);
42 assert(std::as_const(m).upper_bound(7) == m.begin() + 4);
43 assert(std::as_const(m).upper_bound(8) == m.end());
44 assert(std::as_const(m).upper_bound(9) == m.end());
45 }
46
47 {
48 using M = std::flat_map<Key, Value, std::greater<Key>, KeyContainer, ValueContainer>;
49 M m = {{1, 'a'}, {2, 'b'}, {4, 'd'}, {5, 'e'}, {8, 'h'}};
50 ASSERT_SAME_TYPE(decltype(m.upper_bound(0)), typename M::iterator);
51 ASSERT_SAME_TYPE(decltype(std::as_const(m).upper_bound(0)), typename M::const_iterator);
52 assert(m.upper_bound(0) == m.end());
53 assert(m.upper_bound(1) == m.end());
54 assert(m.upper_bound(2) == m.begin() + 4);
55 assert(m.upper_bound(3) == m.begin() + 3);
56 assert(m.upper_bound(4) == m.begin() + 3);
57 assert(m.upper_bound(5) == m.begin() + 2);
58 assert(m.upper_bound(6) == m.begin() + 1);
59 assert(m.upper_bound(7) == m.begin() + 1);
60 assert(std::as_const(m).upper_bound(8) == m.begin() + 1);
61 assert(std::as_const(m).upper_bound(9) == m.begin());
62 }
63}
64
65int main(int, char**) {
66 test<std::vector<int>, std::vector<char>>();
67 test<std::deque<int>, std::vector<char>>();
68 test<MinSequenceContainer<int>, MinSequenceContainer<char>>();
69 test<std::vector<int, min_allocator<int>>, std::vector<char, min_allocator<char>>>();
70
71 return 0;
72}
73

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