flat_multiset_count

flat_multiset_count (std::flat_multiset::count — 원소 개수 세기)

std::flat_multiset에서 지정한 인자와 동등(equivalent) 하게 비교되는 키를 가진 원소의 개수를 세는 멤버 함수예요.

출처: cppreference

본문

시그니처는 다음과 같아요.

size_type count( const Key& key ) const;   // (1) (since C++23)
template< class K >
size_type count( const K& x ) const;       // (2) (since C++23)

(1) 키가 key인 원소의 개수를 반환해요.

(2) x와 동등하게 비교되는 키를 가진 원소의 개수를 반환해요. 이 오버로드는 한정 식별자 Compare::is_transparent가 유효하고 타입을 나타낼 때만 오버로드 해석에 참여해요. Key 인스턴스를 만들지 않고도 이 함수를 호출할 수 있게 해 주는 오버로드예요.

매개변수

  • key: 셀 원소들의 키 값
  • x: 키와 비교할 대체 값

반환값

key 또는 x동등 하게 비교되는 키를 가진 원소의 개수.

복잡도

컨테이너 크기에 대해 로그(logarithmic)에다가 찾은 원소 개수에 선형(linear)이에요.

예제

#include <iostream>
#include <flat_set>
int main()
{
    std::flat_multiset<int> s{1, 2, 3, 2, 4, 2};
    std::cout << s.count(2) << '\n';  // 3
    std::cout << s.count(9) << '\n';  // 0
}

더 알아보기 (Learn more)

cppreference