Virtual Testbed
Ship dynamics simulator for extreme conditions
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) {
25  Mean<T>::update(x);
26  }
27 
28  inline void
29  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>
44  min_max_mean(Iterator first, Iterator last) {
46  while (first != last) { stats.update(*first); ++first; }
47  return stats;
48  }
49 
50 
51  }
52 
53 }
54 
55 #endif // vim:filetype=cpp
Estimates sample mean without overflows.
Definition: mean.hh:20
Main namespace.
Definition: convert.hh:9