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// const key_container_type& keys() const noexcept
14// const mapped_container_type& values() const noexcept
15
16#include <algorithm>
17#include <cassert>
18#include <flat_map>
19#include <functional>
20#include <utility>
21#include <vector>
22#include <deque>
23#include <string>
24
25#include "MinSequenceContainer.h"
26#include "test_macros.h"
27#include "test_allocator.h"
28#include "min_allocator.h"
29
30template <class KeyContainer, class ValueContainer>
31void test() {
32 using Key = typename KeyContainer::value_type;
33 using Value = typename ValueContainer::value_type;
34 using M = std::flat_map<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
35
36 const M m = {{4, 'a'}, {2, 'b'}, {3, 'c'}};
37 std::same_as<const KeyContainer&> decltype(auto) keys = m.keys();
38 std::same_as<const ValueContainer&> decltype(auto) values = m.values();
39
40 // noexcept
41 static_assert(noexcept(m.keys()));
42 static_assert(noexcept(m.values()));
43
44 auto expected_keys = {2, 3, 4};
45 auto expected_values = {'b', 'c', 'a'};
46 assert(std::ranges::equal(keys, expected_keys));
47 assert(std::ranges::equal(values, expected_values));
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.map/flat.map.observers/keys_values.pass.cpp