brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.3 KiB · 8b034df Raw
89 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_set>12 13// size_type count(const key_type& x) const;14 15#include <cassert>16#include <deque>17#include <flat_set>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>26constexpr void test_one() {27  using Key = typename KeyContainer::value_type;28  using S   = typename KeyContainer::size_type;29 30  {31    using M = std::flat_multiset<Key, std::less<>, KeyContainer>;32    M m     = {1, 2, 2, 2, 2, 4, 4, 5, 8, 8, 8};33    ASSERT_SAME_TYPE(decltype(m.count(0)), S);34    assert(m.count(0) == 0);35    assert(m.count(1) == 1);36    assert(m.count(2) == 4);37    assert(m.count(3) == 0);38    assert(m.count(4) == 2);39    assert(m.count(5) == 1);40    assert(m.count(6) == 0);41    assert(m.count(7) == 0);42    assert(std::as_const(m).count(8) == 3);43    assert(std::as_const(m).count(9) == 0);44  }45  {46    using M = std::flat_multiset<Key, std::greater<int>, KeyContainer>;47    M m     = {1, 2, 4, 4, 4, 4, 5, 5, 8};48    ASSERT_SAME_TYPE(decltype(m.count(0)), S);49    assert(m.count(0) == 0);50    assert(m.count(1) == 1);51    assert(m.count(2) == 1);52    assert(m.count(3) == 0);53    assert(m.count(4) == 4);54    assert(m.count(5) == 2);55    assert(m.count(6) == 0);56    assert(m.count(7) == 0);57    assert(std::as_const(m).count(8) == 1);58    assert(std::as_const(m).count(9) == 0);59  }60  {61    // empty62    using M = std::flat_multiset<Key, std::less<>, KeyContainer>;63    M m;64    assert(m.count(0) == 0);65    assert(m.count(1) == 0);66  }67}68 69constexpr bool test() {70  test_one<std::vector<int>>();71#ifndef __cpp_lib_constexpr_deque72  if (!TEST_IS_CONSTANT_EVALUATED)73#endif74    test_one<std::deque<int>>();75  test_one<MinSequenceContainer<int>>();76  test_one<std::vector<int, min_allocator<int>>>();77 78  return true;79}80 81int main(int, char**) {82  test();83#if TEST_STD_VER >= 2684  static_assert(test());85#endif86 87  return 0;88}89