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