SlideShare une entreprise Scribd logo
1  sur  6
Télécharger pour lire hors ligne
Library support for
operator<=>
<compare>
3방향 비교 연산자 (a.k.a 우주선 연산자)
0 : 같음
양수 : 크다
음수 : 작다
<compare> 헤더를 추가해야 사용 가능
단순하고 강력한 비교를 위해 추가 됨
연산자 오버로딩
기존 6개의 비교 연산자
모두 적용됨
default 일 경우 멤버 변수
선언 순서에 따라 비교
연산자 오버로딩
3방향 비교 연산자 반환 타입
3방향 비교 연산자는
strong_ordering, weak_ordering, partial_ordering
중 하나의 타입으로 반환이 됨
~ordering
strong weak partial
less : a < b O O O
equivalent : !(a > b) && !(a < b) ex. insert O O O
equal : a == b ex. find O X X
greater : a > b O O O
unordered : 비교 불가능한 값 지원 ex. Nan X X O
더 강한 순서는 약한 순서로 암묵적 변환이 가능
연산자 오버로딩시 반환 타입을 지정해 줌으로서 어떤
객체인지 알려줄 수도 있다

Contenu connexe

Plus de 진화 손

C++20 Concepts library
C++20 Concepts libraryC++20 Concepts library
C++20 Concepts library진화 손
 
C++20 Coroutine
C++20 CoroutineC++20 Coroutine
C++20 Coroutine진화 손
 
C++ 20 Relaxing the range-for loop customization point finding rules
C++ 20 Relaxing the range-for loop customization point finding rulesC++ 20 Relaxing the range-for loop customization point finding rules
C++ 20 Relaxing the range-for loop customization point finding rules진화 손
 
C++ 20 Relaxing the structured bindings customization point finding rules
C++ 20 Relaxing the structured bindings customization point finding rulesC++ 20 Relaxing the structured bindings customization point finding rules
C++ 20 Relaxing the structured bindings customization point finding rules진화 손
 
C++20 explicit(bool)
C++20 explicit(bool)C++20 explicit(bool)
C++20 explicit(bool)진화 손
 
C++20 std::map::contains
C++20 std::map::containsC++20 std::map::contains
C++20 std::map::contains진화 손
 
C++20 Comparing unordered containers
C++20 Comparing unordered containersC++20 Comparing unordered containers
C++20 Comparing unordered containers진화 손
 
C++20 Attributes [[likely]] and [[unlikely]]
C++20 Attributes [[likely]] and [[unlikely]]C++20 Attributes [[likely]] and [[unlikely]]
C++20 Attributes [[likely]] and [[unlikely]]진화 손
 
C++ 20 Lambdas in unevaluated contexts
C++ 20 Lambdas in unevaluated contextsC++ 20 Lambdas in unevaluated contexts
C++ 20 Lambdas in unevaluated contexts진화 손
 
C++20 Atomic std::shared_ptr and std::weak_ptr
C++20 Atomic std::shared_ptr and std::weak_ptrC++20 Atomic std::shared_ptr and std::weak_ptr
C++20 Atomic std::shared_ptr and std::weak_ptr진화 손
 
C++20 Default member initializers for bit-fields
C++20 Default member initializers for bit-fieldsC++20 Default member initializers for bit-fields
C++20 Default member initializers for bit-fields진화 손
 
C++ 20 constexpr for algorithm and utility
C++ 20 constexpr for  algorithm and utilityC++ 20 constexpr for  algorithm and utility
C++ 20 constexpr for algorithm and utility진화 손
 
C++17 init-statements for if and switch
C++17 init-statements for if and switchC++17 init-statements for if and switch
C++17 init-statements for if and switch진화 손
 
C++17 Aggregate classes with base classes
C++17 Aggregate classes with base classesC++17 Aggregate classes with base classes
C++17 Aggregate classes with base classes진화 손
 
C++17 std::byte
C++17 std::byteC++17 std::byte
C++17 std::byte진화 손
 
C++17 Dynamic memory allocation for over-aligned data
C++17 Dynamic memory allocation for over-aligned dataC++17 Dynamic memory allocation for over-aligned data
C++17 Dynamic memory allocation for over-aligned data진화 손
 
C++17 return type of emplace_ functions of some containers changed from void ...
C++17 return type of emplace_ functions of some containers changed from void ...C++17 return type of emplace_ functions of some containers changed from void ...
C++17 return type of emplace_ functions of some containers changed from void ...진화 손
 
C++17 [[fallthrough]] attribute
C++17 [[fallthrough]] attributeC++17 [[fallthrough]] attribute
C++17 [[fallthrough]] attribute진화 손
 
C++ 17 __has_include in preprocessor conditionals
C++ 17 __has_include in preprocessor conditionalsC++ 17 __has_include in preprocessor conditionals
C++ 17 __has_include in preprocessor conditionals진화 손
 

