-
Notifications
You must be signed in to change notification settings - Fork 0
/
brick-order
52 lines (41 loc) · 2.1 KB
/
brick-order
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 4 -*-
/*
* (c) 2019 Petr Ročkai <[email protected]>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#pragma once
namespace brq
{
struct derive_eq {};
struct derive_ord {};
template< typename T >
constexpr bool is_eq_v = std::is_base_of_v< derive_eq, T >;
template< typename T >
constexpr bool is_ord_v = std::is_base_of_v< derive_ord, T >;
template< typename T > using eq_t = std::enable_if_t< is_eq_v< T >, bool >;
template< typename T > using ord_t = std::enable_if_t< is_ord_v< T >, bool >;
template< typename T > eq_t< T > operator!=( const T &a, const T &b ) { return not ( a == b ); }
template< typename T > std::enable_if_t< !is_eq_v< T > && is_ord_v< T >, bool >
operator!=( const T &a, const T &b ) { return a < b || b < a; }
template< typename T > std::enable_if_t< !is_eq_v< T > && is_ord_v< T >, bool >
operator==( const T &a, const T &b ) { return not ( a != b ); }
template< typename T > ord_t< T > operator> ( const T &a, const T &b ) { return b < a; }
template< typename T > ord_t< T > operator>=( const T &a, const T &b ) { return not ( a < b ); }
template< typename T > ord_t< T > operator<=( const T &a, const T &b ) { return not ( b < a ); }
template< typename T >
auto operator<( const T &a, const T &b ) -> decltype( a.as_tuple() < b.as_tuple() )
{
return a.as_tuple() < b.as_tuple();
}
}