flat_map::contains

flat_map::contains (키 존재 확인)

flat_map에 특정 키가 존재하는지 확인하는 멤버 함수예요. <flat_map> 헤더, C++23부터.

출처: cppreference

본문

contains는 컨테이너에 키가 존재하면 true를 반환해요.

bool contains( const Key& key ) const;
template< class K > bool contains( const K& x ) const;
    1. key와 동등한 키가 있으면 true.
    1. 투명 비교를 지원할 때 x와 동등한 키가 있으면 true.
std::flat_map<std::string, int> m{{"a",1},{"b",2}};
bool has = m.contains("a");   // true
bool has2 = m.contains("z");  // false

"키 존재 여부만" 물어볼 때 find != end()보다 읽기 쉬운 함수예요. flat_map은 정렬된 벡터라 contains는 이진 탐색으로 동작해요.

더 알아보기 (Learn more)

cppreference