brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.0 KiB · abd1e98 Raw
141 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// <set>10 11// class set12 13// size_type count(const key_type& k) const;14 15#include <set>16#include <cassert>17 18#include "test_macros.h"19#include "min_allocator.h"20#include "private_constructor.h"21 22int main(int, char**) {23  {24    typedef int V;25    typedef std::set<int> M;26    typedef M::size_type R;27    V ar[] = {5, 6, 7, 8, 9, 10, 11, 12};28    const M m(ar, ar + sizeof(ar) / sizeof(ar[0]));29    R r = m.count(5);30    assert(r == 1);31    r = m.count(6);32    assert(r == 1);33    r = m.count(7);34    assert(r == 1);35    r = m.count(8);36    assert(r == 1);37    r = m.count(9);38    assert(r == 1);39    r = m.count(10);40    assert(r == 1);41    r = m.count(11);42    assert(r == 1);43    r = m.count(12);44    assert(r == 1);45    r = m.count(4);46    assert(r == 0);47  }48#if TEST_STD_VER >= 1149  {50    typedef int V;51    typedef std::set<int, std::less<int>, min_allocator<int>> M;52    typedef M::size_type R;53    V ar[] = {5, 6, 7, 8, 9, 10, 11, 12};54    const M m(ar, ar + sizeof(ar) / sizeof(ar[0]));55    R r = m.count(5);56    assert(r == 1);57    r = m.count(6);58    assert(r == 1);59    r = m.count(7);60    assert(r == 1);61    r = m.count(8);62    assert(r == 1);63    r = m.count(9);64    assert(r == 1);65    r = m.count(10);66    assert(r == 1);67    r = m.count(11);68    assert(r == 1);69    r = m.count(12);70    assert(r == 1);71    r = m.count(4);72    assert(r == 0);73  }74#endif75#if TEST_STD_VER > 1176  {77    typedef int V;78    typedef std::set<int, std::less<>> M;79    typedef M::size_type R;80    V ar[] = {5, 6, 7, 8, 9, 10, 11, 12};81    const M m(ar, ar + sizeof(ar) / sizeof(ar[0]));82    R r = m.count(5);83    assert(r == 1);84    r = m.count(6);85    assert(r == 1);86    r = m.count(7);87    assert(r == 1);88    r = m.count(8);89    assert(r == 1);90    r = m.count(9);91    assert(r == 1);92    r = m.count(10);93    assert(r == 1);94    r = m.count(11);95    assert(r == 1);96    r = m.count(12);97    assert(r == 1);98    r = m.count(4);99    assert(r == 0);100  }101  {102    typedef PrivateConstructor V;103    typedef std::set<V, std::less<>> M;104    typedef M::size_type R;105 106    M m;107    m.insert(V::make(5));108    m.insert(V::make(6));109    m.insert(V::make(7));110    m.insert(V::make(8));111    m.insert(V::make(9));112    m.insert(V::make(10));113    m.insert(V::make(11));114    m.insert(V::make(12));115 116    const M& mc = m;117 118    R r = mc.count(5);119    assert(r == 1);120    r = mc.count(6);121    assert(r == 1);122    r = mc.count(7);123    assert(r == 1);124    r = mc.count(8);125    assert(r == 1);126    r = mc.count(9);127    assert(r == 1);128    r = mc.count(10);129    assert(r == 1);130    r = mc.count(11);131    assert(r == 1);132    r = mc.count(12);133    assert(r == 1);134    r = mc.count(4);135    assert(r == 0);136  }137#endif138 139  return 0;140}141