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