AFF --- A container for numbers (array) by Friederich and Forbriger.
avg.h
Go to the documentation of this file.
1 
36 // include guard
37 #ifndef AFF_AVG_H_VERSION
38 
39 #define AFF_AVG_H_VERSION \
40  "AFF_AVG_H V1.1 "
41 
42 
43 #include<aff/lib/collector.h>
44 
45 namespace aff {
46 
47  namespace func {
48 
49  namespace util {
50 
58  template<class C>
59  class Extractavg {
60  typedef typename C::Tcoc Tcont;
61  typedef typename C::Tvalue Tvalue;
62  public:
63  typedef Tvalue Tretval;
65  Extractavg(const Tcont& c): Msum(0), Mn(0) { }
67  void operator() (const Tvalue& v) { Msum+=v; ++Mn; }
69  Tretval result() const { return(Msum/Tvalue(Mn)); }
70  private:
72  int Mn;
73  }; // class Extractavg
74 
75  } // namespace util
76 
77 /*----------------------------------------------------------------------*/
78 
89  template<class C>
90  typename C::Tvalue avg(const C& c)
91  {
92  return(aff::func::util::collect<C, aff::func::util::Extractavg>(c));
93  } // avg()
94 
95  } // namespace func
96 
97 } // namespace aff
98 
99 #endif // AFF_AVG_H_VERSION (includeguard)
100 
101 /* ----- END OF avg.h ----- */
Root namespace of library.
Definition: array.h:148
collect values (prototypes)
C::Tvalue avg(const C &c)
Definition: avg.h:90
Tretval result() const
return result of operation
Definition: avg.h:69
void operator()(const Tvalue &v)
collect another value
Definition: avg.h:67
Extractavg(const Tcont &c)
initialize member data
Definition: avg.h:65