658: Make xtd unary functions support argument mutation.

2006-10-18 Thierry GERAUD <theo@tegucigalpa.lrde.epita.fr> Make xtd unary functions support argument mutation. * xtd/accessor.hh (xtd_decl_accessor): Add impl_op mutable version to the accessor class. * xtd/mfun.hh (impl_calc): Add mutable version to m1fun_<F>. * xtd/abstract/open_nary_fun.hh (impl, operator): Add mutable versions to open_nary_fun_<1, E>. * xtd/abstract/plain_nary_fun.hh (operator): Add mutable version to plain_nary_fun_<1, E>. Index: xtd/accessor.hh =================================================================== --- xtd/accessor.hh (revision 657) +++ xtd/accessor.hh (working copy) @@ -60,6 +60,10 @@ { \ return arg.MethodName(); \ } \ + xtd_res(MethodName##_<T>)& impl_op(T& arg) const \ + { \ + return arg.MethodName(); \ + } \ }; \ \ typedef xtd::m1fun_<MethodName##_> MethodName##_type; \ Index: xtd/abstract/open_nary_fun.hh =================================================================== --- xtd/abstract/open_nary_fun.hh (revision 657) +++ xtd/abstract/open_nary_fun.hh (working copy) @@ -82,6 +82,13 @@ { return target.impl_calc(a); } + + // The "mutable a" version below is dedicated to mutators. + static res& impl(const E& target, + A& a) + { + return target.impl_calc(a); + } }; @@ -225,6 +232,14 @@ return case_<A>::impl(this->exact_(), a); } + // The "mutable a" version below is dedicated to mutators. + template <typename A> + typename case_<A>::res & + operator()(A& a) const + { + return case_<A>::impl(this->exact_(), a); + } + protected: open_nary_fun_() {} }; Index: xtd/abstract/plain_nary_fun.hh =================================================================== --- xtd/abstract/plain_nary_fun.hh (revision 657) +++ xtd/abstract/plain_nary_fun.hh (working copy) @@ -144,6 +144,12 @@ return this->exact().impl_op(arg); } + // The "mutable arg" version below is dedicated to mutators. + xtd_res(E)& operator()(xtd_arg(E)& arg) const + { + return this->exact().impl_op(arg); + } + template <typename A> xtd_res(E) operator()(const A& arg) const { Index: xtd/mfun.hh =================================================================== --- xtd/mfun.hh (revision 657) +++ xtd/mfun.hh (working copy) @@ -89,6 +89,18 @@ static const F_ f_; return f_(a); } + template <typename A> + xtd_res(F<A>)& impl_calc(A& a) const + // --------- + { + typedef F<A> F_; + mlc::assert_< mlc::and_< mlc_is_a(F_, abstract::plain_fun_), + mlc_is_a(F_, abstract::nary_fun_<1>) >, + xtd::ERROR::AN_xtd_m1fun_SHOULD_TAKE_AS_PARAMETER_AN_xtd_plain_nary_fun_WITH_n_BEING_1 + >::check(); + static const F_ f_; + return f_(a); + } };
participants (1)
-
Thierry GERAUD