
https://svn.lrde.epita.fr/svn/oln/prototypes/proto-1.0/olena ChangeLog | 9 +++++++++ oln/funobj/arith.hh | 32 +++++++++++++++++++++++++------- tests/funobj/Makefile.am | 3 +++ tests/funobj/tests/arith | 12 ++++++++++++ 4 files changed, 49 insertions(+), 7 deletions(-) Index: ChangeLog from Roland Levillain <roland@lrde.epita.fr> Add unary minus function object. * oln/funobj/arith.hh (f_::uminus_): New functor. (f_uminus): New. * tests/funobj/tests/arith: New test. * tests/funobj/Makefile.am: New file. 2005-06-09 Roland Levillain <roland@lrde.epita.fr> Property changes on: tests/funobj ___________________________________________________________________ Name: svn:ignore + *Makefile *Makefile?in Index: tests/funobj/tests/arith --- tests/funobj/tests/arith (revision 0) +++ tests/funobj/tests/arith (revision 0) @@ -0,0 +1,12 @@ + // -*- C++ -*- +#include <oln/funobj/arith.hh> + +using namespace oln; + +bool check() +{ + if (f_uminus(42) != -42) + return true; + + return false; +} Index: tests/funobj/Makefile.am --- tests/funobj/Makefile.am (revision 0) +++ tests/funobj/Makefile.am (revision 0) @@ -0,0 +1,3 @@ +## Process this file through Automake to create Makefile.in -*- Makefile -*- + +include ../check/Makefile.runtests Index: oln/funobj/arith.hh --- oln/funobj/arith.hh (revision 204) +++ oln/funobj/arith.hh (working copy) @@ -86,15 +86,14 @@ oln_decl_funobj_binary(div, /); oln_decl_funobj_binary(mod, %); - // FIXME: min, max? - // FIXME: uminus? - - - namespace f_ { + template <typename T> struct uminus_; template <typename T> struct min_; template <typename T> struct max_; - } + } // end of namespace oln::f_ + + template <typename T> + struct set_super_type < f_::uminus_<T> > { typedef f_::abstract::unary< f_::uminus_<T> > ret; }; template <typename T> struct set_super_type < f_::min_<T> > { typedef f_::abstract::binary< f_::min_<T> > ret; }; @@ -103,6 +102,13 @@ struct set_super_type < f_::max_<T> > { typedef f_::abstract::binary< f_::max_<T> > ret; }; template <typename T> + struct set_props < category::fun1, f_::uminus_<T> > + { + typedef T res_type; + typedef T arg_type; + }; + + template <typename T> struct set_props < category::fun2, f_::min_<T> > { typedef T res_type; @@ -122,6 +128,15 @@ { template <typename T> + struct uminus_ : public oln_super_of_(f_::uminus_<T>) + { + const T impl_unop(const T& arg) const + { + return -arg; + } + }; + + template <typename T> struct min_ : public oln_super_of_(f_::min_<T>) { const T impl_binop(const T& left, const T& right) const @@ -139,7 +154,10 @@ } }; - } + } // end of namespace oln::f_ + + typedef f_::unary_meta<f_::uminus_> f_uminus_type; + static f_uminus_type f_uminus; typedef f_::binary1_meta<f_::min_> f_min_type; static f_min_type f_min;