37 #define __ADS_OrderKey
60struct IsNumberPair : std::false_type
63template<
class A ,
class B >
64struct IsNumberPair< std::pair< A , B > >
65 : std::bool_constant< RadixKey< A > && RadixKey< B > &&
66 ( sizeof( A ) + sizeof( B ) <= 8 ) >
71concept OrderKeyed = RadixKey< T > || IsNumberPair< T >::value;
74template< class T , class C >
75inline constexpr bool kAscending =
76 std::is_same_v< C , std::less<> > || std::is_same_v< C , std::less< T > >;
78template< class T , class C >
79inline constexpr bool kDescending = std::is_same_v< C , std::greater<> > ||
80 std::is_same_v< C , std::greater< T > >;
83template< class T , class C >
84inline constexpr bool kKeyed =
85 OrderKeyed< T > && ( kAscending< T , C > || kDescending< T , C > );
88template< OrderKeyed T >
89[[nodiscard]] inline auto orderKey( const T & x )
91 if constexpr( RadixKey< T > )
92 return( radixKey( x ) );
94 using A = typename T::first_type;
95 using B = typename T::second_type;
96 using U = std::conditional_t< sizeof( A ) + sizeof( B ) <= 4 ,
99 return( U( ( U( radixKey( x.first ) ) << ( 8 * sizeof( B ) ) ) |
100 U( radixKey( x.second ) ) ) );
105template< class C , class T >
106 requires kKeyed< T , C >
107[[nodiscard]] inline auto orderKeyBy( const T & x )
109 const auto k = orderKey( x );
110 if constexpr( kDescending< T , C > )
111 return( decltype( k )( ~k ) );
The sorts by the digits of the keys, beyond the book (which has Counting Sort and Pigeonhole Sort,...