libjmmcg
release_579_6_g8cffd
A C++ library containing an eclectic mix of useful, advanced components.
max_min.hpp
Go to the documentation of this file.
1
#
ifndef
LIBJMMCG_CORE_MIN_MAX_HPP
2
#
define
LIBJMMCG_CORE_MIN_MAX_HPP
3
4
/******************************************************************************
5
** Copyright © 2013 by J.M.McGuiness, coder@hussar.me.uk
6
**
7
** This library is free software; you can redistribute it and/or
8
** modify it under the terms of the GNU Lesser General Public
9
** License as published by the Free Software Foundation; either
10
** version 2.1 of the License, or (at your option) any later version.
11
**
12
** This library is distributed in the hope that it will be useful,
13
** but WITHOUT ANY WARRANTY; without even the implied warranty of
14
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
** Lesser General Public License for more details.
16
**
17
** You should have received a copy of the GNU Lesser General Public
18
** License along with this library; if not, write to the Free Software
19
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
*/
21
22
namespace
jmmcg
{
namespace
LIBJMMCG_VER_NAMESPACE
{
23
24
template
<
class
Val, Val l, Val r>
25
struct
min
{
26
enum
: Val {
27
value
=(l<r ? l : r)
28
};
29
};
30
template
<
class
Val, Val l, Val r>
31
struct
max
{
32
enum
: Val {
33
value
=(l>r ? l : r)
34
};
35
};
36
37
/// Work around the fact that there is no parameter-pack version of std::max(...). *sigh* C++ is great, no?
38
/**
39
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>.
40
*/
41
template
<
class
V>
42
inline
constexpr
V
43
varadic_max
(V v)
noexcept
(
true
) {
44
return
v;
45
}
46
template
<
class
V,
class
... Values>
47
inline
constexpr
V
48
varadic_max
(V v, Values... values)
noexcept
(
true
) {
49
return
std
::max(varadic_max(values...), v);
50
}
51
52
template
<
class
V>
53
inline
constexpr
V
54
varadic_min
(V v)
noexcept
(
true
) {
55
return
v;
56
}
57
template
<
class
V,
class
... Values>
58
inline
constexpr
V
59
varadic_min
(V v, Values... values)
noexcept
(
true
) {
60
return
std
::min(varadic_min(values...), v);
61
}
62
63
} }
64
65
#
endif
core
max_min.hpp
Generated on Tue May 11 2021 17:16:30 for libjmmcg by
1.9.2