stack_operator_cmp

stack_operator_cmp (std::stack::operator==,<,... — 비교 연산자)

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

출처: cppreference

본문

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

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

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

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

반환값

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

복잡도

선형(linear)이에요.

예제

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

더 알아보기 (Learn more)

cppreference