Embedded Template Library 1.0
Loading...
Searching...
No Matches
compare.h
Go to the documentation of this file.
1
2
3/******************************************************************************
4The MIT License(MIT)
5
6Embedded Template Library.
7https://github.com/ETLCPP/etl
8https://www.etlcpp.com
9
10Copyright(c) 2017 John Wellbelove
11
12Permission is hereby granted, free of charge, to any person obtaining a copy
13of this software and associated documentation files(the "Software"), to deal
14in the Software without restriction, including without limitation the rights
15to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
16copies of the Software, and to permit persons to whom the Software is
17furnished to do so, subject to the following conditions :
18
19The above copyright notice and this permission notice shall be included in all
20copies or substantial portions of the Software.
21
22THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
25AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28SOFTWARE.
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//*****************************************************************************
43namespace 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
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 {
109 }
110}
111
112#endif
bitset_ext
Definition absolute.h:38
ETL_CONSTEXPR14 int three_way_compare(const T &lhs, const T &rhs)
Default implementation of TLess is etl::less.
Definition compare.h:106
Definition compare.h:51
pair holds two objects of arbitrary type
Definition utility.h:164