deque::operator_cmp

deque::operator_cmp (모든 비교 연산자)

std::deque를 비교하는 비교 연산자들을 모아둔 페이지예요. 원소 단위(lexicographical) 비교를 수행해요. <deque> 헤더에 있어요.

출처: cppreference

본문

std::deque<T, Alloc>을 비교하는 연산자들이 정의돼 있어요.

template< class T, class Alloc >
bool operator==( const std::deque<T, Alloc>& lhs,
                 const std::deque<T, Alloc>& rhs );   // (1)

template< class T, class Alloc >
bool operator<( const std::deque<T, Alloc>& lhs,
                const std::deque<T, Alloc>& rhs );    // (3)

==, !=, <, <=, >, >=가 있었는데, C++20부터는 <=>(three-way)와 ==만 제공되고 나머지는 그것들로부터 파생돼요.

비교는 사전식(lexicographical) 규칙을 따라 앞에서부터 원소를 하나씩 비교해요. ==는 같은 크기이고 모든 원소가 같은지, <는 사전 순서로 작은지 등을 판정해요.

std::deque<int> a{1, 2, 3};
std::deque<int> b{1, 2, 4};
bool less = a < b;   // true

원소 타입 T가 비교 연산자를 지원하면 나머지 비교가 자동으로 동작해요. deque는 크기가 달라도 비교가 가능하고, 사전식 비교로 순서 판정이 자연스러워요.

더 알아보기 (Learn more)

cppreference