Namespaces
Variants

operator==,!=,<,<=,>,>=,<=> (std::basic_string)

From cppreference.net
std::basic_string
Constants
Non-member functions
I/O
Comparison
operator== operator!= operator< operator> operator<= operator>= operator<=>
(until C++20) (until C++20) (until C++20) (until C++20) (until C++20) (C++20)
Numeric conversions
(C++11) (C++11) (C++11)
(C++11) (C++11)
(C++11) (C++11) (C++11)
(C++11)
(C++11)
Literals
Helper classes
Deduction guides (C++17)
헤더에 정의됨 <string>
두 개의 basic_string 객체 비교
template < class CharT, class Traits, class Alloc >

bool operator == ( const std:: basic_string < CharT,Traits,Alloc > & lhs,

const std:: basic_string < CharT,Traits,Alloc > & rhs ) ;
(1) (C++11부터 noexcept)
(C++20부터 constexpr)
template < class CharT, class Traits, class Alloc >

bool operator ! = ( const std:: basic_string < CharT,Traits,Alloc > & lhs,

const std:: basic_string < CharT,Traits,Alloc > & rhs ) ;
(2) (C++20 이전)
(C++11부터 noexcept)
template < class CharT, class Traits, class Alloc >

bool operator < ( const std:: basic_string < CharT,Traits,Alloc > & lhs,

const std:: basic_string < CharT,Traits,Alloc > & rhs ) ;
(3) (C++20 이전)
(C++11부터 noexcept)
template < class CharT, class Traits, class Alloc >

bool operator <= ( const std:: basic_string < CharT,Traits,Alloc > & lhs,

const std:: basic_string < CharT,Traits,Alloc > & rhs ) ;
(4) (C++20 이전)
(C++11부터 noexcept)
template < class CharT, class Traits, class Alloc >

bool operator > ( const std:: basic_string < CharT,Traits,Alloc > & lhs,

const std:: basic_string < CharT,Traits,Alloc > & rhs ) ;
(5) (C++20 이전)
(C++11부터 noexcept)
template < class CharT, class Traits, class Alloc >

bool operator >= ( const std:: basic_string < CharT,Traits,Alloc > & lhs,

const std:: basic_string < CharT,Traits,Alloc > & rhs ) ;
(6) (C++20 이전)
(C++11부터 noexcept)
template < class CharT, class Traits, class Alloc >

constexpr /*comp-cat*/
operator <=> ( const std:: basic_string < CharT,Traits,Alloc > & lhs,

const std:: basic_string < CharT,Traits,Alloc > & rhs ) noexcept ;
(7) (C++20부터)
basic_string 객체와 null로 종료된 T 배열 비교
template < class CharT, class Traits, class Alloc >

bool operator == ( const std:: basic_string < CharT,Traits,Alloc > & lhs,

const CharT * rhs ) ;
(8) (C++20부터 constexpr)
template < class CharT, class Traits, class Alloc >

bool operator == ( const CharT * lhs,

const std:: basic_string < CharT,Traits,Alloc > & rhs ) ;
(9) (C++20 이전)
template < class CharT, class Traits, class Alloc >

bool operator ! = ( const std:: basic_string < CharT,Traits,Alloc > & lhs,

const CharT * rhs ) ;
(10) (C++20 이전)
template < class CharT, class Traits, class Alloc >

bool operator ! = ( const CharT * lhs,

const std:: basic_string < CharT,Traits,Alloc > & rhs ) ;
(11) (C++20 이전)
template < class CharT, class Traits, class Alloc >

bool operator < ( const std:: basic_string < CharT,Traits,Alloc > & lhs,

const CharT * rhs ) ;
(12) (C++20 이전)
template < class CharT, class Traits, class Alloc >

bool operator < ( const CharT * lhs,

const std:: basic_string < CharT,Traits,Alloc > & rhs ) ;
(13) (C++20 이전)
template < class CharT, class Traits, class Alloc >

bool operator <= ( const std:: basic_string < CharT,Traits,Alloc > & lhs,

const CharT * rhs ) ;
(14) (C++20 이전)
template < class CharT, class Traits, class Alloc >

bool operator <= ( const CharT * lhs,

const std:: basic_string < CharT,Traits,Alloc > & rhs ) ;
(15) (C++20 이전)
template < class CharT, class Traits, class Alloc >

bool operator > ( const std:: basic_string < CharT,Traits,Alloc > & lhs,

const CharT * rhs ) ;
(16) (C++20 이전)
template < class CharT, class Traits, class Alloc >

bool operator > ( const CharT * lhs,

const std:: basic_string < CharT,Traits,Alloc > & rhs ) ;
(17) (C++20 이전)
template < class CharT, class Traits, class Alloc >

bool operator >= ( const std:: basic_string < CharT,Traits,Alloc > & lhs,

const CharT * rhs ) ;
(18) (C++20 이전)
template < class CharT, class Traits, class Alloc >

bool operator >= ( const CharT * lhs,

const std:: basic_string < CharT,Traits,Alloc > & rhs ) ;
(19) (C++20 이전)
template < class CharT, class Traits, class Alloc >

constexpr /*비교-범주*/
operator <=> ( const std:: basic_string < CharT,Traits,Alloc > & lhs,

const CharT * rhs ) ;
(20) (C++20부터)

문자열의 내용을 다른 문자열 또는 null로 종료된 CharT 배열과 비교합니다.

모든 비교는 compare() 멤버 함수를 통해 수행됩니다 (이 함수 자체는 Traits::compare() 를 기반으로 정의됩니다):

  • 두 문자열은 lhs rhs 의 크기가 모두 같고, lhs 의 각 문자가 동일한 위치의 rhs 에서 해당하는 문자와 동일할 때 서로 같습니다.
1-7) 두 개의 basic_string 객체를 비교합니다.
8-20) basic_string 객체와 null-terminated CharT 배열을 비교합니다.

3-way 비교 연산자( /*comp-cat*/ )의 반환 타입은 Traits :: comparison_category 이 해당 한정자 ID가 존재하고 타입을 나타낼 경우 해당 타입이며, 그렇지 않을 경우 std::weak_ordering 입니다. /*comp-cat*/ 이 비교 범주 타입이 아닐 경우 프로그램은 ill-formed입니다.

< , <= , > , >= , 및 != 연산자는 각각 합성됩니다 ( operator <=> operator == 로부터).

(C++20부터)

목차

매개변수

lhs, rhs - 비교할 내용을 가진 문자열들

반환값

1-6,8-19) true 해당 비교가 성립하는 경우, false 그렇지 않은 경우.
7,20) static_cast < /*comp-cat*/ > ( lhs. compare ( rhs ) <=> 0 ) .

복잡도

문자열의 크기에 선형적으로 비례합니다.

참고 사항

최소한 하나의 매개변수가 std::string , std::wstring , std::u8string , std::u16string , 또는 std::u32string 타입인 경우, operator<=> 의 반환 타입은 std::strong_ordering 입니다.

(since C++20)

예제

결함 보고서

다음의 동작 변경 결함 보고서들은 이전에 발표된 C++ 표준에 소급 적용되었습니다.

DR 적용 대상 게시된 동작 올바른 동작
LWG 2064 C++11 두 개의 basic_string 을 취하는 오버로드의 noexcept 여부가 일관되지 않았음;
CharT* 를 취하는 오버로드는 noexcept였지만 UB를 발생시킬 수 있었음
일관되게 수정됨;
noexcept 제거됨
LWG 3432 C++20 operator<=> 의 반환 타입이 비교 범주 타입일 필요가 없었음 필수로 지정됨