brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.4 KiB · 277abc3 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// size_type count(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  {33    using M = std::flat_multimap<Key, Value, std::less<>, KeyContainer, ValueContainer>;34    M m     = {{1, 1}, {2, 2}, {2, 2}, {4, 4}, {4, 1}, {4, 3}, {4, 4}, {5, 5}, {8, 8}};35    ASSERT_SAME_TYPE(decltype(m.count(0)), size_t);36    assert(m.count(0) == 0);37    assert(m.count(1) == 1);38    assert(m.count(2) == 2);39    assert(m.count(3) == 0);40    assert(m.count(4) == 4);41    assert(m.count(5) == 1);42    assert(m.count(6) == 0);43    assert(m.count(7) == 0);44    assert(std::as_const(m).count(8) == 1);45    assert(std::as_const(m).count(9) == 0);46  }47  {48    using M = std::flat_multimap<Key, Value, std::greater<int>, KeyContainer, ValueContainer>;49    M m     = {{1, 0}, {2, 0}, {4, 0}, {1, 0}, {1, 2}, {8, 1}, {5, 0}, {8, 0}};50    ASSERT_SAME_TYPE(decltype(m.count(0)), size_t);51    assert(m.count(0) == 0);52    assert(m.count(1) == 3);53    assert(m.count(2) == 1);54    assert(m.count(3) == 0);55    assert(m.count(4) == 1);56    assert(m.count(5) == 1);57    assert(m.count(6) == 0);58    assert(m.count(7) == 0);59    assert(std::as_const(m).count(8) == 2);60    assert(std::as_const(m).count(9) == 0);61  }62}63 64constexpr bool test() {65  test<std::vector<int>, std::vector<int>>();66#ifndef __cpp_lib_constexpr_deque67  if (!TEST_IS_CONSTANT_EVALUATED)68#endif69    test<std::deque<int>, std::vector<int>>();70  test<MinSequenceContainer<int>, MinSequenceContainer<int>>();71  test<std::vector<int, min_allocator<int>>, std::vector<int, min_allocator<int>>>();72 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