brintos

brintos / llvm-project-archived public Read only

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