66 lines
2.0 KiB
C++
66 lines
2.0 KiB
C++
/**
|
|
This file is a part of our_dick
|
|
Copyright (C) 2020 rexy712
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU Affero General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU Affero General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#ifndef OUR_DICK_UTIL_MINMAX_HPP
|
|
#define OUR_DICK_UTIL_MINMAX_HPP
|
|
|
|
//prevents inclusion of <algorithm> which triples compile times
|
|
|
|
namespace util{
|
|
|
|
template<typename T>
|
|
struct greater {
|
|
constexpr bool operator()(const T& left, const T& right)const{
|
|
return left > right;
|
|
}
|
|
};
|
|
|
|
template<typename T>
|
|
struct less {
|
|
constexpr bool operator()(const T& left, const T& right)const{
|
|
return left < right;
|
|
}
|
|
};
|
|
|
|
template<typename T, typename... Args>
|
|
static constexpr const T& max(const T& left, const T& right, Args&&... args){
|
|
if constexpr(sizeof...(args) > 0){
|
|
return left > right ? max(left, std::forward<Args>(args)...) : max(right, std::forward<Args>(args)...);
|
|
}
|
|
return left > right ? left : right;
|
|
}
|
|
template<typename T, typename... Args>
|
|
static constexpr const T& min(const T& left, const T& right, Args&&... args){
|
|
if constexpr(sizeof...(args) > 0){
|
|
return left < right ? min(left, std::forward<Args>(args)...) : min(right, std::forward<Args>(args)...);
|
|
}
|
|
return left < right ? left : right;
|
|
}
|
|
template<typename T, typename Compare>
|
|
static constexpr T maxc(const T& left, const T& right, Compare cmp){
|
|
return cmp(left, right) ? left : right;
|
|
}
|
|
template<typename T, typename Compare>
|
|
static constexpr T minc(const T& left, const T& right, Compare cmp){
|
|
return cmp(left, right) ? left : right;
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|