Virtual Testbed
Ship dynamics simulator for extreme conditions
src
vtestbed
base
minmaxmean.hh
1
#ifndef VTESTBED_BASE_MINMAXMEAN_HH
2
#define VTESTBED_BASE_MINMAXMEAN_HH
3
4
#include <iterator>
5
6
#include <vtestbed/base/mean.hh>
7
#include <vtestbed/base/minmax.hh>
8
9
namespace
vtb
{
10
11
namespace
base {
12
13
template
<
class
T>
14
class
MinMaxMean
:
public
MinMax
<T>,
public
Mean
<T> {
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
inline
void
23
update(value_type x) {
24
MinMax<T>::update
(x);
25
Mean<T>::update
(x);
26
}
27
28
inline
void
29
clear() {
30
MinMax<T>::clear
(),
Mean<T>::clear
();
31
}
32
33
inline
friend
std::ostream
&
34
operator<<(
std::ostream
& out,
const
MinMaxMean
& rhs) {
35
return
out
36
<<
static_cast<
const
MinMax<T>
&
>
(rhs) <<
' '
37
<<
static_cast<
const
Mean<T>
&
>
(rhs);
38
}
39
40
};
41
42
template
<
class
Iterator>
43
inline
MinMaxMean<typename std::iterator_traits<Iterator>::value_type
>
44
min_max_mean(Iterator first, Iterator last) {
45
MinMaxMean<typename std::iterator_traits<Iterator>::value_type
> stats;
46
while
(first != last) { stats.update(*first); ++first; }
47
return
stats;
48
}
49
50
51
}
52
53
}
54
55
#endif // vim:filetype=cpp
vtb::base::MinMax
Definition:
minmax.hh:14
vtb::base::MinMaxMean
Definition:
minmaxmean.hh:14
vtb::base::Mean
Estimates sample mean without overflows.
Definition:
mean.hh:20
vtb
Main namespace.
Definition:
convert.hh:9
std::ostream
Generated by
1.8.15