Virtual Testbed
Ship dynamics simulator for extreme conditions
src
vtestbed
base
minmax.hh
1
#ifndef VTESTBED_BASE_MINMAX_HH
2
#define VTESTBED_BASE_MINMAX_HH
3
4
#include <limits>
5
#include <ostream>
6
7
#include <vtestbed/base/blitz.hh>
8
9
namespace
vtb
{
10
11
namespace
base {
12
13
template
<
class
T>
14
class
MinMax
{
15
16
public
:
17
typedef
T value_type;
18
typedef
T& reference;
19
typedef
const
T& const_reference;
20
typedef
int
int_type;
21
22
private
:
23
value_type _min{
std::numeric_limits<T>::max
()};
24
value_type _max{
std::numeric_limits<T>::lowest
()};
25
26
public
:
27
28
inline
value_type
29
min()
const
{
30
return
this->_min;
31
}
32
33
inline
value_type
34
max()
const
{
35
return
this->_max;
36
}
37
38
inline
void
39
update(value_type x) {
40
auto
& min = this->_min;
41
auto
& max = this->_max;
42
if
(x < min) { min = x; }
43
if
(max < x) { max = x; }
44
}
45
46
inline
void
47
clear() {
48
this->_min =
std::numeric_limits<T>::max
();
49
this->_max =
std::numeric_limits<T>::lowest
();
50
}
51
52
inline
friend
std::ostream
&
53
operator<<(
std::ostream
& out,
const
MinMax
& rhs) {
54
return
out << rhs.min() <<
' '
<< rhs.max();
55
}
56
57
};
58
59
}
60
61
}
62
63
#endif // vim:filetype=cpp
vtb::base::MinMax
Definition:
minmax.hh:14
std::numeric_limits::lowest
T lowest(T... args)
std::numeric_limits::max
T max(T... args)
vtb
Main namespace.
Definition:
convert.hh:9
std::ostream
Generated by
1.8.15