From 5317a3bad747784498afbaeae59a206c939d169e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Uhl=C3=ADk?= <jan@uhlik.me> Date: Thu, 29 Mar 2018 20:13:25 +0200 Subject: [PATCH] variadic min and max functions --- alib2std/src/extensions/algorithm.hpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/alib2std/src/extensions/algorithm.hpp b/alib2std/src/extensions/algorithm.hpp index a0615c6c39..b86b4eac9e 100644 --- a/alib2std/src/extensions/algorithm.hpp +++ b/alib2std/src/extensions/algorithm.hpp @@ -120,6 +120,26 @@ std::pair < Iterator, Iterator > find_range ( Iterator begin, Iterator end, cons return res; } +template < typename T > +const T & max ( const T & a ) { + return a; +} + +template < typename T, typename ... Args > +const T & max ( const T & a, const T & b, const Args & ... args ) { + return max ( b < a ? a : b, args ... ); +} + +template < typename T > +const T & min ( const T & a) { + return a; +} + +template < typename T, typename ... Args > +const T & min ( const T & a, const T & b, const Args & ... args) { + return min ( b > a ? a : b, args ... ); +} + } /* namespace ext */ #endif /* __ALGORITHM_HPP_ */ -- GitLab