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

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