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// const key_container_type& keys() const noexcept
16// const mapped_container_type& values() const noexcept
17
18#include <algorithm>
19#include <cassert>
20#include <flat_map>
21#include <functional>
22#include <utility>
23#include <vector>
24#include <deque>
25#include <string>
26
27#include "MinSequenceContainer.h"
28#include "test_macros.h"
29#include "test_allocator.h"
30#include "min_allocator.h"
31
32template <class KeyContainer, class ValueContainer>
33void test() {
34 using Key = typename KeyContainer::value_type;
35 using Value = typename ValueContainer::value_type;
36 using M = std::flat_multimap<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
37
38 const M m = {{4, 'a'}, {2, 'b'}, {2, 'e'}, {3, 'c'}};
39 std::same_as<const KeyContainer&> decltype(auto) keys = m.keys();
40 std::same_as<const ValueContainer&> decltype(auto) values = m.values();
41
42 // noexcept
43 static_assert(noexcept(m.keys()));
44 static_assert(noexcept(m.values()));
45
46 auto expected_keys = {2, 2, 3, 4};
47 auto expected_values = {'b', 'e', 'c', 'a'};
48 assert(std::ranges::equal(keys, expected_keys));
49 assert(std::ranges::equal(values, expected_values));
50}
51
52int main(int, char**) {
53 test<std::vector<int>, std::vector<char>>();
54 test<std::deque<int>, std::vector<char>>();
55 test<MinSequenceContainer<int>, MinSequenceContainer<char>>();
56 test<std::vector<int, min_allocator<int>>, std::vector<char, min_allocator<char>>>();
57
58 return 0;
59}
60

source code of libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.observers/keys_values.pass.cpp