https://svn.lrde.epita.fr/svn/oln/trunk/extended
Index: ChangeLog
from Thierry Geraud <theo(a)lrde.epita.fr>
Add a lot of material for operators (arith, logical, cmp).
* xtd/cast.hh: Fix doc.
* xtd/cfun.hh: New file dedicated to C functions.
* xtd/traits.hh: Add a lot of material.
* xtd/math/arith.hh: Update.
* xtd/ops_expr.hh: Update.
* xtd/builtin/traits.hh: Update.
* xtd/literal.hh: Add static assertions.
* xtd/abstract/fun_expr.hh (nargs): Move to...
* xtd/abstract/nary_fun.hh: ...this file.
(n): New method.
* tests/cfun.cc: New file.
* tests/Makefile.am: Update.
tests/Makefile.am | 2
tests/cfun.cc | 35 ++++
xtd/abstract/fun_expr.hh | 5
xtd/abstract/nary_fun.hh | 8
xtd/builtin/traits.hh | 114 ++++++++-----
xtd/cast.hh | 2
xtd/cfun.hh | 398 +++++++++++++++++++++++++++++++++++++++++++++++
xtd/literal.hh | 14 +
xtd/math/arith.hh | 130 +++++++++------
xtd/ops_expr.hh | 107 ++++++++----
xtd/traits.hh | 115 +++++++++++++
11 files changed, 803 insertions(+), 127 deletions(-)
Index: xtd/cast.hh
--- xtd/cast.hh (revision 442)
+++ xtd/cast.hh (working copy)
@@ -96,7 +96,7 @@
**
** This function mimics the behavior of the method:
**
- ** xtd::meta_nary_fun_<1, E>::operator(const A& a)
+ ** xtd::open_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>.
Index: xtd/cfun.hh
--- xtd/cfun.hh (revision 0)
+++ xtd/cfun.hh (revision 0)
@@ -0,0 +1,398 @@
+// 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_CFUN_HH
+# define EXTENDED_CFUN_HH
+
+# include <xtd/abstract/plain_nary_fun.hh>
+# include <xtd/abstract/meta_nary_fun.hh>
+
+
+
+
+namespace xtd
+{
+
+
+ template <typename F> struct plain_cfun_; // fwd decl
+
+
+ template <typename R>
+ struct fun_traits_< R(*)() >
+ {
+ typedef R res_type;
+ };
+
+ template <typename R, typename A>
+ struct fun_traits_< R(*)(A) >
+ {
+ typedef R res_type;
+ typedef A arg_type;
+ };
+
+ template <typename R, typename A1, typename A2>
+ struct fun_traits_< R(*)(A1, A2) >
+ {
+ typedef R res_type;
+ typedef A1 arg1_type;
+ typedef A2 arg2_type;
+ };
+
+ template <typename R, typename A1, typename A2, typename A3>
+ struct fun_traits_< R(*)(A1, A2, A3) >
+ {
+ typedef R res_type;
+ typedef A1 arg1_type;
+ typedef A2 arg2_type;
+ typedef A3 arg3_type;
+ };
+
+
+ template <typename F>
+ struct fun_traits_< plain_cfun_<F> > : fun_traits_<F>
+ {
+ };
+
+
+
+ /*! \class xtd::plain_cfun_< R(*)() >
+ **
+ ** FIXME: doc
+ */
+
+ template <typename R>
+ struct plain_cfun_ < R(*)() >
+
+ : public abstract::plain_nary_fun_< 0, plain_cfun_<R(*)()> >
+ {
+ typedef R(*cfun_type)();
+ const cfun_type f;
+
+ plain_cfun_(const cfun_type& f)
+ : f(f)
+ {}
+
+ R impl_op() const
+ {
+ return this->f();
+ }
+ };
+
+
+ template <typename R>
+ plain_cfun_<R(*)()> mk_plain_fun( R(*f)() )
+ {
+ plain_cfun_<R(*)()> tmp(f);
+ return tmp;
+ }
+
+
+
+ /*! \class xtd::plain_cfun_< R(*)(A) >
+ **
+ ** FIXME: doc
+ */
+
+ template <typename R, typename A>
+ struct plain_cfun_ < R(*)(A) >
+
+ : public abstract::plain_nary_fun_< 1, plain_cfun_<R(*)(A)> >
+ {
+ typedef R(*cfun_type)(A);
+ const cfun_type f;
+
+ plain_cfun_(const cfun_type& f)
+ : f(f)
+ {}
+
+ R impl_op(const A& a) const
+ {
+ return this->f(a);
+ }
+ };
+
+
+ template <typename R, typename A>
+ plain_cfun_<R(*)(A)> mk_plain_fun( R(*f)(A) )
+ {
+ plain_cfun_<R(*)(A)> tmp(f);
+ return tmp;
+ }
+
+
+
+
+ /*! \class xtd::plain_cfun_< R(*)(A1,A2) >
+ **
+ ** FIXME: doc
+ */
+
+ template <typename R, typename A1, typename A2>
+ struct plain_cfun_ < R(*)(A1,A2) >
+
+ : public abstract::plain_nary_fun_< 2, plain_cfun_<R(*)(A1,A2)> >
+ {
+ typedef R(*cfun_type)(A1,A2);
+ const cfun_type f;
+
+ plain_cfun_(const cfun_type& f)
+ : f(f)
+ {}
+
+ R impl_op(const A1& a1, const A2& a2) const
+ {
+ return this->f(a1, a2);
+ }
+ };
+
+
+ template <typename R, typename A1, typename A2>
+ plain_cfun_<R(*)(A1,A2)> mk_plain_fun( R(*f)(A1,A2) )
+ {
+ plain_cfun_<R(*)(A1,A2)> tmp(f);
+ return tmp;
+ }
+
+
+
+ /*! \class xtd::plain_cfun_< R(*)(A1,A2,A3) >
+ **
+ ** FIXME: doc
+ */
+
+ template <typename R, typename A1, typename A2, typename A3>
+ struct plain_cfun_ < R(*)(A1,A2,A3) >
+
+ : public abstract::plain_nary_fun_< 3, plain_cfun_<R(*)(A1,A2,A3)> >
+ {
+ typedef R(*cfun_type)(A1,A2,A3);
+ const cfun_type f;
+
+ plain_cfun_(const cfun_type& f)
+ : f(f)
+ {}
+
+ R impl_op(const A1& a1, const A2& a2, const A3& a3) const
+ {
+ return this->f(a1, a2, a3);
+ }
+ };
+
+
+ template <typename R, typename A1, typename A2, typename A3>
+ plain_cfun_<R(*)(A1,A2,A3)> mk_plain_fun( R(*f)(A1,A2,A3) )
+ {
+ plain_cfun_<R(*)(A1,A2,A3)> tmp(f);
+ return tmp;
+ }
+
+
+
+
+
+
+
+
+ /*! \class xtd::meta_cfun_<F>
+ **
+ ** FIXME: doc
+ */
+
+ template <typename F>
+ struct meta_cfun_;
+
+
+
+ /*! \class xtd::meta_cfun_< R_(*)() >
+ **
+ ** FIXME: doc
+ */
+
+ template <typename R_>
+ struct res_< meta_cfun_<R_(*)()> >
+ {
+ typedef R_ ret;
+ };
+
+ template <typename R_>
+ struct meta_cfun_ < R_(*)() >
+
+ : public abstract::meta_nary_fun_< 0, meta_cfun_<R_(*)()> >
+ {
+ typedef R_(*cfun_type)();
+ const cfun_type f;
+
+ meta_cfun_(const cfun_type& f)
+ : f(f)
+ {}
+
+ R_ impl_calc() const
+ {
+ return this->f;
+ }
+ };
+
+ template <typename R>
+ meta_cfun_<R(*)()> mk_fun( R(*f)() )
+ {
+ meta_cfun_<R(*)()> tmp(f);
+ return tmp;
+ }
+
+
+
+ /*! \class xtd::meta_cfun_< R_(*)(A_) >
+ **
+ ** FIXME: doc
+ */
+
+ template <typename R_, typename A_,
+ typename A>
+ struct res_< meta_cfun_<R_(*)(A_)>,
+ A >
+ {
+ typedef R_ ret;
+ };
+
+ template <typename R_, typename A_>
+ struct meta_cfun_ < R_(*)(A_) >
+
+ : public abstract::meta_nary_fun_< 1, meta_cfun_<R_(*)(A_)> >
+ {
+ typedef R_(*cfun_type)(A_);
+ const cfun_type f;
+
+ meta_cfun_(const cfun_type& f)
+ : f(f)
+ {}
+
+ template <typename A>
+ R_ impl_calc(const A& a) const
+ {
+ // FIXME: check that conversion "A -> A_" exists
+ return this->f(a);
+ }
+ };
+
+ template <typename R, typename A>
+ meta_cfun_<R(*)(A)> mk_fun( R(*f)(A) )
+ {
+ meta_cfun_<R(*)(A)> tmp(f);
+ return tmp;
+ }
+
+
+
+ /*! \class xtd::meta_cfun_< R_(*)(A1_,A2_) >
+ **
+ ** FIXME: doc
+ */
+
+ template <typename R_, typename A1_, typename A2_,
+ typename A1, typename A2>
+ struct res_< meta_cfun_<R_(*)(A1_,A2_)>,
+ A1, A2 >
+ {
+ typedef R_ ret;
+ };
+
+ template <typename R_, typename A1_, typename A2_>
+ struct meta_cfun_ < R_(*)(A1_,A2_) >
+
+ : public abstract::meta_nary_fun_< 2, meta_cfun_<R_(*)(A1_,A2_)> >
+ {
+ typedef R_(*cfun_type)(A1_,A2_);
+ const cfun_type f;
+
+ meta_cfun_(const cfun_type& f)
+ : f(f)
+ {}
+
+ template <typename A1, typename A2>
+ R_ impl_calc(const A1& a1, const A2& a2) const
+ {
+ // FIXME: check that conversions "Ai -> Ai_" exist
+ return this->f(a1, a2);
+ }
+ };
+
+ template <typename R, typename A1, typename A2>
+ meta_cfun_<R(*)(A1,A2)> mk_fun( R(*f)(A1,A2) )
+ {
+ meta_cfun_<R(*)(A1,A2)> tmp(f);
+ return tmp;
+ }
+
+
+
+ /*! \class xtd::meta_cfun_< R_(*)(A1_,A2_,A3_) >
+ **
+ ** FIXME: doc
+ */
+
+ template <typename R_, typename A1_, typename A2_, typename A3_,
+ typename A1, typename A2, typename A3>
+ struct res_< meta_cfun_<R_(*)(A1_,A2_,A3_)>,
+ A1, A2, A3 >
+ {
+ typedef R_ ret;
+ };
+
+ template <typename R_, typename A1_, typename A2_, typename A3_>
+ struct meta_cfun_ < R_(*)(A1_,A2_,A3_) >
+
+ : public abstract::meta_nary_fun_< 3, meta_cfun_<R_(*)(A1_,A2_,A3_)> >
+ {
+ typedef R_(*cfun_type)(A1_,A2_,A3_);
+ const cfun_type f;
+
+ meta_cfun_(const cfun_type& f)
+ : f(f)
+ {}
+
+ template <typename A1, typename A2, typename A3>
+ R_ impl_calc(const A1& a1, const A2& a2, const A3& a3) const
+ {
+ // FIXME: check that conversions "Ai -> Ai_" exist
+ return this->f(a1, a2, a3);
+ }
+ };
+
+ template <typename R, typename A1, typename A2, typename A3>
+ meta_cfun_<R(*)(A1,A2,A3)> mk_fun( R(*f)(A1,A2,A3) )
+ {
+ meta_cfun_<R(*)(A1,A2,A3)> tmp(f);
+ return tmp;
+ }
+
+
+
+} // end of namespace xtd
+
+
+
+#endif // ! EXTENDED_CFUN_HH
Index: xtd/math/arith.hh
--- xtd/math/arith.hh (revision 442)
+++ xtd/math/arith.hh (working copy)
@@ -33,68 +33,104 @@
# include <xtd/mfun.hh>
+// FIXME: doc
-namespace xtd
-{
+# define xtd_internal_decl_plain_unary_fun_op(OperatorName, OperatorSymbol) \
+ \
+ template <typename T> \
+ struct plain_##OperatorName##_; \
+ \
+ template <typename T> \
+ struct fun_traits_< plain_##OperatorName##_<T> > \
+ { \
+ typedef T arg_type; \
+ typedef xtd_##OperatorName(T) res_type; \
+ }; \
+ \
+ template <typename T> \
+ struct plain_##OperatorName##_ \
+ \
+ : public abstract::plain_nary_fun_< 1, plain_##OperatorName##_<T> > \
+ { \
+ typedef plain_##OperatorName##_<T> self; \
+ xtd_res(self) impl_op(const T& arg) const \
+ { \
+ return OperatorSymbol arg; \
+ } \
+ }; \
+ \
+ typedef m1fun_<plain_##OperatorName##_> OperatorName##_type; \
+ const OperatorName##_type OperatorName; \
+ \
+ struct e_n_d__w_i_t_h__s_e_m_i_c_o_l_o_n
- /*! \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;
- };
+# define xtd_internal_decl_plain_binary_fun_op(OperatorName, OperatorSymbol) \
+ \
+ template <typename T1, typename T2> \
+ struct plain_##OperatorName##_; \
+ \
+ template <typename T1, typename T2> \
+ struct fun_traits_< plain_##OperatorName##_<T1, T2> > \
+ { \
+ typedef T1 arg1_type; \
+ typedef T2 arg2_type; \
+ typedef xtd_##OperatorName(T1, T2) res_type; \
+ }; \
+ \
+ template <typename T1, typename T2> \
+ struct plain_##OperatorName##_ \
+ \
+ : public abstract::plain_nary_fun_< 2, plain_##OperatorName##_<T1, T2>
> \
+ { \
+ typedef plain_##OperatorName##_<T1, T2> self; \
+ xtd_res(self) impl_op(const T1& arg1, const T2& arg2) const \
+ { \
+ return arg1 OperatorSymbol arg2; \
+ } \
+ }; \
+ \
+ typedef m2fun_<plain_##OperatorName##_> OperatorName##_type; \
+ const OperatorName##_type OperatorName; \
+ \
+ struct e_n_d__w_i_t_h__s_e_m_i_c_o_l_o_n
- 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
+
+
+
+namespace xtd
{
- return arg1 + arg2;
- }
- };
- typedef m2fun_<plain_plus_> plus_type;
- const plus_type plus;
+ // logic
+ xtd_internal_decl_plain_binary_fun_op( land, and );
+ xtd_internal_decl_plain_binary_fun_op( lor, or );
+ xtd_internal_decl_plain_binary_fun_op( lxor, xor );
+ xtd_internal_decl_plain_unary_fun_op( lnot, not );
- /*! \class xtd::plain_mult_<T>
- **
- ** FIXME: doc
- */
- template <typename T1, typename T2> struct plain_mult_; // fwd decl
+ // cmp
- 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;
- };
+ xtd_internal_decl_plain_binary_fun_op( eq, == );
+ xtd_internal_decl_plain_binary_fun_op( neq, != );
+ xtd_internal_decl_plain_binary_fun_op( less, < );
+ xtd_internal_decl_plain_binary_fun_op( leq, <= );
+ xtd_internal_decl_plain_binary_fun_op( greater, > );
+ xtd_internal_decl_plain_binary_fun_op( geq, >= );
- 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;
+ // arith
+
+ xtd_internal_decl_plain_binary_fun_op( plus, + );
+ xtd_internal_decl_plain_binary_fun_op( minus, - );
+ xtd_internal_decl_plain_binary_fun_op( mult, * );
+ xtd_internal_decl_plain_binary_fun_op( div, / );
+ xtd_internal_decl_plain_binary_fun_op( mod, % );
+
+ xtd_internal_decl_plain_unary_fun_op( uminus, - );
} // end of namespace xtd
Index: xtd/literal.hh
--- xtd/literal.hh (revision 442)
+++ xtd/literal.hh (working copy)
@@ -59,7 +59,12 @@
};
template <typename T>
- struct plain_literal_ : public abstract::plain_nary_fun_< 0, plain_literal_<T>
>
+ struct plain_literal_
+
+ : private mlc::assert_< mlc_is_not_a(T, abstract::fun_),
+ xtd::ERROR::FIXME >,
+
+ public abstract::plain_nary_fun_< 0, plain_literal_<T> >
{
const T value;
@@ -92,7 +97,12 @@
*/
template <typename T>
- struct meta_literal_ : public abstract::meta_nary_fun_< 0, meta_literal_<T>
>
+ struct meta_literal_
+
+ : private mlc::assert_< mlc_is_not_a(T, abstract::fun_),
+ xtd::ERROR::FIXME >,
+
+ public abstract::meta_nary_fun_< 0, meta_literal_<T> >
{
const T value;
Index: xtd/ops_expr.hh
--- xtd/ops_expr.hh (revision 442)
+++ xtd/ops_expr.hh (working copy)
@@ -33,48 +33,93 @@
# include <xtd/math/arith.hh>
-namespace xtd
-{
-// namespace abstract
+
+// FIXME: doc
+
+
+
+# define xtd_internal_decl_unary_operator(OperatorName, OperatorSymbol) \
+ \
+ template <typename Expr> \
+ xtd::m1expr_<xtd::OperatorName##_type, Expr> \
+ operator OperatorSymbol (const xtd::abstract::fun_expr_<Expr>& expr) \
+ { \
+ xtd::m1expr_<xtd::OperatorName##_type, Expr> tmp(expr); \
+ return tmp; \
+ } \
+ \
+ struct e_n_d__w_i_t_h__s_e_m_i_c_o_l_o_n
+
+
+// FIXME: add something like:
+
+// template <typename Expr>
+// struct OperatorName##_trait_ < Expr >
// {
+// typedef xtd::m1expr_<xtd::OperatorName##_type, Expr> ret;
+// };
- // +
- 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)
+
+# define xtd_internal_decl_binary_operator(OperatorName, OperatorSymbol) \
+ \
+ template <typename Lexpr, typename Rexpr> \
+ xtd::m2expr_<xtd::OperatorName##_type, Lexpr, Rexpr> \
+ operator OperatorSymbol (const xtd::abstract::fun_expr_<Lexpr>& lexpr, \
+ const xtd::abstract::fun_expr_<Rexpr>& rexpr) \
+ { \
+ xtd::m2expr_<xtd::OperatorName##_type, Lexpr, Rexpr> tmp(lexpr, rexpr); \
+ return tmp; \
+ } \
+ \
+ struct e_n_d__w_i_t_h__s_e_m_i_c_o_l_o_n
+
+
+// FIXME: add something like:
+
+// template <typename Lexpr, typename Rexpr>
+// struct OperatorName##_trait_ < Lexpr, Rexpr >
// {
-// xtd::m2expr<xtd::plus_type, L, R> tmp;
-// return tmp;
-// }
+// typedef xtd::m2expr_<xtd::OperatorName##_type, Lexpr, Rexpr> ret;
+// };
+
- // *
- 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)
+
+namespace xtd
{
- xtd::m2expr_<xtd::mult_type, L, R> tmp(lexpr, rexpr);
- return tmp;
- }
-// } // end of namespace xtd::abstract
+ // logic
+
+ xtd_internal_decl_binary_operator( land, and );
+ xtd_internal_decl_binary_operator( lor, or );
+ xtd_internal_decl_binary_operator( lxor, xor );
+
+ xtd_internal_decl_unary_operator( lnot, not );
+
+
+ // cmp
+
+ xtd_internal_decl_binary_operator( eq, == );
+ xtd_internal_decl_binary_operator( neq, != );
+ xtd_internal_decl_binary_operator( less, < );
+ xtd_internal_decl_binary_operator( leq, <= );
+ xtd_internal_decl_binary_operator( greater, > );
+ xtd_internal_decl_binary_operator( geq, >= );
+
+
+ // arith
+
+ xtd_internal_decl_binary_operator( plus, + );
+ xtd_internal_decl_binary_operator( minus, - );
+ xtd_internal_decl_binary_operator( mult, * );
+ xtd_internal_decl_binary_operator( div, / );
+ xtd_internal_decl_binary_operator( mod, % );
+
+ xtd_internal_decl_unary_operator( uminus, - );
} // end of namespace xtd
Index: xtd/abstract/nary_fun.hh
--- xtd/abstract/nary_fun.hh (revision 442)
+++ xtd/abstract/nary_fun.hh (working copy)
@@ -37,9 +37,15 @@
// FIXME: doc!
- template <unsigned n>
+ template <unsigned n_>
class nary_fun_
{
+ public:
+
+ enum { nargs = n_ };
+
+ unsigned n() const { return n_; }
+
protected:
nary_fun_()
{}
Index: xtd/abstract/fun_expr.hh
--- xtd/abstract/fun_expr.hh (revision 442)
+++ xtd/abstract/fun_expr.hh (working copy)
@@ -74,11 +74,6 @@
return this->exact().impl_eval(arglist);
}
- unsigned nargs() const
- {
- return xtd_nargs(E);
- }
-
protected:
fun_expr_() {}
};
Index: xtd/traits.hh
--- xtd/traits.hh (revision 442)
+++ xtd/traits.hh (working copy)
@@ -31,23 +31,136 @@
# include <mlc/flags.hh>
+
+// logic
+
+# define xtd_land(L, R) typename xtd::land_trait_<L, R>::ret
+# define xtd_lor(L, R) typename xtd::lor_trait_<L, R>::ret
+# define xtd_lxor(L, R) typename xtd::lxor_trait_<L, R>::ret
+
+# define xtd_lnot(T) typename xtd::lnot_trait_<T>::ret
+
+
+// cmp
+
+# define xtd_eq(L, R) typename xtd::eq_trait_<L, R>::ret
+# define xtd_neq(L, R) typename xtd::neq_trait_<L, R>::ret
+# define xtd_less(L, R) typename xtd::less_trait_<L, R>::ret
+# define xtd_leq(L, R) typename xtd::leq_trait_<L, R>::ret
+# define xtd_greater(L, R) typename xtd::greater_trait_<L, R>::ret
+# define xtd_geq(L, R) typename xtd::geq_trait_<L, R>::ret
+
+
+// arith
+
# define xtd_plus(L, R) typename xtd::plus_trait_< L, R >::ret
+# define xtd_minus(L, R) typename xtd::minus_trait_<L, R>::ret
# define xtd_mult(L, R) typename xtd::mult_trait_< L, R >::ret
+# define xtd_div(L, R) typename xtd::div_trait_<L, R>::ret
+# define xtd_mod(L, R) typename xtd::mod_trait_<L, R>::ret
+
+# define xtd_uminus(T) typename xtd::uminus_trait_<T>::ret
+
+
+
+// FIXME: xtd_plus(L, R) should be xtd::INTERNAL::plus_trait_< L, R >::ret
+// FIXME: which checks that the trait *is* defined
+
namespace xtd
{
+ // logic
+
+ template <typename L, typename R>
+ struct land_trait_ : public mlc::undefined
+ {
+ };
+
+ template <typename L, typename R>
+ struct lor_trait_ : public mlc::undefined
+ {
+ };
+
+ template <typename L, typename R>
+ struct lxor_trait_ : public mlc::undefined
+ {
+ };
+
+ template <typename T>
+ struct lnot_trait_ : public mlc::undefined
+ {
+ };
+
+
+ // cmp
+
+ template <typename L, typename R>
+ struct eq_trait_ : public mlc::undefined
+ {
+ };
+
+ template <typename L, typename R>
+ struct neq_trait_ : public mlc::undefined
+ {
+ };
+
+ template <typename L, typename R>
+ struct less_trait_ : public mlc::undefined
+ {
+ };
+
+ template <typename L, typename R>
+ struct leq_trait_ : public mlc::undefined
+ {
+ };
+
+ template <typename L, typename R>
+ struct greater_trait_ : public mlc::undefined
+ {
+ };
+
+ template <typename L, typename R>
+ struct geq_trait_ : public mlc::undefined
+ {
+ };
+
+
+ // arith
+
template <typename L, typename R>
struct plus_trait_ : public mlc::undefined
{
};
template <typename L, typename R>
- struct mult_trait_ : public mlc::undefined
+ struct minus_trait_ : public mlc::undefined
+ {
+ };
+
+ template <typename L, typename R>
+ struct mult_trait_ : public mlc::undefined // FIXME: or "times"?
+ {
+ };
+
+ template <typename L, typename R>
+ struct div_trait_ : public mlc::undefined
{
};
+ template <typename L, typename R>
+ struct mod_trait_ : public mlc::undefined
+ {
+ };
+
+ template <typename T>
+ struct uminus_trait_ : public mlc::undefined
+ {
+ };
+
+
+
} // end of namespace xtd
Index: xtd/builtin/traits.hh
--- xtd/builtin/traits.hh (revision 442)
+++ xtd/builtin/traits.hh (working copy)
@@ -31,56 +31,92 @@
# include <xtd/traits.hh>
-namespace xtd
-{
// FIXME: this is dummy and incomplete code!
- // plus
+# define xtd_internal_DUMMY_builtin_arith_traits(OperatorName) \
+ \
+ template <typename T> \
+ struct OperatorName##_trait_ < T, T > \
+ { \
+ typedef T ret; \
+ }; \
+ \
+ template <> struct OperatorName##_trait_ < float, int > { typedef float
ret; }; \
+ template <> struct OperatorName##_trait_ < int, float > { typedef float
ret; }; \
+ template <> struct OperatorName##_trait_ < double, int > { typedef double
ret; }; \
+ template <> struct OperatorName##_trait_ < int, double > { typedef double
ret; }; \
+ template <> struct OperatorName##_trait_ < double, float > { typedef double
ret; }; \
+ template <> struct OperatorName##_trait_ < float, double > { typedef double
ret; }; \
+ \
+ template <> struct OperatorName##_trait_ < long double, int > { typedef
long double ret; }; \
+ template <> struct OperatorName##_trait_ < int, long double > { typedef
long double ret; }; \
+ template <> struct OperatorName##_trait_ < long double, float > { typedef
long double ret; }; \
+ template <> struct OperatorName##_trait_ < float, long double > { typedef
long double ret; }; \
+ template <> struct OperatorName##_trait_ < long double, double > { typedef
long double ret; }; \
+ template <> struct OperatorName##_trait_ < double, long double > { typedef
long double ret; }; \
+ \
+ struct e_n_d__w_i_t_h__s_e_m_i_c_o_l_o_n
+
+
+# define xtd_internal_DUMMY_builtin_logic_traits(OperatorName) \
+ \
+ template <> \
+ struct OperatorName##_trait_ < bool, bool > \
+ { \
+ typedef bool ret; \
+ }; \
+ \
+ struct e_n_d__w_i_t_h__s_e_m_i_c_o_l_o_n
+
+
+# define xtd_internal_DUMMY_builtin_cmp_traits(OperatorName) \
+ \
+ template <typename T> \
+ struct OperatorName##_trait_ < T, T > \
+ { \
+ typedef bool ret; \
+ }; \
+ \
+ struct e_n_d__w_i_t_h__s_e_m_i_c_o_l_o_n
+
- template <typename T>
- struct plus_trait_ < T, T >
+
+
+namespace xtd
{
- 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; };
+ // logic
+ xtd_internal_DUMMY_builtin_logic_traits( land );
+ xtd_internal_DUMMY_builtin_logic_traits( lor );
+ xtd_internal_DUMMY_builtin_logic_traits( lxor );
- // mult
+ template <> struct lnot_trait_< bool > { typedef bool ret; };
- template <typename T>
- struct mult_trait_ < T, T >
- {
- typedef T ret;
- };
+ // cmp
+
+ xtd_internal_DUMMY_builtin_cmp_traits( eq );
+ xtd_internal_DUMMY_builtin_cmp_traits( neq );
+ xtd_internal_DUMMY_builtin_cmp_traits( less );
+ xtd_internal_DUMMY_builtin_cmp_traits( leq );
+ xtd_internal_DUMMY_builtin_cmp_traits( greater );
+ xtd_internal_DUMMY_builtin_cmp_traits( geq );
+
+
+ // arith
+
+ xtd_internal_DUMMY_builtin_arith_traits( plus );
+ xtd_internal_DUMMY_builtin_arith_traits( minus );
+ xtd_internal_DUMMY_builtin_arith_traits( mult );
+ xtd_internal_DUMMY_builtin_arith_traits( div );
+ xtd_internal_DUMMY_builtin_arith_traits( mod );
- 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; };
+ template <> struct uminus_trait_< int > { typedef int ret; };
+ template <> struct uminus_trait_< float > { typedef float ret; };
+ template <> struct uminus_trait_< double > { typedef double ret; };
+ template <> struct uminus_trait_< long double > { typedef long double ret;
};
} // end of namespace xtd
Index: tests/cfun.cc
--- tests/cfun.cc (revision 0)
+++ tests/cfun.cc (revision 0)
@@ -0,0 +1,35 @@
+
+#include <iostream>
+#include <xtd/cfun.hh>
+#include <xtd/arg.hh>
+
+
+namespace my
+{
+
+ float foo()
+ {
+ return 5.1f;
+ }
+
+ float bar(int i)
+ {
+ return float(i) * 3.f;
+ }
+
+}
+
+
+
+int main()
+{
+ std::cout << xtd::mk_plain_fun(my::foo)() << std::endl;
+
+ {
+ using xtd::mk_fun;
+ using xtd::_1;
+
+ std::cout << mk_fun(my::bar)(_1)(17) << std::endl;
+ }
+
+}
Index: tests/Makefile.am
--- tests/Makefile.am (revision 442)
+++ tests/Makefile.am (working copy)
@@ -11,12 +11,14 @@
id \
bind \
cast \
+ cfun \
cos \
lit
id_SOURCES = id.cc
bind_SOURCES = bind.cc
cast_SOURCES = cast.cc
+cfun_SOURCES = cfun.cc
cos_SOURCES = cos.cc
lit_SOURCES = lit.cc