L4Re Operating System Framework
Interface and Usage Documentation
Loading...
Searching...
No Matches
minmax
1
// vi:set ft=cpp: -*- Mode: C++ -*-
2
/*
3
* (c) 2008-2009 Alexander Warg <warg@os.inf.tu-dresden.de>
4
* economic rights: Technische Universität Dresden (Germany)
5
*
6
* This file is part of TUD:OS and distributed under the terms of the
7
* GNU General Public License 2.
8
* Please see the COPYING-GPL-2 file for details.
9
*
10
* As a special exception, you may use this file as part of a free software
11
* library without restriction. Specifically, if other files instantiate
12
* templates or use macros or inline functions from this file, or you compile
13
* this file and link it with other files to produce an executable, this
14
* file does not by itself cause the resulting executable to be covered by
15
* the GNU General Public License. This exception does not however
16
* invalidate any other reasons why the executable file might be covered by
17
* the GNU General Public License.
18
*/
19
#pragma once
20
21
#include "type_traits"
22
27
namespace
cxx
28
{
29
// trivial, used to terminate the variadic recursion
30
template
<
typename
A>
31
constexpr
A
const
&
32
min(A
const
&a)
33
{
return
a; }
34
45
template
<
typename
A,
typename
...ARGS>
46
constexpr
A
const
&
47
min(A
const
&a1, A
const
&a2, ARGS
const
&...a)
48
{
49
return
min((a1 <= a2) ? a1 : a2, a...);
50
}
51
62
template
<
typename
A,
typename
...ARGS>
63
constexpr
A
const
&
64
min(cxx::identity_t<A>
const
&a1,
65
cxx::identity_t<A>
const
&a2,
66
ARGS
const
&...a)
67
{
68
return
min<A>((a1 <= a2) ? a1 : a2, a...);
69
}
70
71
// trivial, used to terminate the variadic recursion
72
template
<
typename
A>
73
constexpr
A
const
&
74
max(A
const
&a)
75
{
return
a; }
76
87
template
<
typename
A,
typename
...ARGS>
88
constexpr
A
const
&
89
max(A
const
&a1, A
const
&a2, ARGS
const
&...a)
90
{
return
max((a1 >= a2) ? a1 : a2, a...); }
91
102
template
<
typename
A,
typename
...ARGS>
103
constexpr
A
const
&
104
max(cxx::identity_t<A>
const
&a1,
105
cxx::identity_t<A>
const
&a2,
106
ARGS
const
&...a)
107
{
108
return
max<A>((a1 >= a2) ? a1 : a2, a...);
109
}
110
118
template
<
typename
T1 >
119
inline
120
T1
clamp
(T1 v, T1 lo, T1 hi)
121
{
return
min(hi, max(lo, v)); }
122
};
cxx::clamp
T1 clamp(T1 v, T1 lo, T1 hi)
Limit v to the range given by lo and hi.
Definition
minmax:120
cxx
Our C++ library.
Definition
arith:22
l4
cxx
minmax
Generated on Sat Aug 24 2024 16:07:21 for L4Re Operating System Framework by
1.9.8