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