Stefan Scholz / ETL
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers compare.h Source File

compare.h

Go to the documentation of this file.
00001 ///\file
00002 
00003 /******************************************************************************
00004 The MIT License(MIT)
00005 
00006 Embedded Template Library.
00007 https://github.com/ETLCPP/etl
00008 https://www.etlcpp.com
00009 
00010 Copyright(c) 2017 jwellbelove
00011 
00012 Permission is hereby granted, free of charge, to any person obtaining a copy
00013 of this software and associated documentation files(the "Software"), to deal
00014 in the Software without restriction, including without limitation the rights
00015 to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
00016 copies of the Software, and to permit persons to whom the Software is
00017 furnished to do so, subject to the following conditions :
00018 
00019 The above copyright notice and this permission notice shall be included in all
00020 copies or substantial portions of the Software.
00021 
00022 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00023 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00024 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
00025 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00026 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00027 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
00028 SOFTWARE.
00029 ******************************************************************************/
00030 
00031 #ifndef __ETL_COMPARE__
00032 #define __ETL_COMPARE__
00033 
00034 #include <functional>
00035 
00036 #include "platform.h "
00037 #include "parameter_type.h "
00038 
00039 //*****************************************************************************
00040 ///\defgroup compare compare
00041 /// Comparisons only using less than operator
00042 ///\ingroup utilities
00043 //*****************************************************************************
00044 
00045 namespace etl
00046 {
00047   //***************************************************************************
00048   /// Defines <=, >, >= interms of <
00049   /// Default 
00050   //***************************************************************************
00051   template <typename T, typename TLess = std::less<T> >
00052   struct compare
00053   {
00054     typedef typename etl::parameter_type<T>::type first_argument_type;
00055     typedef typename etl::parameter_type<T>::type second_argument_type;
00056     typedef bool result_type;
00057 
00058     static result_type lt(first_argument_type lhs, second_argument_type rhs)
00059     {
00060       return TLess()(lhs, rhs);
00061     }
00062 
00063     static result_type gt(first_argument_type lhs, second_argument_type rhs)
00064     {
00065       return TLess()(rhs, lhs);
00066     }
00067 
00068     static result_type lte(first_argument_type lhs, second_argument_type rhs)
00069     {
00070       return !gt(lhs, rhs);
00071     }
00072 
00073     static result_type gte(first_argument_type lhs, second_argument_type rhs)
00074     {
00075       return !lt(lhs, rhs);
00076     }
00077   };
00078 }
00079 
00080 #endif
00081