flat_map::operator_cmp

flat_map::operator_cmp (비교 연산자)

std::flat_map을 비교하는 연산자들을 모아둔 페이지예요. 원소 단위(사전식) 비교를 수행해요. <flat_map> 헤더, C++23부터.

출처: cppreference

본문

std::flat_map을 비교하는 연산자들이 정의돼 있어요.

template<...>
bool operator==( const std::flat_map<...>& lhs,
                 const std::flat_map<...>& rhs );   // (1)
template<...>
auto operator<=>( const std::flat_map<...>& lhs,
                  const std::flat_map<...>& rhs );  // (2) C++20
  • ==: 같은 키-값 쌍을 같은 순서로 가지면 true.
  • <=>: 사전식 비교로 three-way 결과 반환.

flat_map은 정렬된 순서로 저장되므로, 비교는 키 순서대로 원소를 차례로 비교하는 사전식 규칙을 따라요.

std::flat_map<std::string,int> a{{"a",1},{"b",2}};
std::flat_map<std::string,int> b{{"a",1},{"b",2}};
bool eq = (a == b);   // true

C++20부터 <=>가 제공되고 나머지 비교는 그것으로 파생돼요. std::map과 같은 비교 의미예요.

더 알아보기 (Learn more)

cppreference