root/core/max_min.hpp

/* [<][>][^][v][top][bottom][index][help] */

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. varadic_max
  2. varadic_max
  3. varadic_min
  4. varadic_min

   1 #ifndef libjmmcg_core_max_min_hpp
   2 #define libjmmcg_core_max_min_hpp
   3 
   4 /******************************************************************************
   5 ** $Header: svn+ssh://jmmcg@svn.code.sf.net/p/libjmmcg/code/trunk/libjmmcg/core/max_min.hpp 2236 2017-12-26 10:18:08Z jmmcg $
   6 **
   7 ** Copyright © 2013 by J.M.McGuiness, coder@hussar.me.uk
   8 **
   9 ** This library is free software; you can redistribute it and/or
  10 ** modify it under the terms of the GNU Lesser General Public
  11 ** License as published by the Free Software Foundation; either
  12 ** version 2.1 of the License, or (at your option) any later version.
  13 **
  14 ** This library is distributed in the hope that it will be useful,
  15 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  16 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17 ** Lesser General Public License for more details.
  18 **
  19 ** You should have received a copy of the GNU Lesser General Public
  20 ** License along with this library; if not, write to the Free Software
  21 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  22 */
  23 
  24 namespace jmmcg {
  25 
  26 template<class Val, Val l, Val r>
  27 struct min {
  28         enum : Val {
  29                 value=(l<r ? l : r)
  30         };
  31 };
  32 template<class Val, Val l, Val r>
  33 struct max {
  34         enum : Val {
  35                 value=(l>r ? l : r)
  36         };
  37 };
  38 
  39 /// Work around the fact that there is no parameter-pack version of std::max(...). *sigh* C++ is great, no?
  40 /**
  41         See <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2772.pdf">Variadic functions: Variadic templates or initializer lists? -- Revision 1</a>.
  42 */
  43 template<class V> 
  44 inline constexpr V
  45 varadic_max(V v) noexcept(true) {
  46         return v;
  47 }
  48 template<class V, class... Values> 
  49 inline constexpr V
  50 varadic_max(V v, Values... values) noexcept(true) { 
  51         return std::max(varadic_max(values...), v);
  52 }
  53 
  54 template<class V> 
  55 inline constexpr V
  56 varadic_min(V v) noexcept(true) {
  57         return v;
  58 }
  59 template<class V, class... Values> 
  60 inline constexpr V
  61 varadic_min(V v, Values... values) noexcept(true) { 
  62         return std::min(varadic_min(values...), v);
  63 }
  64 
  65 }
  66 
  67 #endif

/* [<][>][^][v][top][bottom][index][help] */