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