std::meta::type_order
From cppreference.com
| Defined in header <meta>
|
||
consteval std::strong_ordering type_order( std::meta::info r1, std::meta::info r2 );
|
(since C++26) | |
Performs a three-way comparison on reflected types. The total ordering of all types is implementation-defined.
Returns std::type_order<T1, T2>::value, where T1 and T2 are the types represented by std::meta::dealias(r1) and std::meta::dealias(r2), respectively.
This ordering need not be consistent with the one induced by std::type_info::before.
The template arguments T1 and T2 can be incomplete types.
Parameters
| r1, r2 | - | reflection values |
Return value
The std::strong_ordering value equal to
std::strong_ordering::lessifT1precedesT2in the implementation-defined total order,std::strong_ordering::greaterifT2precedesT1, andstd::strong_ordering::equalif they are the same type.
Exceptions
Throws std::meta::exception if r1 or r2 does not represent a type or type alias.
Example
Run this code
#include <algorithm>
#include <compare>
#include <meta>
#include <print>
#include <vector>
consteval auto sort_types(std::vector<std::meta::info>&& types)
{
std::ranges::sort(types, [](std::meta::info a, std::meta::info b)
{
return std::meta::type_order(a, b) == std::strong_ordering::less;
});
return std::define_static_array(types);
}
int main()
{
static constexpr auto types{ sort_types({^^double, ^^int, ^^char, ^^int}) };
template for (constexpr auto type : types)
std::print("{} ", std::meta::display_string_of(type));
std::println();
}
Possible output:
char double int int