Plus de 진화 손 (20)

C++20 Concepts library
C++20 Concepts libraryC++20 Concepts library
C++20 Concepts library
 
C++20 Coroutine
C++20 CoroutineC++20 Coroutine
C++20 Coroutine
 
C++ 20 Relaxing the range-for loop customization point finding rules
C++ 20 Relaxing the range-for loop customization point finding rulesC++ 20 Relaxing the range-for loop customization point finding rules
C++ 20 Relaxing the range-for loop customization point finding rules
 
C++ 20 Relaxing the structured bindings customization point finding rules
C++ 20 Relaxing the structured bindings customization point finding rulesC++ 20 Relaxing the structured bindings customization point finding rules
C++ 20 Relaxing the structured bindings customization point finding rules
 
C++20 explicit(bool)
C++20 explicit(bool)C++20 explicit(bool)
C++20 explicit(bool)
 
C++20 std::map::contains
C++20 std::map::containsC++20 std::map::contains
C++20 std::map::contains
 
C++20 Comparing unordered containers
C++20 Comparing unordered containersC++20 Comparing unordered containers
C++20 Comparing unordered containers
 
C++20 Attributes [[likely]] and [[unlikely]]
C++20 Attributes [[likely]] and [[unlikely]]C++20 Attributes [[likely]] and [[unlikely]]
C++20 Attributes [[likely]] and [[unlikely]]
 
C++ 20 Lambdas in unevaluated contexts
C++ 20 Lambdas in unevaluated contextsC++ 20 Lambdas in unevaluated contexts
C++ 20 Lambdas in unevaluated contexts
 
C++20 Atomic std::shared_ptr and std::weak_ptr
C++20 Atomic std::shared_ptr and std::weak_ptrC++20 Atomic std::shared_ptr and std::weak_ptr
C++20 Atomic std::shared_ptr and std::weak_ptr
 
C++20 Default member initializers for bit-fields
C++20 Default member initializers for bit-fieldsC++20 Default member initializers for bit-fields
C++20 Default member initializers for bit-fields
 
C++ 20 constexpr for algorithm and utility
C++ 20 constexpr for  algorithm and utilityC++ 20 constexpr for  algorithm and utility
C++ 20 constexpr for algorithm and utility
 
C++17 init-statements for if and switch
C++17 init-statements for if and switchC++17 init-statements for if and switch
C++17 init-statements for if and switch
 
C++17 Aggregate classes with base classes
C++17 Aggregate classes with base classesC++17 Aggregate classes with base classes
C++17 Aggregate classes with base classes
 
C++17 std::byte
C++17 std::byteC++17 std::byte
C++17 std::byte
 
C++17 not_fn
C++17 not_fnC++17 not_fn
C++17 not_fn
 
C++17 Dynamic memory allocation for over-aligned data
C++17 Dynamic memory allocation for over-aligned dataC++17 Dynamic memory allocation for over-aligned data
C++17 Dynamic memory allocation for over-aligned data
 
C++17 return type of emplace_ functions of some containers changed from void ...
C++17 return type of emplace_ functions of some containers changed from void ...C++17 return type of emplace_ functions of some containers changed from void ...
C++17 return type of emplace_ functions of some containers changed from void ...
 
C++17 [[fallthrough]] attribute
C++17 [[fallthrough]] attributeC++17 [[fallthrough]] attribute
C++17 [[fallthrough]] attribute
 
C++ 17 __has_include in preprocessor conditionals
C++ 17 __has_include in preprocessor conditionalsC++ 17 __has_include in preprocessor conditionals
C++ 17 __has_include in preprocessor conditionals
 

C++20 Library support for operator<=> <compare>

  • 2. 3방향 비교 연산자 (a.k.a 우주선 연산자) 0 : 같음 양수 : 크다 음수 : 작다 <compare> 헤더를 추가해야 사용 가능 단순하고 강력한 비교를 위해 추가 됨
  • 3. 연산자 오버로딩 기존 6개의 비교 연산자 모두 적용됨 default 일 경우 멤버 변수 선언 순서에 따라 비교
  • 5. 3방향 비교 연산자 반환 타입 3방향 비교 연산자는 strong_ordering, weak_ordering, partial_ordering 중 하나의 타입으로 반환이 됨
  • 6. ~ordering strong weak partial less : a < b O O O equivalent : !(a > b) && !(a < b) ex. insert O O O equal : a == b ex. find O X X greater : a > b O O O unordered : 비교 불가능한 값 지원 ex. Nan X X O 더 강한 순서는 약한 순서로 암묵적 변환이 가능 연산자 오버로딩시 반환 타입을 지정해 줌으로서 어떤 객체인지 알려줄 수도 있다