
https://svn.lrde.epita.fr/svn/oln/trunk/milena Index: ChangeLog from Thierry Geraud <thierry.geraud@lrde.epita.fr> Turn take_as_init as a 'template method' pattern. * mln/core/concept/accumulator.hh (take_as_init): Rename as... (take_as_init_): ...this. This is default implementation. (take_as_init): New. Dispatch to take_as_init_. Now, we have the "template method" method pattern. It is cleaner since we do not have any overriding for the client-side method. (take_n_times, take_n_times_): New. * mln/accu/nil.hh, * mln/accu/tuple.hh, * mln/accu/pair.hh, * mln/accu/lor.hh, * mln/accu/sum.hh, * mln/accu/inf.hh, * mln/accu/land_basic.hh, * mln/accu/min.hh, * mln/accu/max.hh, * mln/accu/bbox.hh, * mln/accu/min_h.hh, * mln/accu/max_h.hh, * mln/accu/lor_basic.hh, * mln/accu/p.hh, * mln/accu/rms.hh, * mln/accu/rank_high_quant.hh, * mln/accu/v.hh, * mln/accu/rank_bool.hh, * mln/accu/sup.hh, * mln/accu/land.hh, * mln/morpho/attribute/sum.hh, * mln/morpho/attribute/count_adjacent_vertices.hh, * mln/morpho/attribute/sharpness.hh, * mln/morpho/attribute/volume.hh, * mln/morpho/attribute/height.hh, * mln/morpho/attribute/card.hh (take_as_init): Update. Rename as... (take_as_init_): ...this overriding name. * tests/accu/count.cc: Update. mln/accu/bbox.hh | 4 - mln/accu/inf.hh | 4 - mln/accu/land.hh | 4 - mln/accu/land_basic.hh | 4 - mln/accu/lor.hh | 4 - mln/accu/lor_basic.hh | 4 - mln/accu/max.hh | 4 - mln/accu/max_h.hh | 6 +- mln/accu/min.hh | 4 - mln/accu/min_h.hh | 6 +- mln/accu/nil.hh | 4 - mln/accu/p.hh | 6 +- mln/accu/pair.hh | 8 +- mln/accu/rank_bool.hh | 4 - mln/accu/rank_high_quant.hh | 4 - mln/accu/rms.hh | 4 - mln/accu/sum.hh | 4 - mln/accu/sup.hh | 4 - mln/accu/tuple.hh | 14 ++-- mln/accu/v.hh | 12 ++-- mln/core/concept/accumulator.hh | 72 +++++++++++++++++++++++- mln/morpho/attribute/card.hh | 14 ++-- mln/morpho/attribute/count_adjacent_vertices.hh | 4 - mln/morpho/attribute/height.hh | 12 ++-- mln/morpho/attribute/sharpness.hh | 10 +-- mln/morpho/attribute/sum.hh | 12 ++-- mln/morpho/attribute/volume.hh | 12 ++-- tests/accu/count.cc | 39 ++++++++----- 28 files changed, 182 insertions(+), 101 deletions(-) Index: mln/core/concept/accumulator.hh --- mln/core/concept/accumulator.hh (revision 3726) +++ mln/core/concept/accumulator.hh (working copy) @@ -97,10 +97,30 @@ bool is_valid() const; */ - // Default impl. + /// Take as initialization the value \p t. + /// + /// Dev note: this is a final method; override if needed + /// by take_as_init_ (ending with '_'). template <typename T> void take_as_init(const T& t); // 't' is either argument or E. + /// Default implementation of "take as initialization". + template <typename T> + void take_as_init_(const T& t); + + + /// Take \p n times the value \p t. + /// + /// Dev note: this is a final method; override if needed + /// by take_as_init_ (ending with '_'). + template <typename T> + void take_n_times(unsigned n, const T& t); + + /// Default implementation of "take n times". + template <typename T> + void take_n_times_(unsigned n, const T& t); + + protected: Accumulator(); }; @@ -160,15 +180,63 @@ m6 = 0; } + + // take_as_init + template <typename E> template <typename T> void - Accumulator<E>::take_as_init(const T& t) // either argument or E + Accumulator<E>::take_as_init(const T& t) { + typedef mln_exact(T) T_; + typedef mlc_converts_to(T_, mln_argument(E)) t_is_argument; + typedef mlc_converts_to(T_, E) t_is_accumulator; + mlc_or(t_is_argument, t_is_accumulator)::check(); + + // Dispatch. + exact(this)->take_as_init_(t); + } + + template <typename E> + template <typename T> + void + Accumulator<E>::take_as_init_(const T& t) + { + // Default impl. exact(this)->init(); exact(this)->take(t); } + + // take n times + + template <typename E> + template <typename T> + void + Accumulator<E>::take_n_times(unsigned n, const T& t) + { + typedef mln_exact(T) T_; + typedef mlc_converts_to(T_, mln_argument(E)) t_is_argument; + typedef mlc_converts_to(T_, E) t_is_accumulator; + mlc_or(t_is_argument, t_is_accumulator)::check(); + + if (n == 0u) + return; + + // Dispatch. + exact(this)->take_n_times_(n, t); + } + + template <typename E> + template <typename T> + void + Accumulator<E>::take_n_times_(unsigned n, const T& t) + { + // Default impl. + for (unsigned i = 0; i < n; ++i) + exact(this)->take(t); + } + # endif // ! MLN_INCLUDE_ONLY } // end of namespace mln Index: mln/accu/nil.hh --- mln/accu/nil.hh (revision 3726) +++ mln/accu/nil.hh (working copy) @@ -58,7 +58,7 @@ /// Manipulators. /// \{ void init(); - void take_as_init(const argument&); + void take_as_init_(const argument&); void take(const argument&); void take(const nil<T>&); /// \} @@ -114,7 +114,7 @@ template <typename T> inline void - nil<T>::take_as_init(const argument&) + nil<T>::take_as_init_(const argument&) { } Index: mln/accu/tuple.hh --- mln/accu/tuple.hh (revision 3726) +++ mln/accu/tuple.hh (working copy) @@ -85,7 +85,7 @@ /// Manipulators. /// \{ void init(); - void take_as_init(const argument& t); + void take_as_init_(const argument& t); void take(const argument& t); void take(const tuple<A, n, BOOST_PP_ENUM_PARAMS(10, T)>& other); /// \} @@ -148,10 +148,10 @@ tuplehelper<n - 1, T>::init(a); } - static void take_as_init(typename T::intern& a, const typename T::argument& argument) + static void take_as_init_(typename T::intern& a, const typename T::argument& argument) { - boost::get<n - 1>(a).take_as_init(argument); - tuplehelper<n - 1, T>::take_as_init(a, argument); + boost::get<n - 1>(a).take_as_init_(argument); + tuplehelper<n - 1, T>::take_as_init_(a, argument); } static void take(typename T::intern& a, const typename T::argument& argument) @@ -177,7 +177,7 @@ struct tuplehelper<0, T> { static void init(typename T::intern&) {} - static void take_as_init(typename T::intern&, const typename T::argument&) {} + static void take_as_init_(typename T::intern&, const typename T::argument&) {} static void take(typename T::intern&, const typename T::argument) {} static void take(typename T::intern&, const typename T::intern&) {} static void to_result(const typename T::intern&, typename T::result&) {} @@ -202,9 +202,9 @@ template <typename A, unsigned n, BOOST_PP_ENUM_PARAMS(10, typename T)> inline void - tuple<A,n,BOOST_PP_ENUM_PARAMS(10,T) >::take_as_init(const argument& t) + tuple<A,n,BOOST_PP_ENUM_PARAMS(10,T) >::take_as_init_(const argument& t) { - internal::tuplehelper<n, self>::take_as_init(this->a_, t); + internal::tuplehelper<n, self>::take_as_init_(this->a_, t); } template <typename A, unsigned n, BOOST_PP_ENUM_PARAMS(10, typename T)> Index: mln/accu/pair.hh --- mln/accu/pair.hh (revision 3726) +++ mln/accu/pair.hh (working copy) @@ -70,7 +70,7 @@ /// Manipulators. /// \{ void init(); - void take_as_init(const argument& t); + void take_as_init_(const argument& t); void take(const argument& t); void take(const pair<A1,A2,T>& other); /// \} @@ -135,10 +135,10 @@ template <typename A1, typename A2, typename T> inline void - pair<A1,A2,T>::take_as_init(const argument& t) + pair<A1,A2,T>::take_as_init_(const argument& t) { - a1_.take_as_init(t); - a2_.take_as_init(t); + a1_.take_as_init_(t); + a2_.take_as_init_(t); } template <typename A1, typename A2, typename T> Index: mln/accu/lor.hh --- mln/accu/lor.hh (revision 3726) +++ mln/accu/lor.hh (working copy) @@ -55,7 +55,7 @@ /// Manipulators. /// \{ void init(); - void take_as_init(const argument& t); + void take_as_init_(const argument& t); void take(const argument& t); void take(const lor& other); @@ -110,7 +110,7 @@ } inline - void lor::take_as_init(const argument& t) + void lor::take_as_init_(const argument& t) { ntrue_ = t ? 1 : 0; } Index: mln/accu/sum.hh --- mln/accu/sum.hh (revision 3726) +++ mln/accu/sum.hh (working copy) @@ -67,7 +67,7 @@ /// \{ void init(); void take(const argument& t); - void take_as_init(const argument& t); + void take_as_init_(const argument& t); void take(const sum<T,S>& other); /// \} @@ -129,7 +129,7 @@ template <typename T, typename S> inline - void sum<T,S>::take_as_init(const argument& t) + void sum<T,S>::take_as_init_(const argument& t) { s_ = static_cast<S>(t); } Index: mln/accu/inf.hh --- mln/accu/inf.hh (revision 3726) +++ mln/accu/inf.hh (working copy) @@ -60,7 +60,7 @@ /// Manipulators. /// \{ void init(); - void take_as_init(const argument& t); + void take_as_init_(const argument& t); void take(const argument& t); void take(const inf<T>& other); /// \} @@ -120,7 +120,7 @@ template <typename T> inline - void inf<T>::take_as_init(const argument& t) + void inf<T>::take_as_init_(const argument& t) { t_ = t; } Index: mln/accu/land_basic.hh --- mln/accu/land_basic.hh (revision 3726) +++ mln/accu/land_basic.hh (working copy) @@ -57,7 +57,7 @@ /// Manipulators. /// \{ void init(); - void take_as_init(const argument& t); + void take_as_init_(const argument& t); void take(const argument& t); void take(const land_basic& other); @@ -114,7 +114,7 @@ } inline - void land_basic::take_as_init(const argument& t) + void land_basic::take_as_init_(const argument& t) { res_ = t; } Index: mln/accu/min.hh --- mln/accu/min.hh (revision 3726) +++ mln/accu/min.hh (working copy) @@ -60,7 +60,7 @@ /// Manipulators. /// \{ void init(); - void take_as_init(const argument& t); + void take_as_init_(const argument& t); void take(const argument& t); void take(const min<T>& other); /// \} @@ -119,7 +119,7 @@ template <typename T> inline - void min<T>::take_as_init(const argument& t) + void min<T>::take_as_init_(const argument& t) { t_ = t; } Index: mln/accu/max.hh --- mln/accu/max.hh (revision 3726) +++ mln/accu/max.hh (working copy) @@ -58,7 +58,7 @@ /// Manipulators. /// \{ void init(); - void take_as_init(const argument& t); + void take_as_init_(const argument& t); void take(const argument& t); void take(const max<T>& other); /// \} @@ -117,7 +117,7 @@ template <typename T> inline void - max<T>::take_as_init(const argument& t) + max<T>::take_as_init_(const argument& t) { t_ = t; } Index: mln/accu/bbox.hh --- mln/accu/bbox.hh (revision 3726) +++ mln/accu/bbox.hh (working copy) @@ -58,7 +58,7 @@ /// Manipulators. /// \{ void init(); - void take_as_init(const P& p); + void take_as_init_(const P& p); void take(const P& p); void take(const bbox<P>& other); void take(const box<P>& b); @@ -114,7 +114,7 @@ template <typename P> inline void - bbox<P>::take_as_init(const P& p) + bbox<P>::take_as_init_(const P& p) { b_.pmin() = p; b_.pmax() = p; Index: mln/accu/min_h.hh --- mln/accu/min_h.hh (revision 3726) +++ mln/accu/min_h.hh (working copy) @@ -58,7 +58,7 @@ /// \{ void init(); void take(const argument& t); - void take_as_init(const argument& t); + void take_as_init_(const argument& t); void take(const min_h<V>& other); void untake(const argument& t); /// \} @@ -132,7 +132,7 @@ { if (h_.sum() == 0) { - this->take_as_init(t); + this->take_as_init_(t); return; } h_.take(t); @@ -233,7 +233,7 @@ template <typename V> inline void - min_h<V>::take_as_init(const argument& t) + min_h<V>::take_as_init_(const argument& t) { h_.take(t); sum_ = 0; Index: mln/accu/max_h.hh --- mln/accu/max_h.hh (revision 3726) +++ mln/accu/max_h.hh (working copy) @@ -57,7 +57,7 @@ /// \{ void init(); void take(const argument& t); - void take_as_init(const argument& t); + void take_as_init_(const argument& t); void take(const max_h<V>& other); void untake(const argument& t); /// \} @@ -131,7 +131,7 @@ { if (h_.sum() == 0) { - this->take_as_init(t); + this->take_as_init_(t); return; } h_.take(t); @@ -232,7 +232,7 @@ template <typename V> inline void - max_h<V>::take_as_init(const argument& t) + max_h<V>::take_as_init_(const argument& t) { h_.take(t); sum_ = 0; Index: mln/accu/lor_basic.hh --- mln/accu/lor_basic.hh (revision 3726) +++ mln/accu/lor_basic.hh (working copy) @@ -57,7 +57,7 @@ /// Manipulators. /// \{ void init(); - void take_as_init(const argument& t); + void take_as_init_(const argument& t); void take(const argument& t); void take(const lor_basic& other); @@ -114,7 +114,7 @@ } inline - void lor_basic::take_as_init(const argument& t) + void lor_basic::take_as_init_(const argument& t) { res_ = t; } Index: mln/accu/p.hh --- mln/accu/p.hh (revision 3726) +++ mln/accu/p.hh (working copy) @@ -60,7 +60,7 @@ /// Manipulators. /// \{ void init(); - void take_as_init(const argument& t); + void take_as_init_(const argument& t); void take(const argument& t); void take(const p<A>& other); /// \} @@ -123,9 +123,9 @@ template <typename A> inline void - p<A>::take_as_init(const argument& t) + p<A>::take_as_init_(const argument& t) { - a_.take_as_init(t.p()); // FIXME: Generalize with "psite(t)". + a_.take_as_init_(t.p()); // FIXME: Generalize with "psite(t)". } template <typename A> Index: mln/accu/rms.hh --- mln/accu/rms.hh (revision 3726) +++ mln/accu/rms.hh (working copy) @@ -58,7 +58,7 @@ /// Manipulators. /// \{ void init(); - void take_as_init(const T& p); + void take_as_init_(const T& p); void take(const T& p); void take(const rms<T,V>& other); /// \} @@ -118,7 +118,7 @@ template <typename T, typename V> inline void - rms<T,V>::take_as_init(const T& t) + rms<T,V>::take_as_init_(const T& t) { v_ += t * t; ++count_; Index: mln/accu/rank_high_quant.hh --- mln/accu/rank_high_quant.hh (revision 3726) +++ mln/accu/rank_high_quant.hh (working copy) @@ -61,7 +61,7 @@ /// Manipulators. /// \{ void init(); - void take_as_init(const argument& t); + void take_as_init_(const argument& t); void take(const argument& t); void take(const rank<T>& other); void sort(); @@ -139,7 +139,7 @@ template <typename T> inline - void rank<T>::take_as_init(const argument& t) + void rank<T>::take_as_init_(const argument& t) { elts_.push_back(t); is_sorted_ = false; Index: mln/accu/v.hh --- mln/accu/v.hh (revision 3726) +++ mln/accu/v.hh (working copy) @@ -60,11 +60,11 @@ /// Manipulators. /// \{ void init(); - void take_as_init(const argument& t); + void take_as_init_(const argument& t); void take(const argument& t); void take(const val<A>& other); template <typename I> - void take_as_init(const util::pix<I>& pix); + void take_as_init_(const util::pix<I>& pix); template <typename I> void take(const util::pix<I>& pix); /// \} @@ -127,9 +127,9 @@ template <typename A> inline void - val<A>::take_as_init(const argument& t) + val<A>::take_as_init_(const argument& t) { - a_.take_as_init(t); + a_.take_as_init_(t); } template <typename A> @@ -152,9 +152,9 @@ template <typename I> inline void - val<A>::take_as_init(const util::pix<I>& pix) + val<A>::take_as_init_(const util::pix<I>& pix) { - a_.take_as_init(pix.v()); // FIXME: Generalize with "value(pix)". + a_.take_as_init_(pix.v()); // FIXME: Generalize with "value(pix)". } template <typename A> Index: mln/accu/rank_bool.hh --- mln/accu/rank_bool.hh (revision 3726) +++ mln/accu/rank_bool.hh (working copy) @@ -62,7 +62,7 @@ /// Manipulators. /// \{ void init(); - void take_as_init(const argument& t); + void take_as_init_(const argument& t); void take(const argument& t); void take(const rank<bool>& other); void untake(const argument& t); @@ -105,7 +105,7 @@ } inline - void rank<bool>::take_as_init(const argument& t) + void rank<bool>::take_as_init_(const argument& t) { nfalse_ = t ? 0 : 1; } Index: mln/accu/sup.hh --- mln/accu/sup.hh (revision 3726) +++ mln/accu/sup.hh (working copy) @@ -60,7 +60,7 @@ /// Manipulators. /// \{ void init(); - void take_as_init(const argument& t); + void take_as_init_(const argument& t); void take(const argument& t); void take(const sup<T>& other); /// \} @@ -120,7 +120,7 @@ template <typename T> inline - void sup<T>::take_as_init(const argument& t) + void sup<T>::take_as_init_(const argument& t) { t_ = t; } Index: mln/accu/land.hh --- mln/accu/land.hh (revision 3726) +++ mln/accu/land.hh (working copy) @@ -55,7 +55,7 @@ /// Manipulators. /// \{ void init(); - void take_as_init(const argument& t); + void take_as_init_(const argument& t); void take(const argument& t); void take(const land& other); @@ -110,7 +110,7 @@ } inline - void land::take_as_init(const argument& t) + void land::take_as_init_(const argument& t) { nfalse_ = t ? 0 : 1; } Index: mln/morpho/attribute/sum.hh --- mln/morpho/attribute/sum.hh (revision 3726) +++ mln/morpho/attribute/sum.hh (working copy) @@ -96,8 +96,8 @@ void take(const util::pix<I>& px); void take(const sum<I,S>& other); - void take_as_init(const argument& v); - void take_as_init(const util::pix<I>& px); + void take_as_init_(const argument& v); + void take_as_init_(const util::pix<I>& px); /// \} /// Get the value of the accumulator. @@ -167,12 +167,12 @@ s_ += other.s_; } - // take_as_init. + // take_as_init_. template <typename I, typename S> inline void - sum<I,S>::take_as_init(const argument& v) + sum<I,S>::take_as_init_(const argument& v) { s_ = v; } @@ -180,9 +180,9 @@ template <typename I, typename S> inline void - sum<I,S>::take_as_init(const util::pix<I>& px) + sum<I,S>::take_as_init_(const util::pix<I>& px) { - take_as_init(px.v()); + take_as_init_(px.v()); } template <typename I, typename S> Index: mln/morpho/attribute/count_adjacent_vertices.hh --- mln/morpho/attribute/count_adjacent_vertices.hh (revision 3726) +++ mln/morpho/attribute/count_adjacent_vertices.hh (working copy) @@ -98,7 +98,7 @@ void take(const argument& px); void take(const count_adjacent_vertices<I>& other); - void take_as_init(const argument& px); + void take_as_init_(const argument& px); /// \} /// Get the value of the accumulator. @@ -160,7 +160,7 @@ template <typename I> inline void - count_adjacent_vertices<I>::take_as_init(const argument& px) + count_adjacent_vertices<I>::take_as_init_(const argument& px) { vertices_.clear(); take(px); Index: mln/morpho/attribute/sharpness.hh --- mln/morpho/attribute/sharpness.hh (revision 3726) +++ mln/morpho/attribute/sharpness.hh (working copy) @@ -94,7 +94,7 @@ void take(const mln_value(I)& v); void take(const sharpness<I>& other); - void take_as_init(const mln_value(I)& v); + void take_as_init_(const mln_value(I)& v); /// \} /// Get the value of the accumulator. @@ -146,7 +146,7 @@ { if (! is_valid()) { - take_as_init(v); + take_as_init_(v); return; } volume_.take(v); @@ -166,10 +166,10 @@ template <typename I> inline void - sharpness<I>::take_as_init(const mln_value(I)& v) + sharpness<I>::take_as_init_(const mln_value(I)& v) { - volume_.take_as_init(v); - height_.take_as_init(v); + volume_.take_as_init_(v); + height_.take_as_init_(v); } template <typename I> Index: mln/morpho/attribute/volume.hh --- mln/morpho/attribute/volume.hh (revision 3726) +++ mln/morpho/attribute/volume.hh (working copy) @@ -93,8 +93,8 @@ void take(const util::pix<I>& px); void take(const volume<I>& other); - void take_as_init(const mln_value(I)& v); - void take_as_init(const util::pix<I>& px); + void take_as_init_(const mln_value(I)& v); + void take_as_init_(const util::pix<I>& px); /// \} /// Get the value of the accumulator. @@ -143,7 +143,7 @@ mln_invariant(volume_ != mln_max(unsigned)); if (! is_valid()) { - take_as_init(v); + take_as_init_(v); return; } ++area_; @@ -176,7 +176,7 @@ template <typename I> inline void - volume<I>::take_as_init(const mln_value(I)& v) + volume<I>::take_as_init_(const mln_value(I)& v) { cur_level_ = v; area_ = 1; @@ -186,9 +186,9 @@ template <typename I> inline void - volume<I>::take_as_init(const util::pix<I>& px) + volume<I>::take_as_init_(const util::pix<I>& px) { - take_as_init(px.v()); + take_as_init_(px.v()); } template <typename I> Index: mln/morpho/attribute/height.hh --- mln/morpho/attribute/height.hh (revision 3726) +++ mln/morpho/attribute/height.hh (working copy) @@ -93,8 +93,8 @@ void take(const mln_value(I)& v); void take(const util::pix<I>& v); void take(const height<I>& other); - void take_as_init(const mln_value(I)& v); - void take_as_init(const util::pix<I>& px); + void take_as_init_(const mln_value(I)& v); + void take_as_init_(const util::pix<I>& px); /// \} /// Check whether this accu is able to return a result. @@ -139,7 +139,7 @@ { if (!is_valid ()) { - take_as_init(v); + take_as_init_(v); } cur_ = v; } @@ -182,7 +182,7 @@ template <typename I> inline void - height<I>::take_as_init(const mln_value(I)& v) + height<I>::take_as_init_(const mln_value(I)& v) { cur_ = ref_ = v; initialized_ = true; @@ -191,9 +191,9 @@ template <typename I> inline void - height<I>::take_as_init(const util::pix<I>& px) + height<I>::take_as_init_(const util::pix<I>& px) { - take_as_init(px.v()); + take_as_init_(px.v()); } Index: mln/morpho/attribute/card.hh --- mln/morpho/attribute/card.hh (revision 3726) +++ mln/morpho/attribute/card.hh (working copy) @@ -94,9 +94,9 @@ void take(const util::pix<I>& px); void take(const card<I>& other); - void take_as_init(); - void take_as_init(const util::pix<I>& px); - using super_::take_as_init; + void take_as_init_(); + void take_as_init_(const util::pix<I>& px); + using super_::take_as_init_; /// \} /// Get the value of the accumulator. @@ -164,12 +164,12 @@ c_ += other.c_; } - // take_as_init. + // take_as_init_. template <typename I> inline void - card<I>::take_as_init() + card<I>::take_as_init_() { init(); take(); @@ -178,9 +178,9 @@ template <typename I> inline void - card<I>::take_as_init(const util::pix<I>&) + card<I>::take_as_init_(const util::pix<I>&) { - take_as_init(); + take_as_init_(); } template <typename I> Index: tests/accu/count.cc --- tests/accu/count.cc (revision 3726) +++ tests/accu/count.cc (working copy) @@ -1,4 +1,4 @@ -// Copyright (C) 2007 EPITA Research and Development Laboratory +// Copyright (C) 2007, 2009 EPITA Research and Development Laboratory // // This file is part of the Olena Library. This library is free // software; you can redistribute it and/or modify it under the terms @@ -25,30 +25,43 @@ // reasons why the executable file might be covered by the GNU General // Public License. -/*! \file tests/accu/count.cc - * - * \brief Tests on mln::accu::count. - */ - -#include <mln/value/int_u8.hh> +/// \file tests/accu/count.cc +/// +/// Tests on mln::accu::count. #include <mln/accu/count.hh> +struct toto {}; + + int main() { using namespace mln; { - accu::count<value::int_u8> accu; - mln_assertion(accu.to_result() == 0); + // The code below do not compile, as expected :-) + // accu::count<int> a; + // a.take_as_init(toto()); } - { - accu::count<value::int_u8> accu; + accu::count<int> a; + mln_assertion(a.to_result() == 0); + } + { + accu::count<int> a; for (int i = 0; i < 200; i++) - accu.take(i); - mln_assertion(accu.to_result() == 200); + a.take(i); + mln_assertion(a.to_result() == 200); } + { + accu::count<int> a, a_; + a.take_as_init(1); + mln_assertion(a == 1); + a.take(2); + mln_assertion(a == 2); + a_.take_as_init(a); + mln_assertion(a_ == 2); + } }