https://svn.lrde.epita.fr/svn/oln/trunk/extended
Index: ChangeLog
from Thierry Geraud <theo(a)lrde.epita.fr>
First draft of extended functions.
* xtd/math.hh: New file.
* xtd/res.hh: New file.
* xtd/cast.hh: New file.
* xtd/math: New file.
* xtd/math/trigo.hh: New file.
* xtd/math/arith.hh: New file.
* xtd/math/id.hh: New file.
* xtd/mexpr.hh: New file.
* xtd/args.hh: New file.
* xtd/literal.hh: New file.
* xtd/ops_expr.hh: New file.
* xtd/abstract: New file.
* xtd/abstract/nary_fun.hh: New file.
* xtd/abstract/exact.hh: New file.
* xtd/abstract/fun_expr.hh: New file.
* xtd/abstract/any.hh: New file.
* xtd/abstract/fun.hh: New file.
* xtd/abstract/plain_fun.hh: New file.
* xtd/abstract/meta_fun.hh: New file.
* xtd/mfun.hh: New file.
* xtd/traits.hh: New file.
* xtd/builtin: New file.
* xtd/builtin/traits.hh: New file.
* xtd/arg.hh: New file.
* xtd/case.hh: New file.
* tests/id.cc: New file.
* tests/cos.cc: New file.
* tests/cast.cc: New file.
* tests/Makefile.am: Update.
tests/Makefile.am | 13 +
tests/cast.cc | 37 ++++
tests/cos.cc | 52 +++++
tests/id.cc | 43 ++++
xtd/abstract/any.hh | 67 +++++++
xtd/abstract/exact.hh | 93 ++++++++++
xtd/abstract/fun.hh | 58 ++++++
xtd/abstract/fun_expr.hh | 225 +++++++++++++++++++++++++
xtd/abstract/meta_fun.hh | 290 ++++++++++++++++++++++++++++++++
xtd/abstract/nary_fun.hh | 53 +++++
xtd/abstract/plain_fun.hh | 271 ++++++++++++++++++++++++++++++
xtd/arg.hh | 152 ++++++++++++++++
xtd/args.hh | 179 +++++++++++++++++++
xtd/builtin/traits.hh | 90 ++++++++++
xtd/case.hh | 37 ++++
xtd/cast.hh | 126 ++++++++++++++
xtd/literal.hh | 113 ++++++++++++
xtd/math.hh | 45 +++++
xtd/math/arith.hh | 104 +++++++++++
xtd/math/id.hh | 68 +++++++
xtd/math/trigo.hh | 154 +++++++++++++++++
xtd/mexpr.hh | 413 ++++++++++++++++++++++++++++++++++++++++++++++
xtd/mfun.hh | 195 +++++++++++++++++++++
xtd/ops_expr.hh | 84 +++++++++
xtd/res.hh | 292 ++++++++++++++++++++++++++++++++
xtd/traits.hh | 55 ++++++
26 files changed, 3308 insertions(+), 1 deletion(-)
Index: xtd/math.hh
--- xtd/math.hh (revision 0)
+++ xtd/math.hh (revision 0)
@@ -0,0 +1,45 @@
+// Copyright (C) 2002, 2005, 2006 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
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef EXTENDED_MATH_HH
+# define EXTENDED_MATH_HH
+
+# include <cmath>
+
+# include <xtd/abstract/plain_fun.hh>
+# include <xtd/mfun.hh>
+# include <xtd/arg.hh>
+# include <xtd/ops_expr.hh>
+
+# include <xtd/math/id.hh>
+# include <xtd/math/trigo.hh>
+# include <xtd/math/arith.hh>
+// # include <xtd/math/logic.hh>
+
+
+
+#endif // ! EXTENDED_MATH_HH
Index: xtd/res.hh
--- xtd/res.hh (revision 0)
+++ xtd/res.hh (revision 0)
@@ -0,0 +1,292 @@
+// Copyright (C) 2002, 2005, 2006 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
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef EXTENDED_RES_HH
+# define EXTENDED_RES_HH
+
+# include <mlc/flags.hh>
+# include <mlc/bool.hh> // FIXME: should be assert.hh
+# include <mlc/if.hh>
+# include <mlc/is_a.hh>
+# include <mlc/comma.hh>
+# include <mlc/cmp.hh>
+# include <mlc/ret.hh>
+
+# include <xtd/abstract/nary_fun.hh>
+
+
+
+// forward declarations ...............................
+
+namespace xtd
+{
+
+ namespace abstract
+ {
+
+ template <typename E>
+ class meta_fun_;
+
+ template <unsigned n, typename E>
+ class meta_nary_fun_;
+
+ template <typename E>
+ class fun_expr_;
+
+ } // end of namespace xtd::abstract
+
+ template <typename F,
+ typename Expr>
+ struct m1expr;
+
+ template <typename F,
+ typename Expr1, typename Expr2>
+ struct m2expr;
+
+ template <typename F,
+ typename Expr1, typename Expr2, typename Expr3>
+ struct m3expr;
+
+} // end of namespace xtd
+
+
+// end of forward declarations ........................
+
+
+
+
+// macros
+
+# define xtd_res_0(F) typename xtd::internal::get_res_<F>::ret
+# define xtd_res_1(F, A1) typename xtd::internal::get_res_<F, A1>::ret
+# define xtd_res_2(F, A1, A2) typename xtd::internal::get_res_<F, A1,
A2>::ret
+# define xtd_res_3(F, A1, A2, A3) typename xtd::internal::get_res_<F, A1, A2,
A3>::ret
+
+# define xtd_expr_res(F, Args) typename xtd::internal::get_expr_res_<F,
Args>::ret
+
+
+namespace xtd
+{
+
+ namespace ERROR
+ {
+ struct THE_MACRO_xtd_res_0_IS_FOR_USE_ON_AN_xtd_meta_fun;
+ struct THE_MACRO_xtd_res_1_IS_FOR_USE_ON_AN_xtd_meta_fun;
+ struct THE_MACRO_xtd_res_2_IS_FOR_USE_ON_AN_xtd_meta_fun;
+ struct THE_MACRO_xtd_res_3_IS_FOR_USE_ON_AN_xtd_meta_fun;
+
+ struct THE_MACRO_xtd_expr_res_IS_FOR_USE_ON_AN_xtd_fun_expr;
+ struct THE_MACRO_xtd_expr_res_IS_FOR_USE_WITH_AN_xtd_args;
+
+ struct THE_MACRO_xtd_res_0_IS_FOR_USE_ON_AN_xtd_meta_nary_fun_WITH_n_BEING_0;
+ struct THE_MACRO_xtd_res_1_IS_FOR_USE_ON_AN_xtd_meta_nary_fun_WITH_n_BEING_1;
+ struct THE_MACRO_xtd_res_2_IS_FOR_USE_ON_AN_xtd_meta_nary_fun_WITH_n_BEING_2;
+ struct THE_MACRO_xtd_res_3_IS_FOR_USE_ON_AN_xtd_meta_nary_fun_WITH_n_BEING_3;
+
+ struct SPECIALIZATION_OF_xtd_res_NOT_FOUND;
+ struct SPECIALIZATION_OF_xtd_expr_res_NOT_FOUND;
+
+ struct NO_ret_FOUND_IN_THE_SPECIALIZATION_OF_xtd_res;
+ struct NO_ret_FOUND_IN_THE_SPECIALIZATION_OF_xtd_expr_res;
+
+ struct YOU_SHOULD_NOT_DERIVE_DIRECTLY_FROM_xtd_meta_fun_BUT_FROM_xtd_meta_nary_fun_;
+
+ struct FIXME_NAME_THIS_ERROR ;
+
+ } // end of namespace xtd::ERROR
+
+
+
+
+ // FIXME: doc
+
+ template <typename F,
+ typename A1 = mlc::none,
+ typename A2 = mlc::none,
+ typename A3 = mlc::none>
+ struct res_ : public mlc::undefined
+ {
+ };
+
+
+ template <typename F,
+ typename Args>
+ struct expr_res_ : public mlc::undefined
+ {
+ };
+
+
+
+ namespace internal
+ {
+ // FIXME: doc...
+
+
+ // for meta_fun that are *not* fun_expr
+ // ------------------------------------
+
+
+ // three args
+
+ template <typename F,
+ typename A1 = mlc::none,
+ typename A2 = mlc::none,
+ typename A3 = mlc::none>
+ struct do_get_res_
+
+ : private mlc::assert_< mlc_is_a(F, xtd::abstract::meta_fun_),
+ xtd::ERROR::THE_MACRO_xtd_res_3_IS_FOR_USE_ON_AN_xtd_meta_fun >,
+
+ private mlc::assert_< mlc::and_< mlc_is_a(F, xtd::abstract::meta_fun_),
+ mlc_is_a(F, xtd::abstract::nary_fun_<3>) >,
+
xtd::ERROR::THE_MACRO_xtd_res_3_IS_FOR_USE_ON_AN_xtd_meta_nary_fun_WITH_n_BEING_3 >,
+
+ private mlc::assert_< mlc_is_not_a(mlc_comma_3(xtd::res_<F,A1,A2,A3>),
mlc::undefined),
+ xtd::ERROR::SPECIALIZATION_OF_xtd_res_NOT_FOUND >,
+
+ private mlc::assert_< mlc::neq_<
mlc_ret(mlc_comma_3(xtd::res_<F,A1,A2,A3>)), mlc::not_found >,
+ xtd::ERROR::NO_ret_FOUND_IN_THE_SPECIALIZATION_OF_xtd_res
>
+ {
+ typedef mlc_ret(mlc_comma_3(xtd::res_<F,A1,A2,A3>)) ret;
+ };
+
+
+
+ // no arg
+
+ template <typename F>
+ struct do_get_res_< F >
+
+ : private mlc::assert_< mlc_is_a(F, xtd::abstract::meta_fun_),
+ xtd::ERROR::THE_MACRO_xtd_res_0_IS_FOR_USE_ON_AN_xtd_meta_fun >,
+
+ private mlc::assert_< mlc::and_< mlc_is_a(F, xtd::abstract::meta_fun_),
+ mlc_is_a(F, xtd::abstract::nary_fun_<0>) >,
+
xtd::ERROR::THE_MACRO_xtd_res_0_IS_FOR_USE_ON_AN_xtd_meta_nary_fun_WITH_n_BEING_0 >,
+
+ private mlc::assert_< mlc_is_not_a(xtd::res_<F>, mlc::undefined),
+ xtd::ERROR::SPECIALIZATION_OF_xtd_res_NOT_FOUND >,
+
+ private mlc::assert_< mlc::neq_< mlc_ret(xtd::res_<F>), mlc::not_found
>,
+ xtd::ERROR::NO_ret_FOUND_IN_THE_SPECIALIZATION_OF_xtd_res
>
+ {
+ typedef mlc_ret(xtd::res_<F>) ret;
+ };
+
+
+ // a single arg
+
+ template <typename F, typename A1>
+ struct do_get_res_< F, A1 >
+
+ : private mlc::assert_< mlc_is_a(F, xtd::abstract::meta_fun_),
+ xtd::ERROR::THE_MACRO_xtd_res_1_IS_FOR_USE_ON_AN_xtd_meta_fun >,
+
+ private mlc::assert_< mlc::and_< mlc_is_a(F, xtd::abstract::meta_fun_),
+ mlc_is_a(F, xtd::abstract::nary_fun_<1>) >,
+
xtd::ERROR::THE_MACRO_xtd_res_1_IS_FOR_USE_ON_AN_xtd_meta_nary_fun_WITH_n_BEING_1 >,
+
+ private mlc::assert_< mlc_is_not_a(mlc_comma_1(xtd::res_<F,A1>),
mlc::undefined),
+ xtd::ERROR::SPECIALIZATION_OF_xtd_res_NOT_FOUND >,
+
+ private mlc::assert_< mlc::neq_< mlc_ret(mlc_comma_1(xtd::res_<F,A1>)),
mlc::not_found >,
+ xtd::ERROR::NO_ret_FOUND_IN_THE_SPECIALIZATION_OF_xtd_res
>
+ {
+ typedef mlc_ret(mlc_comma_1(xtd::res_<F,A1>)) ret;
+ };
+
+
+ // a couple of args
+
+ template <typename F, typename A1, typename A2>
+ struct do_get_res_< F, A1, A2 >
+
+ : private mlc::assert_< mlc_is_a(F, xtd::abstract::meta_fun_),
+ xtd::ERROR::THE_MACRO_xtd_res_2_IS_FOR_USE_ON_AN_xtd_meta_fun >,
+
+ private mlc::assert_< mlc::and_< mlc_is_a(F, xtd::abstract::meta_fun_),
+ mlc_is_a(F, xtd::abstract::nary_fun_<2>) >,
+
xtd::ERROR::THE_MACRO_xtd_res_2_IS_FOR_USE_ON_AN_xtd_meta_nary_fun_WITH_n_BEING_2 >,
+
+ private mlc::assert_< mlc_is_not_a(mlc_comma_2(xtd::res_<F,A1,A2>),
mlc::undefined),
+ xtd::ERROR::SPECIALIZATION_OF_xtd_res_NOT_FOUND >,
+
+ private mlc::assert_< mlc::neq_< mlc_ret(mlc_comma_2(xtd::res_<F,A1,A2>)),
mlc::not_found >,
+ xtd::ERROR::NO_ret_FOUND_IN_THE_SPECIALIZATION_OF_xtd_res
>
+ {
+ typedef mlc_ret(mlc_comma_2(xtd::res_<F,A1,A2>)) ret;
+ };
+
+
+
+ // for meta_fun that *are* fun_expr
+ // ------------------------------------
+
+ template <typename F,
+ typename Args>
+ struct get_expr_res_
+
+ : private mlc::assert_< mlc_is_a(F, xtd::abstract::fun_expr_),
+ xtd::ERROR::THE_MACRO_xtd_expr_res_IS_FOR_USE_ON_AN_xtd_fun_expr >,
+
+ private mlc::assert_< mlc_is_a(Args, xtd::abstract::args),
+ xtd::ERROR::THE_MACRO_xtd_expr_res_IS_FOR_USE_WITH_AN_xtd_args >,
+
+ private mlc::assert_< mlc_is_not_a(mlc_comma_1(xtd::expr_res_<F,Args>),
mlc::undefined),
+ xtd::ERROR::SPECIALIZATION_OF_xtd_expr_res_NOT_FOUND >,
+
+ private mlc::assert_< mlc::neq_<
mlc_ret(mlc_comma_1(xtd::expr_res_<F,Args>)), mlc::not_found >,
+
xtd::ERROR::NO_ret_FOUND_IN_THE_SPECIALIZATION_OF_xtd_expr_res >
+ {
+ typedef mlc_ret(mlc_comma_1(xtd::expr_res_<F,Args>)) ret;
+ };
+
+
+
+ // get_res_ is the entry point
+ // ------------------------------------
+
+ template <typename F,
+ typename A1 = mlc::none,
+ typename A2 = mlc::none,
+ typename A3 = mlc::none>
+ struct get_res_ : public mlc::if_< mlc_is_a(F, xtd::abstract::fun_expr_),
+ get_expr_res_<F, xtd::args_<A1, A2, A3> >,
+ do_get_res_<F, A1, A2, A3> >::ret
+ {};
+
+ // FIXME: add extra assertions here(?)
+
+
+
+ } // end of namespace xtd::internal
+
+} // end of namespace xtd
+
+
+
+#endif // ! EXTENDED_RES_HH
Index: xtd/cast.hh
--- xtd/cast.hh (revision 0)
+++ xtd/cast.hh (revision 0)
@@ -0,0 +1,126 @@
+// Copyright (C) 2002, 2005, 2006 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
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef EXTENDED_CAST_HH
+# define EXTENDED_CAST_HH
+
+# include <mlc/pair.hh>
+
+# include <xtd/abstract/plain_fun.hh>
+# include <xtd/abstract/meta_fun.hh>
+# include <xtd/mexpr.hh>
+
+
+
+namespace xtd
+{
+
+ /*! \class xtd::plain_cast_<Dest>
+ **
+ ** FIXME: doc
+ */
+
+ template <typename Dest, typename Src> struct plain_cast_; // fwd decl
+
+ template <typename Dest, typename Src>
+ struct fun_traits_< plain_cast_<Dest, Src> >
+ {
+ typedef Src arg_type;
+ typedef Dest res_type;
+ };
+
+ template <typename Dest, typename Src>
+ struct plain_cast_ : public abstract::plain_nary_fun_< 1, plain_cast_<Dest,
Src> >
+ {
+ Dest impl_op(const Src& arg) const
+ {
+ return Dest(arg);
+ }
+ };
+
+
+
+
+ // equipment for xtd::meta_cast_<Dest>
+
+ template <typename Dest> struct meta_cast_; // fwd decl
+
+ template <typename Dest, typename A>
+ struct res_< meta_cast_<Dest>, A >
+ {
+ typedef Dest ret;
+ };
+
+
+ /*! \class xtd::meta_cast_<Dest>
+ **
+ ** FIXME: doc
+ */
+
+ template <typename Dest>
+ struct meta_cast_ : public abstract::meta_nary_fun_< 1, meta_cast_<Dest> >
+ {
+ template <typename A>
+ Dest impl_calc(const A& a) const
+ // ---------
+ {
+ return Dest(a);
+ }
+ };
+
+
+
+ /*! \function xtd::cast_<Dest>(arg)
+ **
+ ** This function mimics the behavior of the method:
+ **
+ ** xtd::meta_nary_fun_<1, E>::operator(const A& a)
+ **
+ ** The method is thus turned into a function where E, the
+ ** unary meta function actually is meta_cast_<Dest>.
+ */
+
+ template <typename Dest, typename A>
+ typename xtd::case_< xtd::tag::meta_1ary_fun_operator,
+ mlc::pair_< meta_cast_<Dest>,
+ A >
+ >::ret::res
+ cast_(const A& a)
+ {
+ typedef typename xtd::case_< xtd::tag::meta_1ary_fun_operator,
+ mlc::pair_< meta_cast_<Dest>, A> >::ret
case_t;
+ static const meta_cast_<Dest> the_;
+ return case_t::impl(&the_, a);
+ }
+
+
+
+} // end of namespace xtd
+
+
+
+#endif // ! EXTENDED_CAST_HH
Index: xtd/math/trigo.hh
--- xtd/math/trigo.hh (revision 0)
+++ xtd/math/trigo.hh (revision 0)
@@ -0,0 +1,154 @@
+// Copyright (C) 2002, 2005, 2006 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
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef EXTENDED_MATH_TRIGO_HH
+# define EXTENDED_MATH_TRIGO_HH
+
+# include <cmath>
+
+# include <mlc/assert.hh>
+# include <mlc/logic.hh>
+# include <mlc/cmp.hh>
+
+# include <xtd/abstract/plain_fun.hh>
+# include <xtd/mfun.hh>
+
+
+
+
+
+// FIXME: macro doc!
+
+# define xtd_decl_trigo_fun(FunName) \
+ \
+ template <typename T> struct FunName##_; \
+ \
+ template <typename T> \
+ struct fun_traits_< FunName##_<T> > \
+ \
+ : private mlc::assert_< mlc::or_list_< mlc::eq_<T, float>, \
+ mlc::eq_<T, double>, \
+ mlc::eq_<T, long double> >, \
+ xtd::ERROR::TRIGONOMETRY_ONLY_RUNS_ON_float_OR_double_OR_long_double > \
+ { \
+ typedef mlc::dummy arg_type; \
+ typedef mlc::dummy res_type; \
+ }; \
+ \
+ template <> \
+ struct fun_traits_< FunName##_<float> > \
+ { \
+ typedef float arg_type; \
+ typedef float res_type; \
+ }; \
+ \
+ template <> \
+ struct fun_traits_< FunName##_<double> > \
+ { \
+ typedef double arg_type; \
+ typedef double res_type; \
+ }; \
+ \
+ template <> \
+ struct fun_traits_< FunName##_<long double> > \
+ { \
+ typedef long double arg_type; \
+ typedef long double res_type; \
+ }; \
+ \
+ template <typename T> \
+ struct FunName##_ : public abstract::trigo_< T, FunName##_<T> > \
+ { \
+ typedef FunName##_<T> self; \
+ \
+ xtd_res(self) impl_op(const T& arg) const \
+ { \
+ return std::FunName(arg); \
+ } \
+ }; \
+ \
+ const FunName##_<float> f##FunName; \
+ const FunName##_<double> d##FunName; \
+ const FunName##_<long double> ld##FunName; \
+ \
+ typedef m1fun_<FunName##_> FunName##_type; \
+ const FunName##_type FunName; \
+ \
+ struct e_n_d__w_i_t_h__s_e_m_i_c_o_l_o_n
+
+
+
+namespace xtd
+{
+
+ namespace ERROR
+ {
+
+ struct TRIGONOMETRY_ONLY_RUNS_ON_float_OR_double_OR_long_double;
+
+ } // end of namespace xtd::ERROR
+
+
+ namespace abstract
+ {
+
+ template <typename T, typename E>
+ struct trigo_ :
+
+ private mlc::assert_< mlc::or_list_< mlc::eq_<T, float>,
+ mlc::eq_<T, double>,
+ mlc::eq_<T, long double> >,
+ xtd::ERROR::TRIGONOMETRY_ONLY_RUNS_ON_float_OR_double_OR_long_double >,
+
+ public abstract::plain_nary_fun_< 1, E >
+ {
+ protected:
+ trigo_() {}
+ };
+
+
+ } // end of namespace xtd::abstract
+
+
+ xtd_decl_trigo_fun(cos);
+ xtd_decl_trigo_fun(sin);
+ xtd_decl_trigo_fun(tan);
+
+ xtd_decl_trigo_fun(acos);
+ xtd_decl_trigo_fun(asin);
+ xtd_decl_trigo_fun(atan);
+
+ xtd_decl_trigo_fun(cosh);
+ xtd_decl_trigo_fun(sinh);
+ xtd_decl_trigo_fun(tanh);
+
+
+} // end of namespace xtd
+
+
+
+#endif // ! EXTENDED_MATH_COS_HH
Index: xtd/math/arith.hh
--- xtd/math/arith.hh (revision 0)
+++ xtd/math/arith.hh (revision 0)
@@ -0,0 +1,104 @@
+// Copyright (C) 2002, 2005, 2006 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
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef EXTENDED_MATH_ARITH_HH
+# define EXTENDED_MATH_ARITH_HH
+
+# include <xtd/builtin/traits.hh>
+# include <xtd/abstract/plain_fun.hh>
+# include <xtd/mfun.hh>
+
+
+
+namespace xtd
+{
+
+
+ /*! \class xtd::plain_plus_<T>
+ **
+ ** FIXME: doc
+ */
+
+ template <typename T1, typename T2> struct plain_plus_; // fwd decl
+
+ template <typename T1, typename T2>
+ struct fun_traits_< plain_plus_<T1, T2> >
+ {
+ typedef T1 arg1_type;
+ typedef T2 arg2_type;
+ typedef xtd_plus(T1, T2) res_type;
+ };
+
+ template <typename T1, typename T2>
+ struct plain_plus_ : public abstract::plain_nary_fun_< 2, plain_plus_<T1, T2>
>
+ {
+ typedef plain_plus_<T1, T2> self;
+ xtd_res(self) impl_op(const T1& arg1, const T2& arg2) const
+ {
+ return arg1 + arg2;
+ }
+ };
+
+ typedef m2fun_<plain_plus_> plus_type;
+ const plus_type plus;
+
+
+
+ /*! \class xtd::plain_mult_<T>
+ **
+ ** FIXME: doc
+ */
+
+ template <typename T1, typename T2> struct plain_mult_; // fwd decl
+
+ template <typename T1, typename T2>
+ struct fun_traits_< plain_mult_<T1, T2> >
+ {
+ typedef T1 arg1_type;
+ typedef T2 arg2_type;
+ typedef xtd_mult(T1, T2) res_type;
+ };
+
+ template <typename T1, typename T2>
+ struct plain_mult_ : public abstract::plain_nary_fun_< 2, plain_mult_<T1, T2>
>
+ {
+ typedef plain_mult_<T1, T2> self;
+ xtd_res(self) impl_op(const T1& arg1, const T2& arg2) const
+ {
+ return arg1 * arg2;
+ }
+ };
+
+ typedef m2fun_<plain_mult_> mult_type;
+ const mult_type mult;
+
+
+} // end of namespace xtd
+
+
+
+#endif // ! EXTENDED_MATH_ARITH_HH
Index: xtd/math/id.hh
--- xtd/math/id.hh (revision 0)
+++ xtd/math/id.hh (revision 0)
@@ -0,0 +1,68 @@
+// Copyright (C) 2002, 2005, 2006 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
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef EXTENDED_MATH_ID_HH
+# define EXTENDED_MATH_ID_HH
+
+# include <xtd/abstract/plain_fun.hh>
+# include <xtd/mfun.hh>
+
+
+namespace xtd
+{
+
+ /*! \class xtd::plain_id_<T>
+ **
+ ** FIXME: doc
+ */
+
+ template <typename T> struct plain_id_; // fwd decl
+
+ template <typename T>
+ struct fun_traits_< plain_id_<T> >
+ {
+ typedef T arg_type;
+ typedef T res_type;
+ };
+
+ template <typename T>
+ struct plain_id_ : public abstract::plain_nary_fun_< 1, plain_id_<T> >
+ {
+ T impl_op(const T& arg) const
+ {
+ return arg;
+ }
+ };
+
+ // id
+ const m1fun_<plain_id_> id;
+
+} // end of namespace xtd
+
+
+
+#endif // ! EXTENDED_MATH_ID_HH
Index: xtd/mexpr.hh
--- xtd/mexpr.hh (revision 0)
+++ xtd/mexpr.hh (revision 0)
@@ -0,0 +1,413 @@
+// Copyright (C) 2002, 2005, 2006 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
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef EXTENDED_MEXPR_HH
+# define EXTENDED_MEXPR_HH
+
+# include <mlc/case.hh>
+# include <mlc/assert.hh>
+# include <mlc/is_a.hh>
+
+# include <xtd/args.hh>
+# include <xtd/res.hh>
+# include <xtd/abstract/nary_fun.hh>
+# include <xtd/abstract/fun_expr.hh>
+
+
+
+
+
+namespace xtd
+{
+
+ namespace ERROR
+ {
+
+ struct FIXME;
+
+ } // end of namespace xtd::ERROR
+
+
+
+ // FIXME: temporary code; move it elsewhere!
+
+ template <unsigned n1, unsigned n2>
+ struct n_max {
+ static const unsigned ret = (n1 > n2 ? n1 : n2);
+ };
+
+
+
+ // m0expr_
+
+ template <typename F>
+ struct m0expr_;
+
+
+ template <typename F>
+ struct nargs_< m0expr_<F> >
+ {
+ static const unsigned ret = 0;
+ };
+
+
+ template <typename F, typename Args>
+ struct expr_res_< m0expr_<F>, Args >
+ {
+ // f()
+ typedef xtd_res_0(F) ret;
+ };
+
+
+ template <typename F>
+ struct m0expr_
+
+ : public abstract::nary_fun_expr_< 0, m0expr_<F> >
+ {
+ const F f;
+
+ m0expr_() :
+ f()
+ {}
+
+ m0expr_(const F& f) :
+ f(f)
+ {
+ mlc::assert_< mlc_is_a(F, abstract::nary_fun_<0>),
+ ERROR::FIXME >::check();
+ }
+
+ template <typename Args>
+ xtd_res_0(F) impl_eval(const Args& as) const
+ {
+ return f();
+ }
+ };
+
+
+
+ // m1expr_
+
+ template <typename F,
+ typename Expr>
+ struct m1expr_;
+
+
+ template <typename F,
+ typename Expr>
+ struct nargs_< m1expr_<F, Expr> >
+ {
+ static const unsigned ret = xtd_nargs(Expr);
+ };
+
+
+ template <typename F,
+ typename Expr,
+ typename Args>
+ struct expr_res_< m1expr_<F, Expr>,
+ Args >
+ {
+ // f(expr.eval(as))
+ typedef xtd_expr_res(Expr, Args) eval_t;
+ typedef xtd_res_1(F, eval_t) ret;
+ };
+
+
+ template <typename F,
+ typename Expr>
+ struct m1expr_
+
+ : public abstract::nary_fun_expr_< xtd_nargs(Expr),
+ m1expr_<F, Expr> >
+ {
+ typedef m1expr_<F, Expr> self;
+
+ const F f;
+ const Expr expr;
+
+ m1expr_() :
+ f(),
+ expr()
+ {}
+
+ m1expr_(const abstract::fun_expr_<Expr>& expr) :
+ f(),
+ expr(exact_of(expr))
+ {}
+
+ m1expr_(const F& f,
+ const abstract::fun_expr_<Expr>& expr) :
+ f(f),
+ expr(exact_of(expr))
+ {
+ mlc::assert_< mlc_is_a(F, abstract::nary_fun_<1>),
+ ERROR::FIXME >::check();
+ }
+
+ template <typename Args>
+ xtd_expr_res(self, Args) impl_eval(const Args& as) const
+ {
+ return f(expr.eval(as));
+ }
+ };
+
+
+
+
+ // m2expr_
+
+
+ template <typename F,
+ typename Expr1, typename Expr2>
+ struct m2expr_;
+
+
+ template <typename F,
+ typename Expr1, typename Expr2>
+ struct nargs_< m2expr_<F, Expr1, Expr2> >
+ {
+ static const unsigned ret = n_max< xtd_nargs(Expr1),
+ xtd_nargs(Expr2) >::ret;
+ };
+
+
+ template <typename F,
+ typename Expr1, typename Expr2,
+ typename Args>
+ struct expr_res_< m2expr_<F, Expr1, Expr2>,
+ Args >
+ {
+ // f(expr1.eval(as), expr2.eval(as))
+ typedef xtd_expr_res(Expr1, Args) eval1_t;
+ typedef xtd_expr_res(Expr2, Args) eval2_t;
+ typedef xtd_res_2(F, eval1_t, eval2_t) ret;
+ };
+
+
+ template <typename F,
+ typename Expr1, typename Expr2>
+ struct m2expr_
+
+ : public abstract::nary_fun_expr_< xtd_nargs(mlc_comma_2(m2expr_<F, Expr1,
Expr2>)),
+ m2expr_<F, Expr1, Expr2> >
+ {
+ typedef m2expr_<F, Expr1, Expr2> self;
+
+ const F f;
+ const Expr1 expr1;
+ const Expr2 expr2;
+
+ m2expr_() :
+ f(),
+ expr1(),
+ expr2()
+ {}
+
+ m2expr_(const abstract::fun_expr_<Expr1>& expr1,
+ const abstract::fun_expr_<Expr2>& expr2) :
+ f(),
+ expr1(exact_of(expr1)),
+ expr2(exact_of(expr2))
+ {}
+
+ m2expr_(const F& f,
+ const abstract::fun_expr_<Expr1>& expr1,
+ const abstract::fun_expr_<Expr2>& expr2) :
+ f(f),
+ expr1(exact_of(expr1)),
+ expr2(exact_of(expr2))
+ {
+ mlc::assert_< mlc_is_a(F, abstract::nary_fun_<2>),
+ ERROR::FIXME >::check();
+ }
+
+ template <typename Args>
+ xtd_expr_res(self, Args) impl_eval(const Args& as) const
+ {
+ return f(expr1.eval(as), expr2.eval(as));
+ }
+ };
+
+
+
+ // m3expr_
+
+ template <typename F,
+ typename Expr1, typename Expr2, typename Expr3>
+ struct m3expr_;
+
+
+ template <typename F,
+ typename Expr1, typename Expr2, typename Expr3>
+ struct nargs_< m3expr_<F, Expr1, Expr2, Expr3> >
+ {
+ static const unsigned ret = n_max< xtd_nargs(Expr1),
+ n_max< xtd_nargs(Expr2),
+ xtd_nargs(Expr3) >::ret >::ret;
+ };
+
+
+ template <typename F,
+ typename Expr1, typename Expr2, typename Expr3,
+ typename Args>
+ struct expr_res_< m3expr_<F, Expr1, Expr2, Expr3>,
+ Args >
+ {
+ // f(expr1.eval(as), expr2.eval(as), expr3.eval(as))
+ typedef xtd_expr_res(Expr1, Args) eval1_t;
+ typedef xtd_expr_res(Expr2, Args) eval2_t;
+ typedef xtd_expr_res(Expr3, Args) eval3_t;
+ typedef xtd_res_3(F, eval1_t, eval2_t, eval3_t) ret;
+ };
+
+
+ template <typename F,
+ typename Expr1, typename Expr2, typename Expr3>
+ struct m3expr_
+
+ : public abstract::nary_fun_expr_< xtd_nargs(mlc_comma_3(m3expr_<F, Expr1,
Expr2, Expr3>)),
+ m3expr_<F, Expr1, Expr2, Expr3> >
+ {
+ typedef m3expr_<F, Expr1, Expr2, Expr3> self;
+
+ const F f;
+ const Expr1 expr1;
+ const Expr2 expr2;
+ const Expr3 expr3;
+
+ m3expr_() :
+ f(),
+ expr1(),
+ expr2(),
+ expr3()
+ {}
+
+ m3expr_(const abstract::fun_expr_<Expr1>& expr1,
+ const abstract::fun_expr_<Expr2>& expr2,
+ const abstract::fun_expr_<Expr3>& expr3) :
+ f(),
+ expr1(exact_of(expr1)),
+ expr2(exact_of(expr2)),
+ expr3(exact_of(expr3))
+ {}
+
+ m3expr_(const F& f,
+ const abstract::fun_expr_<Expr1>& expr1,
+ const abstract::fun_expr_<Expr2>& expr2,
+ const abstract::fun_expr_<Expr3>& expr3) :
+ f(f),
+ expr1(exact_of(expr1)),
+ expr2(exact_of(expr2)),
+ expr3(exact_of(expr3))
+ {
+ mlc::assert_< mlc_is_a(F, abstract::nary_fun_<3>),
+ ERROR::FIXME >::check();
+ }
+
+ template <typename Args>
+ xtd_expr_res(self, Args) impl_eval(const Args& as) const
+ {
+ return f(expr1.eval(as), expr2.eval(as), expr3.eval(as));
+ }
+ };
+
+
+
+
+
+ // meta_nary_fun_<1, F>::operator()(abstract::fun_expr_<Expr>& expr)
const
+
+ template <typename F, typename Expr>
+ struct case_< tag::meta_1ary_fun_operator,
+ mlc::pair_<F, Expr>,
+ 1 >
+ : public mlc::where_< mlc_is_a(Expr, abstract::fun_expr_) >
+ {
+ typedef m1expr_<F, Expr> res;
+
+ static res impl(const abstract::meta_nary_fun_<1, F>* this_,
+ const abstract::fun_expr_<Expr>& expr)
+ {
+ res tmp(exact_of(*this_), expr);
+ return tmp;
+ }
+ };
+
+
+ // meta_nary_fun_<2, F>::operator()(const fun_expr_<Expr1>& expr1,
+ // const fun_expr_<Expr2>& expr2) const
+
+ template <typename F, typename Expr1, typename Expr2>
+ struct case_< tag::meta_2ary_fun_operator,
+ mlc::valist_<F, Expr1, Expr2>,
+ 1 >
+ : public mlc::where_< mlc::and_< mlc_is_a(Expr1, abstract::fun_expr_),
+ mlc_is_a(Expr2, abstract::fun_expr_) > >
+ {
+ typedef m2expr_<F, Expr1, Expr2> res;
+
+ static res impl(const abstract::meta_nary_fun_<2, F>* this_,
+ const abstract::fun_expr_<Expr1>& expr1,
+ const abstract::fun_expr_<Expr2>& expr2)
+ {
+ res tmp(exact_of(*this_), expr1, expr2);
+ return tmp;
+ }
+ };
+
+
+ // meta_nary_fun_<3, F>::operator()(const fun_expr_<Expr1>& expr1,
+ // const fun_expr_<Expr2>& expr2,
+ // const fun_expr_<Expr3>& expr3) const
+
+ template <typename F, typename Expr1, typename Expr2, typename Expr3>
+ struct case_< tag::meta_3ary_fun_operator,
+ mlc::valist_<F, Expr1, Expr2, Expr3>,
+ 1 >
+ : public mlc::where_< mlc::and_< mlc_is_a(Expr1, abstract::fun_expr_),
+ mlc::and_< mlc_is_a(Expr2, abstract::fun_expr_),
+ mlc_is_a(Expr3, abstract::fun_expr_) > > >
+ {
+ typedef m3expr_<F, Expr1, Expr2, Expr3> res;
+
+ static res impl(const abstract::meta_nary_fun_<3, F>* this_,
+ const abstract::fun_expr_<Expr1>& expr1,
+ const abstract::fun_expr_<Expr2>& expr2,
+ const abstract::fun_expr_<Expr3>& expr3)
+ {
+ res tmp(exact_of(*this_), expr1, expr2, expr3);
+ return tmp;
+ }
+ };
+
+
+
+} // end of namespace xtd
+
+
+
+#endif // ! EXTENDED_MEXPR_HH
Index: xtd/args.hh
--- xtd/args.hh (revision 0)
+++ xtd/args.hh (revision 0)
@@ -0,0 +1,179 @@
+// Copyright (C) 2002, 2005, 2006 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
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef EXTENDED_ARGS_HH
+# define EXTENDED_ARGS_HH
+
+# include <mlc/flags.hh>
+
+
+
+// FIXME: doc
+// FIXME: this code should be rewritten to check that
+// FIXME: xtd::nargs_<F>::ret is properly defined; see for
+// FIXME: instance, the code of xtd_res or xtd_arg1...
+
+# define xtd_nargs(F) xtd::nargs_<F>::ret
+
+
+
+namespace xtd
+{
+
+ namespace abstract
+ {
+ /*! \class xtd::abstract::args
+ **
+ ** FIXME: Abstract base class for args_<..>
+ */
+
+ struct args
+ {
+ protected:
+ args() {}
+ };
+
+ } // end of namespace xtd::abstract
+
+
+
+
+ /*! \class xtd::nargs_<F>
+ **
+ ** FIXME: doc
+ ** FIXME: and add a mechanism so that the type of F is checked
+ ** FIXME: Cf. get_res0_ in xtd/abstract/meta_fun.hh
+ */
+
+ template <typename F>
+ struct nargs_;
+
+
+
+
+ /*! \class xtd::args_<A1, ..>
+ **
+ ** FIXME: to pack arguments
+ */
+
+ // three args
+
+ template <typename A1 = mlc::none,
+ typename A2 = mlc::none,
+ typename A3 = mlc::none>
+ struct args_ : public abstract::args
+ {
+ args_(const A1& arg1, const A2& arg2, const A3& arg3)
+ : arg1(arg1),
+ arg2(arg2),
+ arg3(arg3)
+ {}
+ const A1 arg1;
+ const A2 arg2;
+ const A3 arg3;
+ typedef A1 arg1_type;
+ typedef A2 arg2_type;
+ typedef A3 arg3_type;
+ };
+
+ template <typename A1, typename A2, typename A3>
+ args_<A1,A2,A3> mk_args(const A1& arg1, const A2& arg2, const A3&
arg3)
+ {
+ args_<A1,A2,A3> tmp(arg1, arg2, arg3);
+ return tmp;
+ }
+
+
+ // no arg
+
+ template <>
+ struct args_<> : public abstract::args
+ {
+ args_()
+ {}
+ typedef mlc::none arg1_type;
+ typedef mlc::none arg2_type;
+ typedef mlc::none arg3_type;
+ };
+
+ args_<> mk_args()
+ {
+ args_<> tmp;
+ return tmp;
+ }
+
+
+ // a single arg
+
+ template <typename A1>
+ struct args_< A1 > : public abstract::args
+ {
+ args_(const A1& arg1)
+ : arg1(arg1)
+ {}
+ const A1 arg1;
+ typedef A1 arg1_type;
+ typedef mlc::none arg2_type;
+ typedef mlc::none arg3_type;
+ };
+
+ template <typename A1>
+ args_<A1> mk_args(const A1& arg1)
+ {
+ args_<A1> tmp(arg1);
+ return tmp;
+ }
+
+
+ // a couple of args
+
+ template <typename A1, typename A2>
+ struct args_< A1, A2 > : public abstract::args
+ {
+ args_(const A1& arg1, const A2& arg2)
+ : arg1(arg1),
+ arg2(arg2)
+ {}
+ const A1 arg1;
+ const A2 arg2;
+ typedef A1 arg1_type;
+ typedef A2 arg2_type;
+ typedef mlc::none arg3_type;
+ };
+
+ template <typename A1, typename A2>
+ args_<A1,A2> mk_args(const A1& arg1, const A2& arg2)
+ {
+ args_<A1,A2> tmp(arg1, arg2);
+ return tmp;
+ }
+
+
+} // end of namespace xtd
+
+
+#endif // ! EXTENDED_ARGS_HH
Index: xtd/literal.hh
--- xtd/literal.hh (revision 0)
+++ xtd/literal.hh (revision 0)
@@ -0,0 +1,113 @@
+// Copyright (C) 2002, 2005, 2006 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
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef EXTENDED_LITERAL_HH
+# define EXTENDED_LITERAL_HH
+
+# include <xtd/abstract/plain_fun.hh>
+
+
+
+namespace xtd
+{
+
+ /*! \class xtd::literal_<T>
+ **
+ ** FIXME: doc
+ */
+
+ template <typename T> struct literal_; // fwd decl
+
+ template <typename T>
+ struct fun_traits_< literal_<T> >
+ {
+ typedef T res_type;
+ };
+
+ template <typename T>
+ struct literal_ : public abstract::plain_nary_fun_< 0, literal_<T> >
+ {
+ const T value;
+
+ literal_(const T& value)
+ : value(value)
+ {}
+
+ T impl_op() const
+ {
+ return this->value;
+ }
+ };
+
+
+
+ // literal as fun expression
+ // FIXME: this should be the only version (?)
+ // FIXME: we should remove the plain version (?)
+
+ template <typename T>
+ struct literal_expr_;
+
+
+ template <typename T>
+ struct nargs_< literal_expr_<T> >
+ {
+ static const unsigned ret = 0;
+ };
+
+
+ template <typename T, typename Args>
+ struct expr_res_< literal_expr_<T>, Args >
+ {
+ typedef T ret;
+ };
+
+
+ template <typename T>
+ struct literal_expr_
+
+ : public abstract::nary_fun_expr_< 0, literal_expr_<T> >
+ {
+ const T value;
+
+ literal_expr_(const T& value) :
+ value(value)
+ {}
+
+ template <typename Args>
+ T impl_eval(const Args&) const
+ {
+ return this->value;
+ }
+ };
+
+
+} // end of namespace xtd
+
+
+
+#endif // ! EXTENDED_LITERAL_HH
Index: xtd/ops_expr.hh
--- xtd/ops_expr.hh (revision 0)
+++ xtd/ops_expr.hh (revision 0)
@@ -0,0 +1,84 @@
+// Copyright (C) 2002, 2005, 2006 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
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef EXTENDED_OPS_EXPR_HH
+# define EXTENDED_OPS_EXPR_HH
+
+# include <mlc/case.hh>
+
+# include <xtd/abstract/fun_expr.hh>
+# include <xtd/mexpr.hh>
+# include <xtd/math/arith.hh>
+
+
+namespace xtd
+{
+
+// namespace abstract
+// {
+
+
+ // +
+
+ template <typename L, typename R>
+ xtd::m2expr_<xtd::plus_type, L, R>
+ operator + (const xtd::abstract::fun_expr_<L>& lexpr,
+ const xtd::abstract::fun_expr_<R>& rexpr)
+ {
+ xtd::m2expr_<xtd::plus_type, L, R> tmp(lexpr, rexpr);
+ return tmp;
+ }
+
+ // HERE
+
+// template <typename R>
+// xtd::m2expr_<xtd::plus_type, m0expr<literal_<int> >, R>
+// operator + (int i,
+// const xtd::abstract::fun_expr_<R>& rexpr)
+// {
+// xtd::m2expr<xtd::plus_type, L, R> tmp;
+// return tmp;
+// }
+
+
+ // *
+
+ template <typename L, typename R>
+ xtd::m2expr_<xtd::mult_type, L, R>
+ operator * (const xtd::abstract::fun_expr_<L>& lexpr,
+ const xtd::abstract::fun_expr_<R>& rexpr)
+ {
+ xtd::m2expr_<xtd::mult_type, L, R> tmp(lexpr, rexpr);
+ return tmp;
+ }
+
+// } // end of namespace xtd::abstract
+
+} // end of namespace xtd
+
+
+#endif // ! EXTENDED_OPS_EXPR_HH
Index: xtd/abstract/nary_fun.hh
--- xtd/abstract/nary_fun.hh (revision 0)
+++ xtd/abstract/nary_fun.hh (revision 0)
@@ -0,0 +1,53 @@
+// Copyright (C) 2002, 2005, 2006 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
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef EXTENDED_ABSTRACT_NARY_FUN_HH
+# define EXTENDED_ABSTRACT_NARY_FUN_HH
+
+
+namespace xtd
+{
+
+ namespace abstract
+ {
+
+ // FIXME: doc!
+
+ template <unsigned n>
+ class nary_fun_
+ {
+ protected:
+ nary_fun_()
+ {}
+ };
+
+ } // end of namespace xtd::abstract
+
+} // end of namespace xtd
+
+
+#endif // ! EXTENDED_ABSTRACT_NARY_FUN_HH
Index: xtd/abstract/exact.hh
--- xtd/abstract/exact.hh (revision 0)
+++ xtd/abstract/exact.hh (revision 0)
@@ -0,0 +1,93 @@
+// Copyright (C) 2002, 2005, 2006 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
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef EXTENDED_ABSTRACT_EXACT_HH
+# define EXTENDED_ABSTRACT_EXACT_HH
+
+
+namespace xtd
+{
+
+ namespace abstract
+ {
+
+ template <typename E> class plain_fun_;
+ template <typename E> class meta_fun_;
+ template <typename E> class fun_expr_;
+
+ } // end of namespace xtd::abstract
+
+
+ // plain_fun_
+
+ template <typename E>
+ const E* exact_of(const abstract::plain_fun_<E>* f)
+ {
+ return (const E*)(const void*)(f);
+ }
+
+ template <typename E>
+ const E& exact_of(const abstract::plain_fun_<E>& f)
+ {
+ return *exact_of(&f);
+ }
+
+
+ // meta_fun_
+
+ template <typename E>
+ const E* exact_of(const abstract::meta_fun_<E>* f)
+ {
+ return (const E*)(const void*)(f);
+ }
+
+ template <typename E>
+ const E& exact_of(const abstract::meta_fun_<E>& f)
+ {
+ return *exact_of(&f);
+ }
+
+
+ // fun_expr_
+
+ template <typename E>
+ const E* exact_of(const abstract::fun_expr_<E>* f)
+ {
+ return (const E*)(const void*)(f);
+ }
+
+ template <typename E>
+ const E& exact_of(const abstract::fun_expr_<E>& f)
+ {
+ return *exact_of(&f);
+ }
+
+
+} // end of namespace xtd
+
+
+#endif // ! EXTENDED_ABSTRACT_EXACT_HH
Index: xtd/abstract/fun_expr.hh
--- xtd/abstract/fun_expr.hh (revision 0)
+++ xtd/abstract/fun_expr.hh (revision 0)
@@ -0,0 +1,225 @@
+// Copyright (C) 2002, 2005, 2006 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
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef EXTENDED_ABSTRACT_FUN_EXPR_HH
+# define EXTENDED_ABSTRACT_FUN_EXPR_HH
+
+# include <mlc/bool.hh>
+# include <mlc/is_a.hh>
+# include <mlc/comma.hh>
+
+# include <xtd/args.hh>
+# include <xtd/res.hh>
+# include <xtd/abstract/exact.hh>
+# include <xtd/abstract/meta_fun.hh>
+
+
+
+
+namespace xtd
+{
+
+ namespace ERROR
+ {
+
+ struct INTERNAL_ILL_FORMED_CALL_TO_xtd_fun_expr_eval;
+
+ } // end of namespace xtd::ERROR
+
+
+
+ namespace abstract
+ {
+
+ /*! \class xtd::abstract::fun_expr_<E>
+ **
+ ** Abstract base class for function expressions. Parameter E is
+ ** the exact type of the function expression.
+ **
+ ** Design note: this class does not derive from xtd::abstract::any
+ ** to avoid diamond inheritance since fun_expr classes are also
+ ** meta_fun classes.
+ */
+
+ template <typename E>
+ class fun_expr_
+
+ // FIXME: at that point, we should verify that nargs_<E> is user-defined...
+
+ : public fun_<E>
+ {
+ public:
+
+ // evaluation:
+
+ template <typename Args>
+ xtd_expr_res(E, Args)
+ eval(const Args& as) const
+ {
+ mlc::assert_< mlc_is_a(Args, xtd::abstract::args),
+ xtd::ERROR::INTERNAL_ILL_FORMED_CALL_TO_xtd_fun_expr_eval
>::check();
+ return exact_of(this)->impl_eval(as);
+ }
+
+ // FIXME: the get_nargs method is obsolete; remove it!
+ unsigned nargs() const { return xtd_nargs(E); }
+
+ protected:
+ fun_expr_() {}
+ };
+
+
+
+ /*! \class xtd::abstract::nary_fun_expr_<n, E>
+ **
+ ** Abstract base class for function expressions with an explicit
+ ** number of arguments.
+ **
+ ** Parameter n is the number of arguments with n being 0, 1, 2, or
+ ** 3.
+ **
+ ** Parameter E is the exact type of the function.
+ */
+
+ template <unsigned n, typename E>
+ class nary_fun_expr_;
+
+
+
+ /*! \class xtd::abstract::nary_fun_expr_<0, E>
+ **
+ ** Abstract base class for function expressions taking no
+ ** argument.
+ **
+ ** Parameter E is the exact type of the function.
+ */
+
+ template <typename E>
+ class nary_fun_expr_< 0, E >
+
+ : public fun_expr_<E>,
+ public meta_nary_fun_<0, E>
+ {
+ public:
+ xtd_res_0(E) impl_calc() const
+ {
+ return this->eval(mk_args());
+ }
+ protected:
+ nary_fun_expr_() {}
+ };
+
+
+
+ /*! \class xtd::abstract::nary_fun_expr_<1, E>
+ **
+ ** Abstract base class for function expressions taking one
+ ** argument.
+ **
+ ** Parameter E is the exact type of the function.
+ */
+
+ template <typename E>
+ class nary_fun_expr_< 1, E >
+
+ : public fun_expr_<E>,
+ public meta_nary_fun_<1, E>
+ {
+ public:
+ template <typename A>
+ xtd_res_1(E, A)
+ impl_calc(const A& a) const
+ {
+ return this->eval(mk_args(a));
+ }
+ protected:
+ nary_fun_expr_() {}
+ };
+
+
+
+ /*! \class xtd::abstract::nary_fun_expr_<2, E>
+ **
+ ** Abstract base class for function expressions taking two
+ ** arguments.
+ **
+ ** Parameter E is the exact type of the function.
+ */
+
+ template <typename E>
+ class nary_fun_expr_< 2, E >
+
+ : public fun_expr_<E>,
+ public meta_nary_fun_<2, E>
+ {
+ public:
+ template <typename A1, typename A2>
+ xtd_res_2(E, A1, A2)
+ impl_calc(const A1& a1, const A2& a2) const
+ {
+ return this->eval(mk_args(a1, a2));
+ }
+ protected:
+ nary_fun_expr_() {}
+ };
+
+
+
+ /*! \class xtd::abstract::nary_fun_expr_<3, E>
+ **
+ ** Abstract base class for function expressions taking three
+ ** arguments.
+ **
+ ** Parameter E is the exact type of the function.
+ */
+
+ template <typename E>
+ class nary_fun_expr_< 3, E >
+
+ : public fun_expr_<E>,
+ public meta_nary_fun_<3, E>
+ {
+ public:
+ template <typename A1, typename A2, typename A3>
+ xtd_res_3(E, A1, A2, A3)
+ impl_calc(const A1& a1, const A2& a2, const A3& a3) const
+ {
+ return this->eval(mk_args(a1, a2, a3));
+ }
+ protected:
+ nary_fun_expr_() {}
+ };
+
+
+ } // end of namespace xtd::abstract
+
+
+} // end of namespace xtd
+
+
+
+#endif // ! EXTENDED_ABSTRACT_FUN_EXPR_HH
Index: xtd/abstract/any.hh
--- xtd/abstract/any.hh (revision 0)
+++ xtd/abstract/any.hh (revision 0)
@@ -0,0 +1,67 @@
+// Copyright (C) 2002, 2005, 2006 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
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef EXTENDED_ABSTRACT_ANY_HH
+# define EXTENDED_ABSTRACT_ANY_HH
+
+
+
+namespace xtd
+{
+
+ namespace abstract
+ {
+
+ /*! \class xtd::abstract::any
+ **
+ ** Abstract base class for static hierarchies in xtd. Parameter E
+ ** is the exact type.
+ */
+
+ template <class E>
+ class any
+ {
+ public:
+
+ typedef E exact_type;
+
+ // exact is not provided by stc::any so that xtd is independant
+ // from the stc lib.
+ E& exact() { return *(E*)(void*)(this); }
+ const E& exact() const { return *(const E*)(const void*)(this); }
+
+ protected:
+ any() {}
+ };
+
+
+ } // end of namespace abstract::xtd
+
+} // end of namespace xtd
+
+
+#endif // ! EXTENDED_ABSTRACT_ANY_HH
Index: xtd/abstract/fun.hh
--- xtd/abstract/fun.hh (revision 0)
+++ xtd/abstract/fun.hh (revision 0)
@@ -0,0 +1,58 @@
+// Copyright (C) 2002, 2005, 2006 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
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef EXTENDED_ABSTRACT_FUN_HH
+# define EXTENDED_ABSTRACT_FUN_HH
+
+
+namespace xtd
+{
+
+ namespace abstract
+ {
+
+ /*! \class xtd::abstract::fun_
+ **
+ ** Abstract base class for xtd functions. Parameter E is the
+ ** exact type of the function.
+ */
+
+ template <typename E>
+ class fun_
+ {
+ protected:
+ fun_() {}
+ };
+
+
+ } // end of namespace xtd::abstract
+
+} // end of namespace xtd
+
+
+
+#endif // ! EXTENDED_ABSTRACT_FUN_HH
Index: xtd/abstract/plain_fun.hh
--- xtd/abstract/plain_fun.hh (revision 0)
+++ xtd/abstract/plain_fun.hh (revision 0)
@@ -0,0 +1,271 @@
+// Copyright (C) 2002, 2005, 2006 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
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef EXTENDED_ABSTRACT_PLAIN_FUN_HH
+# define EXTENDED_ABSTRACT_PLAIN_FUN_HH
+
+# include <mlc/flags.hh>
+# include <mlc/bool.hh> // FIXME: should be assert.hh
+# include <mlc/is_a.hh>
+# include <mlc/typedef.hh>
+
+# include <xtd/abstract/exact.hh>
+# include <xtd/abstract/fun.hh>
+# include <xtd/abstract/nary_fun.hh>
+
+
+// macros
+
+# define xtd_arg(F) typename xtd::typedef_::arg_type::from_<xtd::fun_traits_<F>
>::ret
+
+# define xtd_arg1(F) typename
xtd::typedef_::arg1_type::from_<xtd::fun_traits_<F> >::ret
+# define xtd_arg2(F) typename
xtd::typedef_::arg2_type::from_<xtd::fun_traits_<F> >::ret
+# define xtd_arg3(F) typename
xtd::typedef_::arg3_type::from_<xtd::fun_traits_<F> >::ret
+
+# define xtd_res(F) typename xtd::typedef_::res_type::from_<xtd::fun_traits_<F>
>::ret
+
+
+
+
+namespace xtd
+{
+
+ namespace ERROR
+ {
+ struct SPECIALIZATION_OF_xtd_fun_traits_NOT_FOUND_FOR_AN_xtd_plain_fun;
+ struct xtd_fun_traits_SHOULD_DEFINE_res_type_FOR_AN_xtd_plain_fun;
+
+ struct
xtd_fun_traits_SHOULD_DEFINE_arg_type_FOR_AN_xtd_plain_nary_fun_WITH_n_BEING_1;
+
+ struct
xtd_fun_traits_SHOULD_DEFINE_arg1_type_FOR_AN_xtd_plain_nary_fun_WITH_n_BEING_2;
+ struct
xtd_fun_traits_SHOULD_DEFINE_arg2_type_FOR_AN_xtd_plain_nary_fun_WITH_n_BEING_2;
+
+ struct
xtd_fun_traits_SHOULD_DEFINE_arg1_type_FOR_AN_xtd_plain_nary_fun_WITH_n_BEING_3;
+ struct
xtd_fun_traits_SHOULD_DEFINE_arg2_type_FOR_AN_xtd_plain_nary_fun_WITH_n_BEING_3;
+ struct
xtd_fun_traits_SHOULD_DEFINE_arg3_type_FOR_AN_xtd_plain_nary_fun_WITH_n_BEING_3;
+
+ struct YOU_SHOULD_NOT_DERIVE_FROM_xtd_plain_fun_BUT_FROM_xtd_plain_nary_fun;
+
+ // FIXME: add error messages corresponding to definitions without sense
+ // FIXME: such as having arg2 when the plain function is unary
+
+ } // end of namespace xtd::ERROR
+
+
+ template <typename F>
+ struct fun_traits_ : public mlc::undefined
+ {
+ // nothing
+ };
+
+ mlc_decl_typedef(arg_type);
+
+ mlc_decl_typedef(arg1_type);
+ mlc_decl_typedef(arg2_type);
+ mlc_decl_typedef(arg3_type);
+
+ mlc_decl_typedef(res_type);
+
+
+ namespace abstract
+ {
+
+ // fwd decl
+ template <unsigned n, typename E> class plain_nary_fun_;
+
+
+
+ /*! \class xtd::abstract::plain_fun_
+ **
+ ** Abstract base class for plain functions. Parameter E is the
+ ** exact type of the function.
+ */
+
+ template <typename E>
+ class plain_fun_
+
+ : private mlc::assert_< mlc_is_not_a(xtd::fun_traits_<E>,
mlc::undefined),
+ xtd::ERROR::SPECIALIZATION_OF_xtd_fun_traits_NOT_FOUND_FOR_AN_xtd_plain_fun
>,
+
+ private mlc::assert_< mlc::neq_<xtd_res(E), mlc::not_found>,
+
xtd::ERROR::xtd_fun_traits_SHOULD_DEFINE_res_type_FOR_AN_xtd_plain_fun >,
+
+ public fun_<E>
+ {
+ protected:
+ plain_fun_(){
+ // FIXME: unsigned is parameter so mlc_is_a does not work
+// mlc::assert_< mlc_is_a(E, plain_nary_fun_),
+//
xtd::ERROR::YOU_SHOULD_NOT_DERIVE_FROM_xtd_plain_fun_BUT_FROM_xtd_plain_nary_fun
+// >::check();
+ }
+ };
+
+
+ /*! \class xtd::abstract::plain_nary_fun_<n, E>
+ **
+ ** Abstract base class for plain functions with an explicit number
+ ** of arguments.
+ **
+ ** Parameter n is the number of arguments with n being 0, 1, 2, or
+ ** 3.
+ **
+ ** Parameter E is the exact type of the function.
+ */
+
+ template <unsigned n, typename E>
+ class plain_nary_fun_;
+
+
+
+ /*! \class xtd::abstract::plain_nary_fun_<0, E>
+ **
+ ** Abstract base class for plain functions taking no argument.
+ ** This class is defined as a specialization.
+ **
+ ** Parameter E is the exact type of the function.
+ */
+
+ template <typename E>
+ class plain_nary_fun_< 0, E >
+
+ : public plain_fun_<E>,
+ public nary_fun_<0>
+ {
+ public:
+ xtd_res(E) operator()() const
+ {
+ return exact_of(this)->impl_op();
+ }
+ protected:
+ plain_nary_fun_() {}
+ };
+
+
+
+ /*! \class xtd::abstract::plain_nary_fun_<1, E>
+ **
+ ** Abstract base class for plain functions taking one argument.
+ ** This class is defined as a specialization.
+ **
+ ** Parameter E is the exact type of the function.
+ */
+
+ template <typename E>
+ class plain_nary_fun_< 1, E >
+
+ : public plain_fun_<E>,
+ public nary_fun_<1>,
+
+ private mlc::assert_< mlc::neq_<xtd_arg(E), mlc::not_found>,
+
xtd::ERROR::xtd_fun_traits_SHOULD_DEFINE_arg_type_FOR_AN_xtd_plain_nary_fun_WITH_n_BEING_1
>
+ {
+ public:
+ xtd_res(E) operator()(const xtd_arg(E)& arg) const
+ {
+ return exact_of(this)->impl_op(arg);
+ }
+ protected:
+ plain_nary_fun_() {}
+ };
+
+
+
+ /*! \class xtd::abstract::plain_nary_fun_<2, E>
+ **
+ ** Abstract base class for plain functions taking two arguments.
+ ** This class is defined as a specialization.
+ **
+ ** Parameter E is the exact type of the function.
+ */
+
+ template <typename E>
+ class plain_nary_fun_< 2, E >
+
+ : public plain_fun_<E>,
+ public nary_fun_<2>,
+
+ private mlc::assert_< mlc::neq_<xtd_arg1(E), mlc::not_found>,
+
xtd::ERROR::xtd_fun_traits_SHOULD_DEFINE_arg1_type_FOR_AN_xtd_plain_nary_fun_WITH_n_BEING_2
>,
+
+ private mlc::assert_< mlc::neq_<xtd_arg2(E), mlc::not_found>,
+
xtd::ERROR::xtd_fun_traits_SHOULD_DEFINE_arg2_type_FOR_AN_xtd_plain_nary_fun_WITH_n_BEING_2
>
+ {
+ public:
+ xtd_res(E) operator()(const xtd_arg1(E)& arg1,
+ const xtd_arg2(E)& arg2) const
+ {
+ return exact_of(this)->impl_op(arg1, arg2);
+ }
+ protected:
+ plain_nary_fun_() {}
+ };
+
+
+
+ /*! \class xtd::abstract::plain_nary_fun_<3, E>
+ **
+ ** Abstract base class for plain functions taking three arguments.
+ ** This class is defined as a specialization.
+ **
+ ** Parameter E is the exact type of the function.
+ */
+
+ template <typename E>
+ class plain_nary_fun_< 3, E >
+
+ : public plain_fun_<E>,
+ public nary_fun_<3>,
+
+ private mlc::assert_< mlc::neq_<xtd_arg1(E), mlc::not_found>,
+
xtd::ERROR::xtd_fun_traits_SHOULD_DEFINE_arg1_type_FOR_AN_xtd_plain_nary_fun_WITH_n_BEING_3
>,
+
+ private mlc::assert_< mlc::neq_<xtd_arg2(E), mlc::not_found>,
+
xtd::ERROR::xtd_fun_traits_SHOULD_DEFINE_arg2_type_FOR_AN_xtd_plain_nary_fun_WITH_n_BEING_3
>,
+
+ private mlc::assert_< mlc::neq_<xtd_arg3(E), mlc::not_found>,
+
xtd::ERROR::xtd_fun_traits_SHOULD_DEFINE_arg3_type_FOR_AN_xtd_plain_nary_fun_WITH_n_BEING_3
>
+ {
+ public:
+ xtd_res(E) operator()(const xtd_arg1(E)& arg1,
+ const xtd_arg2(E)& arg2,
+ const xtd_arg3(E)& arg3) const
+ {
+ return exact_of(this)->impl_op(arg1, arg2, arg3);
+ }
+ protected:
+ plain_nary_fun_() {}
+ };
+
+
+ } // end of namespace xtd::abstract
+
+} // end of namespace xtd
+
+
+
+#endif // ! EXTENDED_ABSTRACT_PLAIN_FUN_HH
Index: xtd/abstract/meta_fun.hh
--- xtd/abstract/meta_fun.hh (revision 0)
+++ xtd/abstract/meta_fun.hh (revision 0)
@@ -0,0 +1,290 @@
+// Copyright (C) 2002, 2005, 2006 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
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef EXTENDED_ABSTRACT_META_FUN_HH
+# define EXTENDED_ABSTRACT_META_FUN_HH
+
+# include <mlc/pair.hh>
+# include <mlc/valist.hh>
+
+# include <xtd/abstract/exact.hh>
+# include <xtd/abstract/fun.hh>
+# include <xtd/abstract/nary_fun.hh>
+# include <xtd/args.hh>
+# include <xtd/res.hh>
+# include <xtd/case.hh>
+
+
+
+
+// macros
+
+namespace xtd
+{
+
+ // FIXME: document case stuff...
+
+ namespace tag
+ {
+
+ struct meta_1ary_fun_operator;
+ struct meta_2ary_fun_operator;
+ struct meta_3ary_fun_operator;
+
+ } // end of namespace xtd::tag
+
+
+ // meta_nary_fun_<1, E>::operator()(const A& a) const
+
+ template <typename E, typename A>
+ struct default_case_ < tag::meta_1ary_fun_operator,
+ mlc::pair_<E, A> >
+ {
+ typedef xtd_res_1(E, A) res;
+
+ static res impl(const abstract::meta_nary_fun_<1, E>* this_,
+ const A& a)
+ {
+ return exact_of(this_)->impl_calc(a);
+ }
+ };
+
+
+ // meta_nary_fun_<2, E>::operator()(const A1& a1, const A2& a2) const
+
+ template <typename E, typename A1, typename A2>
+ struct default_case_ < tag::meta_2ary_fun_operator,
+ mlc::valist_<E, A1, A2> >
+ {
+ typedef xtd_res_2(E, A1, A2) res;
+
+ static res impl(const abstract::meta_nary_fun_<2, E>* this_,
+ const A1& a1, const A2& a2)
+ {
+ return exact_of(this_)->impl_calc(a1, a2);
+ }
+ };
+
+
+ // meta_nary_fun_<3, E>::operator()(const A1& a1, const A2& a2, const
A3& a3) const
+
+ template <typename E, typename A1, typename A2, typename A3>
+ struct default_case_ < tag::meta_3ary_fun_operator,
+ mlc::valist_<E, A1, A2, A3> >
+ {
+ typedef xtd_res_3(E, A1, A2, A3) res;
+
+ static res impl(const abstract::meta_nary_fun_<3, E>* this_,
+ const A1& a1, const A2& a2, const A3& a3)
+ {
+ return exact_of(this_)->impl_calc(a1, a2, a3);
+ }
+ };
+
+
+} // end of namespace xtd
+
+
+namespace xtd
+{
+
+ namespace abstract
+ {
+
+
+ /*! \class xtd::abstract::meta_fun_<E>
+ **
+ ** Abstract base class for meta functions. Parameter E is the
+ ** exact type of the function.
+ */
+
+ template <typename E>
+ class meta_fun_
+
+ : public fun_<E>
+ {
+ protected:
+ meta_fun_()
+ {
+ // FIXME: mlc_is_a does not work with unsigned parameter...
+// mlc::assert_< mlc_is_a(E, xtd::abstract::meta_nary_fun_),
+//
xtd::ERROR::YOU_SHOULD_NOT_DERIVE_DIRECTLY_FROM_xtd_meta_fun_BUT_FROM_xtd_meta_nary_fun_
+// >::check();
+ }
+ };
+
+
+ /*! \class xtd::abstract::meta_nary_fun_<n, E>
+ **
+ ** Abstract base class for meta functions with an explicit number
+ ** of arguments.
+ **
+ ** Parameter n is the number of arguments with n being 1, 2, or 3.
+ **
+ ** Parameter E is the exact type of the function.
+ */
+
+ template <unsigned n, typename E>
+ class meta_nary_fun_;
+
+
+
+ /*! \class xtd::abstract::meta_nary_fun_<0, E>
+ **
+ ** Abstract base class for meta functions taking no argument.
+ ** This class is defined as a specialization.
+ **
+ ** Parameter E is the exact type of the function.
+ */
+
+ template <typename E>
+ class meta_nary_fun_< 0, E >
+
+ : public meta_fun_<E>,
+ public nary_fun_<0>
+ {
+ public:
+
+ xtd_res_0(E)
+ operator()() const
+ {
+ return exact_of(this)->impl_calc();
+ }
+
+ protected:
+ meta_nary_fun_() {}
+ };
+
+
+
+ /*! \class xtd::abstract::meta_nary_fun_<1, E>
+ **
+ ** Abstract base class for meta functions taking one argument.
+ ** This class is defined as a specialization.
+ **
+ ** Parameter E is the exact type of the function.
+ */
+
+ template <typename E>
+ class meta_nary_fun_< 1, E >
+
+ : public meta_fun_<E>,
+ public nary_fun_<1>
+ {
+ public:
+
+ template <typename A>
+ struct case_ : public xtd::case_< xtd::tag::meta_1ary_fun_operator,
+ mlc::pair_<E, A> >::ret
+ {};
+
+ template <typename A>
+ typename case_<A>::res
+ operator()(const A& a) const
+ {
+ return case_<A>::impl(this, a);
+ }
+
+ protected:
+ meta_nary_fun_() {}
+ };
+
+
+
+ /*! \class xtd::abstract::meta_nary_fun_<2, E>
+ **
+ ** Abstract base class for meta functions taking two arguments.
+ ** This class is defined as a specialization.
+ **
+ ** Parameter E is the exact type of the function.
+ */
+
+ template <typename E>
+ class meta_nary_fun_< 2, E >
+
+ : public meta_fun_<E>,
+ public nary_fun_<2>
+ {
+ public:
+
+ template <typename A1, typename A2>
+ struct case_ : public xtd::case_< xtd::tag::meta_2ary_fun_operator,
+ mlc::valist_<E, A1, A2> >::ret
+ {};
+
+ template <typename A1, typename A2>
+ typename case_<A1, A2>::res
+ operator()(const A1& a1, const A2& a2) const
+ {
+ return case_<A1, A2>::impl(this, a1, a2);
+ }
+
+ protected:
+ meta_nary_fun_() {}
+ };
+
+
+ /*! \class xtd::abstract::meta_nary_fun_<3, E>
+ **
+ ** Abstract base class for meta functions taking three arguments.
+ ** This class is defined as a specialization.
+ **
+ ** Parameter E is the exact type of the function.
+ */
+
+ template <typename E>
+ class meta_nary_fun_< 3, E >
+
+ : public meta_fun_<E>,
+ public nary_fun_<3>
+ {
+ public:
+
+ template <typename A1, typename A2, typename A3>
+ struct case_ : public xtd::case_< xtd::tag::meta_3ary_fun_operator,
+ mlc::valist_<E, A1, A2, A3> >::ret
+ {};
+
+ template <typename A1, typename A2, typename A3>
+ typename case_<A1, A2, A3>::res
+ operator()(const A1& a1, const A2& a2, const A3& a3) const
+ {
+ return case_<A1, A2, A3>::impl(this, a1, a2, a3);
+ }
+
+ protected:
+ meta_nary_fun_() {}
+ };
+
+
+ } // end of namespace xtd::abstract
+
+} // end of namespace xtd
+
+
+
+#endif // ! EXTENDED_ABSTRACT_META_FUN_HH
Index: xtd/mfun.hh
--- xtd/mfun.hh (revision 0)
+++ xtd/mfun.hh (revision 0)
@@ -0,0 +1,195 @@
+// Copyright (C) 2002, 2005, 2006 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
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef EXTENDED_MFUN_HH
+# define EXTENDED_MFUN_HH
+
+# include <mlc/assert.hh>
+# include <mlc/logic.hh>
+# include <mlc/is_a.hh>
+
+# include <xtd/abstract/plain_fun.hh>
+# include <xtd/abstract/meta_fun.hh>
+
+
+
+// FIXME: in this file replace impl_calc by impl_op
+
+
+namespace xtd
+{
+
+
+ namespace ERROR
+ {
+
+ struct AN_xtd_m1fun_SHOULD_TAKE_AS_PARAMETER_AN_xtd_plain_nary_fun_WITH_n_BEING_1;
+ struct AN_xtd_m2fun_SHOULD_TAKE_AS_PARAMETER_AN_xtd_plain_nary_fun_WITH_n_BEING_2;
+ struct AN_xtd_m3fun_SHOULD_TAKE_AS_PARAMETER_AN_xtd_plain_nary_fun_WITH_n_BEING_3;
+
+ } // end of namespace xtd::ERROR
+
+
+
+
+ // equipment for xtd::m1fun_<F>
+
+ template <template <typename> class F>
+ struct m1fun_;
+
+ template <template <typename> class F, typename A>
+ struct res_< m1fun_<F>, A >
+
+ : private mlc::assert_< mlc::and_< mlc_is_a(F<A>, abstract::plain_fun_),
+ mlc_is_a(F<A>, abstract::nary_fun_<1>) >,
+
xtd::ERROR::AN_xtd_m1fun_SHOULD_TAKE_AS_PARAMETER_AN_xtd_plain_nary_fun_WITH_n_BEING_1
>
+
+ {
+ typedef xtd_res(F<A>) ret;
+ };
+
+
+ /*! \class xtd::m1fun_<F>
+ **
+ ** FIXME: doc
+ */
+
+ template <template <typename> class F>
+ struct m1fun_ : public abstract::meta_nary_fun_< 1, m1fun_<F> >
+ {
+ template <typename A>
+ xtd_res(F<A>) impl_calc(const 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);
+ }
+ };
+
+
+
+
+
+ // equipment for xtd::m2fun_<F>
+
+ template <template <typename, typename> class F>
+ struct m2fun_;
+
+
+ template <template <typename, typename> class F,
+ typename A1, typename A2>
+
+ struct res_< m2fun_<F>, A1, A2 >
+
+ : private mlc::assert_< mlc::and_< mlc_is_a(mlc_comma_1(F<A1,A2>),
abstract::plain_fun_),
+ mlc_is_a(mlc_comma_1(F<A1,A2>), abstract::nary_fun_<2>) >,
+
xtd::ERROR::AN_xtd_m2fun_SHOULD_TAKE_AS_PARAMETER_AN_xtd_plain_nary_fun_WITH_n_BEING_2
>
+ {
+ typedef F<A1,A2> F_;
+ typedef xtd_res(F_) ret;
+ };
+
+
+ /*! \class xtd::m2fun_<F>
+ **
+ ** FIXME: doc
+ */
+
+ template <template <typename, typename> class F>
+ struct m2fun_ : public abstract::meta_nary_fun_< 2, m2fun_<F> >
+ {
+ template <typename A1, typename A2>
+ xtd_res(mlc_comma_1(F<A1,A2>)) impl_calc(const A1& a1, const A2& a2)
const
+ // ---------
+ {
+ typedef F<A1,A2> F_;
+ mlc::assert_< mlc::and_< mlc_is_a(F_, abstract::plain_fun_),
+ mlc_is_a(F_, abstract::nary_fun_<2>) >,
+
xtd::ERROR::AN_xtd_m2fun_SHOULD_TAKE_AS_PARAMETER_AN_xtd_plain_nary_fun_WITH_n_BEING_2
>::check();
+ static const F_ f_;
+ return f_(a1, a2);
+ }
+ };
+
+
+
+
+
+
+ // equipment for xtd::m3fun_<F>
+
+ template <template <typename, typename, typename> class F>
+ struct m3fun_;
+
+
+ template <template <typename, typename, typename> class F,
+ typename A1, typename A2, typename A3>
+
+ struct res_< m3fun_<F>, A1, A2, A3 >
+
+ : private mlc::assert_< mlc::and_< mlc_is_a(mlc_comma_2(F<A1,A2,A3>),
abstract::plain_fun_),
+ mlc_is_a(mlc_comma_2(F<A1,A2,A3>), abstract::nary_fun_<3>) >,
+
xtd::ERROR::AN_xtd_m3fun_SHOULD_TAKE_AS_PARAMETER_AN_xtd_plain_nary_fun_WITH_n_BEING_3
>
+ {
+ typedef F<A1,A2,A3> F_;
+ typedef xtd_res(F_) ret;
+ };
+
+
+ /*! \class xtd::m3fun_<F>
+ **
+ ** FIXME: doc
+ */
+
+ template <template <typename, typename, typename> class F>
+ struct m3fun_ : public abstract::meta_nary_fun_< 3, m3fun_<F> >
+ {
+ template <typename A1, typename A2, typename A3>
+ xtd_res(mlc_comma_2(F<A1,A2,A3>)) impl_calc(const A1& a1, const A2& a2,
const A3& a3) const
+ // ---------
+ {
+ typedef F<A1,A2,A3> F_;
+ mlc::assert_< mlc::and_< mlc_is_a(F_, abstract::plain_fun_),
+ mlc_is_a(F_, abstract::nary_fun_<3>) >,
+
xtd::ERROR::AN_xtd_m3fun_SHOULD_TAKE_AS_PARAMETER_AN_xtd_plain_nary_fun_WITH_n_BEING_3
>::check();
+ static const F_ f_;
+ return f_(a1, a2, a3);
+ }
+ };
+
+
+
+} // end of namespace xtd
+
+
+
+#endif // ! EXTENDED_MFUN_HH
Index: xtd/traits.hh
--- xtd/traits.hh (revision 0)
+++ xtd/traits.hh (revision 0)
@@ -0,0 +1,55 @@
+// Copyright (C) 2002, 2005, 2006 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
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef EXTENDED_TRAITS_HH
+# define EXTENDED_TRAITS_HH
+
+# include <mlc/flags.hh>
+
+
+# define xtd_plus(L, R) typename xtd::plus_trait_< L, R >::ret
+# define xtd_mult(L, R) typename xtd::mult_trait_< L, R >::ret
+
+
+namespace xtd
+{
+
+ template <typename L, typename R>
+ struct plus_trait_ : public mlc::undefined
+ {
+ };
+
+ template <typename L, typename R>
+ struct mult_trait_ : public mlc::undefined
+ {
+ };
+
+} // end of namespace xtd
+
+
+
+#endif // ! EXTENDED_TRAITS_HH
Index: xtd/builtin/traits.hh
--- xtd/builtin/traits.hh (revision 0)
+++ xtd/builtin/traits.hh (revision 0)
@@ -0,0 +1,90 @@
+// Copyright (C) 2002, 2005, 2006 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
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef EXTENDED_BUILTIN_TRAITS_HH
+# define EXTENDED_BUILTIN_TRAITS_HH
+
+# include <xtd/traits.hh>
+
+
+namespace xtd
+{
+
+ // FIXME: this is dummy and incomplete code!
+
+
+ // plus
+
+ template <typename T>
+ struct plus_trait_ < T, T >
+ {
+ typedef T ret;
+ };
+
+ template <> struct plus_trait_ < float, int > { typedef float ret; };
+ template <> struct plus_trait_ < int, float > { typedef float ret; };
+ template <> struct plus_trait_ < double, int > { typedef double ret; };
+ template <> struct plus_trait_ < int, double > { typedef double ret; };
+ template <> struct plus_trait_ < double, float > { typedef double ret; };
+ template <> struct plus_trait_ < float, double > { typedef double ret; };
+
+ template <> struct plus_trait_ < long double, int > { typedef long double
ret; };
+ template <> struct plus_trait_ < int, long double > { typedef long double
ret; };
+ template <> struct plus_trait_ < long double, float > { typedef long double
ret; };
+ template <> struct plus_trait_ < float, long double > { typedef long double
ret; };
+ template <> struct plus_trait_ < long double, double > { typedef long
double ret; };
+ template <> struct plus_trait_ < double, long double > { typedef long
double ret; };
+
+
+ // mult
+
+ template <typename T>
+ struct mult_trait_ < T, T >
+ {
+ typedef T ret;
+ };
+
+ template <> struct mult_trait_ < float, int > { typedef float ret; };
+ template <> struct mult_trait_ < int, float > { typedef float ret; };
+ template <> struct mult_trait_ < double, int > { typedef double ret; };
+ template <> struct mult_trait_ < int, double > { typedef double ret; };
+ template <> struct mult_trait_ < double, float > { typedef double ret; };
+ template <> struct mult_trait_ < float, double > { typedef double ret; };
+
+ template <> struct mult_trait_ < long double, int > { typedef long double
ret; };
+ template <> struct mult_trait_ < int, long double > { typedef long double
ret; };
+ template <> struct mult_trait_ < long double, float > { typedef long double
ret; };
+ template <> struct mult_trait_ < float, long double > { typedef long double
ret; };
+ template <> struct mult_trait_ < long double, double > { typedef long
double ret; };
+ template <> struct mult_trait_ < double, long double > { typedef long
double ret; };
+
+
+} // end of namespace xtd
+
+
+
+#endif // ! EXTENDED_BUILTIN_TRAITS_HH
Index: xtd/arg.hh
--- xtd/arg.hh (revision 0)
+++ xtd/arg.hh (revision 0)
@@ -0,0 +1,152 @@
+// Copyright (C) 2002, 2005, 2006 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
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef EXTENDED_ARG_HH
+# define EXTENDED_ARG_HH
+
+# include <mlc/assert.hh>
+# include <mlc/is_a.hh>
+
+# include <xtd/args.hh>
+# include <xtd/mexpr.hh>
+
+
+
+
+# define xtd_nargs(F) xtd::nargs_<F>::ret
+
+
+
+namespace xtd
+{
+
+
+
+ namespace internal
+ {
+
+ // FIXME: doc
+
+ template <unsigned i> struct impl_arg_;
+
+ template <>
+ struct impl_arg_<1>
+ {
+ template <typename Args>
+ typename Args::arg1_type impl_eval(const Args& args) const
+ {
+ mlc::assert_< mlc_is_a(Args, xtd::abstract::args) >::check();
+ return args.arg1;
+ }
+ };
+
+ template <>
+ struct impl_arg_<2>
+ {
+ template <typename Args>
+ typename Args::arg2_type impl_eval(const Args& args) const
+ {
+ mlc::assert_< mlc_is_a(Args, xtd::abstract::args) >::check();
+ return args.arg2;
+ }
+ };
+
+ template <>
+ struct impl_arg_<3>
+ {
+ template <typename Args>
+ typename Args::arg3_type impl_eval(const Args& args) const
+ {
+ mlc::assert_< mlc_is_a(Args, xtd::abstract::args) >::check();
+ return args.arg3;
+ }
+ };
+
+ } // end of namespace xtd::internal
+
+
+
+
+ /*! \class xtd::arg_<i>
+ **
+ ** FIXME: placeholder for the ith argument
+ */
+
+
+ template <unsigned i> struct arg_;
+
+ template <unsigned i>
+ struct nargs_< arg_<i> >
+ {
+ static const unsigned ret = i;
+ };
+
+
+ template <typename Args>
+ struct expr_res_< arg_<1>, Args >
+ {
+ typedef typename Args::arg1_type ret;
+ };
+
+ template <typename Args>
+ struct expr_res_< arg_<2>, Args >
+ {
+ typedef typename Args::arg2_type ret;
+ };
+
+ template <typename Args>
+ struct expr_res_< arg_<3>, Args >
+ {
+ typedef typename Args::arg3_type ret;
+ };
+
+
+ template <unsigned i>
+ struct arg_
+
+ : public abstract::nary_fun_expr_< i, arg_<i> >,
+
+ public internal::impl_arg_<i>
+
+ // FIXME: add something like ": private mlc::assert_< (i > 1 and i <= 3)
>"
+ {
+ typedef internal::impl_arg_<i> super;
+ using super::impl_eval;
+ };
+
+
+ // placeholders:
+
+ const arg_<1> _1 = arg_<1>();
+ const arg_<2> _2 = arg_<2>();
+ const arg_<3> _3 = arg_<3>();
+
+
+} // end of namespace xtd
+
+
+#endif // ! EXTENDED_ARG_HH
Index: xtd/case.hh
--- xtd/case.hh (revision 0)
+++ xtd/case.hh (revision 0)
@@ -0,0 +1,37 @@
+// Copyright (C) 2002, 2005, 2006 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
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef EXTENDED_CASE_HH
+# define EXTENDED_CASE_HH
+
+# include <mlc/case.hh>
+
+
+mlc_case_equipment_for_namespace(xtd);
+
+
+#endif // ! EXTENDED_CASE_HH
Index: tests/id.cc
--- tests/id.cc (revision 0)
+++ tests/id.cc (revision 0)
@@ -0,0 +1,43 @@
+#include <iostream>
+
+
+#include <xtd/math/id.hh>
+
+
+
+// namespace xtd
+// {
+// struct xfail;
+
+// template <>
+// struct fun_traits_< xfail >
+// {
+// typedef int res_type;
+// };
+// struct xfail : public xtd::abstract::plain_fun_< xfail >
+// {
+// };
+
+// }
+
+
+
+int main()
+{
+
+// {
+// xtd::xfail test;
+// }
+
+
+ {
+ xtd::plain_id_<int> id_int;
+ std::cout << id_int(51) << std::endl;
+
+ xtd::plain_id_<float> id_float;
+ std::cout << id_float(5.1f) << std::endl;
+
+ }
+
+
+}
Index: tests/cos.cc
--- tests/cos.cc (revision 0)
+++ tests/cos.cc (revision 0)
@@ -0,0 +1,52 @@
+#include <iostream>
+
+#include <xtd/math.hh>
+
+
+int main()
+{
+
+// {
+// using xtd::cos;
+// std::cout << cos(5.1f) << std::endl;
+// }
+
+// {
+// using xtd::cos;
+// using xtd::sin;
+// using xtd::_1;
+// using xtd::_2;
+
+// std::cout << cos(_1)(5.1f) << std::endl;
+// std::cout << (cos(_1) + sin(_2))(5.f, 1.f) << std::endl;
+// std::cout << (cos(_1) + sin(_2)).nargs() << std::endl;
+// }
+
+// {
+// using xtd::cos;
+// using xtd::_1;
+// using xtd::_2;
+// std::cout << (cos(_1)(_2)).nargs() << std::endl; // gives: 2
+// }
+
+ {
+ using xtd::cos;
+ using xtd::sin;
+ using xtd::_1;
+ using xtd::_2;
+
+// std::cout << (cos(_1) * cos(_1) + sin(_2) * sin(_2))(5.f, 5.f) <<
std::endl;
+
+// std::cout << (_1)(_1)(51.f) << std::endl;
+// std::cout << (_1 + _1)(51.f) << std::endl;
+// std::cout << (_1 + _2)(5.f, 1.f) << std::endl;
+
+// (cos(_1) + sin(_1))(_1);
+// std::cout << (cos(_1) * cos(_1) + sin(_1) * sin(_1))(_1)(51.f) <<
std::endl;
+
+ std::cout << (_1 * _1 + _2 * _2)(cos(_1), sin(_1))(51.f) << std::endl;
+
+// std::cout << ((cos(_1) + sin(_2))(_1, _1)).nargs() << std::endl;
+ }
+
+}
Index: tests/Makefile.am
--- tests/Makefile.am (revision 433)
+++ tests/Makefile.am (working copy)
@@ -1,8 +1,19 @@
## Process this file through Automake to create Makefile.in -*- Makefile -*-
-AM_CPPFLAGS = -I$(top_srcdir)/extended -I$(top_srcdir)/metalic
+AM_CPPFLAGS = -I$(top_srcdir)/extended
# FIXME: Add
#
# AM_CXXFLAGS = $(CXXFLAGS_STRICT) $(CXXFLAGS_OPTIMIZE) -ggdb
#
# when oln.m4 is available in the distribution.
+
+check_PROGRAMS = \
+ id \
+ cast \
+ cos
+
+id_SOURCES = id.cc
+cast_SOURCES = cast.cc
+cos_SOURCES = cos.cc
+
+TESTS = $(check_PROGRAMS)
Index: tests/cast.cc
--- tests/cast.cc (revision 0)
+++ tests/cast.cc (revision 0)
@@ -0,0 +1,37 @@
+#include <iostream>
+#include <xtd/cast.hh>
+#include <xtd/arg.hh>
+#include <xtd/math/trigo.hh>
+
+
+int main()
+{
+
+ {
+ xtd::plain_cast_<int, float> fun;
+ std::cout << fun(3.14) << std::endl;
+ }
+
+ {
+ xtd::meta_cast_<int> fun;
+ std::cout << fun(3.14) << std::endl;
+ }
+
+ {
+ using xtd::cast_;
+ using xtd::cos;
+ using xtd::_1;
+ std::cout << (cast_<int>(cos(_1)))(3.14) << std::endl;
+ std::cout << cos(cast_<float>(_1))(3) << std::endl;
+ }
+
+// {
+// xtd::cos_<int> c;
+// }
+
+// {
+// using xtd::cos;
+// cos(1);
+// }
+
+}