brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.0 KiB · 6b98c11 Raw
72 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// const key_container_type& keys() const noexcept14// const mapped_container_type& values() const noexcept15 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>31constexpr void 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  // noexcept41  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 50constexpr bool test() {51  test<std::vector<int>, std::vector<char>>();52#ifndef __cpp_lib_constexpr_deque53  if (!TEST_IS_CONSTANT_EVALUATED)54#endif55  {56    test<std::deque<int>, std::vector<char>>();57  }58  test<MinSequenceContainer<int>, MinSequenceContainer<char>>();59  test<std::vector<int, min_allocator<int>>, std::vector<char, min_allocator<char>>>();60 61  return true;62}63 64int main(int, char**) {65  test();66#if TEST_STD_VER >= 2667  static_assert(test());68#endif69 70  return 0;71}72