GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
std::compare_three_way_result(3) C++ Standard Libary std::compare_three_way_result(3)

std::compare_three_way_result - std::compare_three_way_result


Defined in header <compare>
template<class T, class U = T> (since C++20)
struct compare_three_way_result;


Let t and u denote lvalue of const std::remove_reference_t<T> and const
std::remove_reference_t<U> respectively, if the expression t <=> u is well-formed,
provides the member typedef type equal to decltype(t <=> u), otherwise there is no
member type.


The behavior of a program that adds specializations for compare_three_way_result is
undefined.


Name Definition
type the result type of operator<=> on const-qualified lvalue of T and U


template<class T, class U = T>
using compare_three_way_result_t = typename (since C++20)
compare_three_way_result<T, U>::type;


// recommended by Casey Carter
// see also: https://github.com/microsoft/STL/pull/385#discussion_r357894054
template<class T, class U = T>
using compare_three_way_result_t = decltype(
std::declval<const std::remove_reference_t<T>&>() <=>
std::declval<const std::remove_reference_t<U>&>()
);


template<class T, class U = T>
struct compare_three_way_result {};


template<class T, class U>
requires requires { typename compare_three_way_result_t<T, U>; }
struct compare_three_way_result<T, U> {
using type = compare_three_way_result_t<T, U>;
};

// Run this code


#include <compare>
#include <type_traits>
#include <iostream>


template <class Ord>
void print_cmp_type()
{
if constexpr (std::is_same_v<Ord, std::strong_ordering>)
std::cout << "strong ordering\n";
else if constexpr (std::is_same_v<Ord, std::weak_ordering>)
std::cout << "weak ordering\n";
else if constexpr (std::is_same_v<Ord, std::partial_ordering>)
std::cout << "partial ordering\n";
else
std::cout << "illegal comparison result type\n";
}


int main()
{
print_cmp_type<std::compare_three_way_result_t<int>>();
print_cmp_type<std::compare_three_way_result_t<double>>();
}


strong ordering
partial ordering


partial_ordering the result type of 3-way comparison that supports all 6 operators,
(C++20) is not substitutable, and allows incomparable values
(class)
weak_ordering the result type of 3-way comparison that supports all 6 operators
(C++20) and is not substitutable
(class)
strong_ordering the result type of 3-way comparison that supports all 6 operators
(C++20) and is substitutable
(class)

2022.07.31 http://cppreference.com

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.