forward_list_operator_cmp

forward_list_operator_cmp (std::forward_list::operator==,<,... — 비교 연산자)

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

출처: cppreference

본문

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

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

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

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

반환값

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

복잡도

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

예제

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

더 알아보기 (Learn more)

cppreference