flat_multimap::count

flat_multimap::count (키 개수 세기)

flat_multimap에서 특정 키와 일치하는 요소의 개수를 반환하는 멤버 함수예요. 중복 키를 허용하므로 0 이상의 값이 돼요. <flat_map> 헤더, C++23부터.

출처: cppreference

본문

count는 특정 키의 요소 개수를 반환해요.

size_type count( const Key& key ) const;
template< class K > size_type count( const K& x ) const;
  • flat_multimap은 중복 키를 허용하므로, 같은 키가 여러 개면 그 개수를 모두 세요.
    1. 투명 비교를 지원할 때 x와 동등한 키를 세요.
std::flat_multimap<std::string, int> m{{"a",1},{"a",2},{"b",3}};
size_t n = m.count("a");   // 2

flat_map::count가 0/1만 반환하는 것과 달리, flat_multimap은 동일 키의 전체 개수를 반환해요.

더 알아보기 (Learn more)

cppreference