Embedded Template Library
1.0
Loading...
Searching...
No Matches
compare.h
Go to the documentation of this file.
1
2
3
/******************************************************************************
4
The MIT License(MIT)
5
6
Embedded Template Library.
7
https://github.com/ETLCPP/etl
8
https://www.etlcpp.com
9
10
Copyright(c) 2017 John Wellbelove
11
12
Permission is hereby granted, free of charge, to any person obtaining a copy
13
of this software and associated documentation files(the "Software"), to deal
14
in the Software without restriction, including without limitation the rights
15
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
16
copies of the Software, and to permit persons to whom the Software is
17
furnished to do so, subject to the following conditions :
18
19
The above copyright notice and this permission notice shall be included in all
20
copies or substantial portions of the Software.
21
22
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
25
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28
SOFTWARE.
29
******************************************************************************/
30
31
#ifndef ETL_COMPARE_INCLUDED
32
#define ETL_COMPARE_INCLUDED
33
34
#include "
platform.h
"
35
#include "
parameter_type.h
"
36
#include "
functional.h
"
37
38
//*****************************************************************************
42
//*****************************************************************************
43
namespace
etl
44
{
45
//***************************************************************************
48
//***************************************************************************
49
template
<
typename
T,
typename
TLess = etl::less<T> >
50
struct
compare
51
{
52
enum
cmp_result
53
{
54
Less = -1,
55
Equal = 0,
56
Greater = 1
57
};
58
59
typedef
typename
etl::parameter_type<T>::type
first_argument_type
;
60
typedef
typename
etl::parameter_type<T>::type
second_argument_type
;
61
62
static
ETL_CONSTEXPR
bool
lt(
first_argument_type
lhs
,
second_argument_type
rhs
)
63
{
64
return
TLess
()(
lhs
,
rhs
);
65
}
66
67
static
ETL_CONSTEXPR
bool
gt(
first_argument_type
lhs
,
second_argument_type
rhs
)
68
{
69
return
TLess
()(
rhs
,
lhs
);
70
}
71
72
static
ETL_CONSTEXPR
bool
lte(
first_argument_type
lhs
,
second_argument_type
rhs
)
73
{
74
return
!gt(
lhs
,
rhs
);
75
}
76
77
static
ETL_CONSTEXPR
bool
gte(
first_argument_type
lhs
,
second_argument_type
rhs
)
78
{
79
return
!lt(
lhs
,
rhs
);
80
}
81
82
static
ETL_CONSTEXPR
bool
eq(
first_argument_type
lhs
,
second_argument_type
rhs
)
83
{
84
return
gte(
lhs
,
rhs
) && lte(
lhs
,
rhs
);
85
}
86
87
static
ETL_CONSTEXPR
bool
ne(
first_argument_type
lhs
,
second_argument_type
rhs
)
88
{
89
return
!eq(
lhs
,
rhs
);
90
}
91
92
static
ETL_CONSTEXPR cmp_result cmp(
first_argument_type
lhs
,
second_argument_type
rhs
)
93
{
94
return
lt(
lhs
,
rhs
) ? Less : gt(
lhs
,
rhs
) ? Greater : Equal;
95
}
96
};
97
98
//***************************************************************************
100
//***************************************************************************
101
#if ETL_USING_CPP11
102
template
<
typename
T,
typename
TLess = etl::less<T> >
103
#else
104
template
<
typename
T,
typename
TLess>
105
#endif
106
ETL_CONSTEXPR14
int
three_way_compare
(
const
T
&
lhs
,
const
T
&
rhs
)
107
{
108
return
etl::compare<T>::cmp
(
lhs
,
rhs
);
109
}
110
}
111
112
#endif
functional.h
etl
bitset_ext
Definition
absolute.h:38
etl::three_way_compare
ETL_CONSTEXPR14 int three_way_compare(const T &lhs, const T &rhs)
Default implementation of TLess is etl::less.
Definition
compare.h:106
parameter_type.h
platform.h
etl::compare
Definition
compare.h:51
etl::pair
pair holds two objects of arbitrary type
Definition
utility.h:164
include
etl
compare.h
Generated on Thu Jan 2 2025 19:14:45 for Embedded Template Library by
1.9.8