79 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// UNSUPPORTED: c++03, c++11, c++14, c++17, c++2010 11// <flat_map>12 13// class flat_multimap14 15// const key_container_type& keys() const noexcept16// const mapped_container_type& values() const noexcept17 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#include "../helpers.h"32 33template <class KeyContainer, class ValueContainer>34constexpr void test() {35 using Key = typename KeyContainer::value_type;36 using Value = typename ValueContainer::value_type;37 using M = std::flat_multimap<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;38 39 const M m = {{4, 'a'}, {2, 'b'}, {2, 'e'}, {3, 'c'}};40 std::same_as<const KeyContainer&> decltype(auto) keys = m.keys();41 std::same_as<const ValueContainer&> decltype(auto) values = m.values();42 43 // noexcept44 static_assert(noexcept(m.keys()));45 static_assert(noexcept(m.values()));46 47 auto expected_keys = {2, 2, 3, 4};48 assert(std::ranges::equal(keys, expected_keys));49 check_possible_values(50 values,51 std::vector<std::vector<char>>{52 {'b', 'e'},53 {'b', 'e'},54 {'c'},55 {'a'},56 });57}58 59constexpr bool test() {60 test<std::vector<int>, std::vector<char>>();61#ifndef __cpp_lib_constexpr_deque62 if (!TEST_IS_CONSTANT_EVALUATED)63#endif64 test<std::deque<int>, std::vector<char>>();65 test<MinSequenceContainer<int>, MinSequenceContainer<char>>();66 test<std::vector<int, min_allocator<int>>, std::vector<char, min_allocator<char>>>();67 68 return true;69}70 71int main(int, char**) {72 test();73#if TEST_STD_VER >= 2674 static_assert(test());75#endif76 77 return 0;78}79