std::error_condition 비교 연산자
std::error_condition 비교 연산자 (operator== 등)
두 std::error_condition을 서로 비교하거나, error_condition과 error_code를 비교하는 연산자들이에요. 오류 조건의 의미적 동등성을 판정해요. C++11부터 있어요.
출처: cppreference
본문
<system_error> 헤더에 정의돼 있고, std::error_condition용 비교 연산자들이에요.
bool operator==( const error_condition& lhs, const error_condition& rhs ) noexcept;
bool operator!=( const error_condition& lhs, const error_condition& rhs ) noexcept;
- 두
error_condition을 비교할 때는 값(value())과 카테고리(category())가 모두 같아야==가true예요. error_condition과error_code를 비교할 때는error_code::default_error_condition()가 그error_condition과 같은지 판정해요. 이를 통해 플랫폼 특정 오류 코드가 표준error_condition과 같은 의미인지 비교할 수 있어요.
예제를 보면요.
#include <system_error>
#include <iostream>
int main()
{
std::error_condition c1 = std::errc::broken_pipe;
std::error_condition c2 = std::make_error_condition(std::errc::broken_pipe);
std::cout << std::boolalpha << (c1 == c2) << '\n'; // true
}
이 연산자 덕분에 여러 오류 시스템의 조건들을 비교해 동일 오류인지 판단할 수 있어요. error_condition은 플랫폼 간 의미 비교를 위한 포팅 가능한 조건이므로, 값·카테고리 일치를 기준으로 동등성이 결정돼요.