multimap_operator_cmp

multimap_operator_cmp (std::multimap::operator==,<,... — 비교 연산자)

std::multimap을 사전식(lexicographically)으로 비교하는 비멤버 연산자 함수들이에요.

출처: cppreference

본문

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

template< class Key, class T, class Compare, class Alloc >
bool operator==( const std::multimap<Key, T, Compare, Alloc>& lhs,
                 const std::multimap<Key, T, Compare, Alloc>& rhs );   // (1)
template< class Key, class T, class Compare, class Alloc >
bool operator!=( ... );     // (until C++20)
template< class Key, class T, class Compare, class Alloc >
bool operator<( ... );      // (until C++20)
template< class Key, class T, class Compare, class Alloc >
bool operator<=>( const std::multimap<Key, T, Compare, Alloc>& lhs,
                  const std::multimap<Key, T, Compare, Alloc>& rhs );  // (since C++20)

두 컨테이너의 내용을 사전식으로 비교해요.

  • operator==: 두 컨테이너의 원소 개수가 같고 각 위치의 원소가 같으면 true.
  • C++20부터는 operator!=, <, <=, >, >=operator<=>(삼중 비교)와 operator==에서 파생돼요.

반환값

  • (1) lhs의 원소들이 rhs와 같으면 true.
  • 그 외 각 연산자에 해당하는 비교 결과.

복잡도

두 컨테이너 크기가 다르면 operator==는 상수, 그 외에는 컨테이너 크기에 선형.

예제

#include <iostream>
#include <map>
int main()
{
    std::multimap<int, char> a{{1, 'a'}, {2, 'b'}};
    std::multimap<int, char> b{{1, 'a'}, {2, 'b'}};
    std::cout << std::boolalpha << (a == b) << '\n';   // true
}

더 알아보기 (Learn more)

cppreference