flat_multiset_contains

flat_multiset_contains (std::flat_multiset::contains — 포함 여부 확인)

std::flat_multiset에 특정 키와 동등한 원소가 있는지 확인하는 멤버 함수예요. 투명 비교자를 쓰면 Key 인스턴스를 만들지 않고 값을 기준으로 확인할 수 있어요.

출처: cppreference

본문

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

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

(1) 컨테이너에 key와 동등한 키를 가진 원소가 있는지 확인해요.

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

매개변수

  • key: 찾을 원소의 키 값
  • x: 키와 투명하게 비교할 수 있는 어떤 타입의 값

반환값

그런 원소가 있으면 true, 없으면 false.

복잡도

컨테이너 크기에 대해 로그(logarithmic)예요.

예제

#include <iostream>
#include <flat_set>
int main()
{
    std::flat_multiset<int> example{1, 2, 3, 4};
    for (int x : {2, 5})
    {
        if (example.contains(x))
            std::cout << x << " found\n";
        else
            std::cout << x << " not found\n";
    }
}

더 알아보기 (Learn more)

cppreference