brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.3 KiB · 051c895 Raw
85 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// bool contains(const key_type& x) const;14 15#include <cassert>16#include <deque>17#include <flat_map>18#include <functional>19#include <utility>20 21#include "MinSequenceContainer.h"22#include "test_macros.h"23#include "min_allocator.h"24 25template <class KeyContainer, class ValueContainer>26constexpr void test() {27  using Key   = typename KeyContainer::value_type;28  using Value = typename ValueContainer::value_type;29  {30    using M = std::flat_map<Key, Value, std::less<>, KeyContainer, ValueContainer>;31    M m     = {{1, 1}, {2, 2}, {4, 4}, {5, 5}, {8, 8}};32    assert(!m.contains(0));33    assert(m.contains(1));34    assert(m.contains(2));35    assert(!m.contains(3));36    assert(m.contains(4));37    assert(m.contains(5));38    assert(!m.contains(6));39    assert(!m.contains(7));40    assert(std::as_const(m).contains(8));41    assert(!std::as_const(m).contains(9));42    m.clear();43    assert(!m.contains(1));44  }45  {46    using M = std::flat_map<Key, Value, std::greater<int>, KeyContainer, ValueContainer>;47    M m     = {{1, 0}, {2, 0}, {4, 0}, {5, 0}, {8, 0}};48    assert(!m.contains(0));49    assert(m.contains(1));50    assert(m.contains(2));51    assert(!m.contains(3));52    assert(m.contains(4));53    assert(m.contains(5));54    assert(!m.contains(6));55    assert(!m.contains(7));56    assert(std::as_const(m).contains(8));57    assert(!std::as_const(m).contains(9));58    m.clear();59    assert(!m.contains(1));60  }61}62 63constexpr bool test() {64  test<std::vector<int>, std::vector<int>>();65#ifndef __cpp_lib_constexpr_deque66  if (!TEST_IS_CONSTANT_EVALUATED)67#endif68  {69    test<std::deque<int>, std::vector<int>>();70  }71  test<MinSequenceContainer<int>, MinSequenceContainer<int>>();72  test<std::vector<int, min_allocator<int>>, std::vector<int, min_allocator<int>>>();73 74  return true;75}76 77int main(int, char**) {78  test();79#if TEST_STD_VER >= 2680  static_assert(test());81#endif82 83  return 0;84}85