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 find(const key_type& k);
14// const_iterator find(const key_type& k) const;
15
16#include <cassert>
17#include <deque>
18#include <flat_map>
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
27template <class KeyContainer, class ValueContainer>
28void test() {
29 using Key = typename KeyContainer::value_type;
30 using Value = typename ValueContainer::value_type;
31 using M = std::flat_map<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
32
33 M m = {{1, 'a'}, {2, 'b'}, {4, 'd'}, {5, 'e'}, {8, 'h'}};
34 ASSERT_SAME_TYPE(decltype(m.find(0)), typename M::iterator);
35 ASSERT_SAME_TYPE(decltype(std::as_const(m).find(0)), typename M::const_iterator);
36 assert(m.find(0) == m.end());
37 assert(m.find(1) == m.begin());
38 assert(m.find(2) == m.begin() + 1);
39 assert(m.find(3) == m.end());
40 assert(m.find(4) == m.begin() + 2);
41 assert(m.find(5) == m.begin() + 3);
42 assert(m.find(6) == m.end());
43 assert(m.find(7) == m.end());
44 assert(std::as_const(m).find(8) == m.begin() + 4);
45 assert(std::as_const(m).find(9) == m.end());
46}
47
48int main(int, char**) {
49 test<std::vector<int>, std::vector<char>>();
50 test<std::deque<int>, std::vector<char>>();
51 test<MinSequenceContainer<int>, MinSequenceContainer<char>>();
52 test<std::vector<int, min_allocator<int>>, std::vector<char, min_allocator<char>>>();
53
54 return 0;
55}
56

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