966: Better oln operators mechanism.

https://svn.lrde.epita.fr/svn/oln/trunk/olena Index: ChangeLog from Thierry Geraud <thierry.geraud@lrde.epita.fr> Better oln operators mechanism. * oln/core/gen/literal.hh: Rename as... * oln/core/gen/constant.hh: ...this. (lit_p2v_, lit_p2b_): Rename as... (constant_p2v_, constant_p2b_): ...these. (literal_): Remove. * oln/core/gen/value.hh: New. * oln/core/gen/traits.hh (oln_not_trait, not_id), (set_utrait_, get_utrait_), (uminus_id, plus_equal_id, minus_equal_id, modulus_equal_id): New. * oln/core/gen/fun_ops.hh (oln_decl_p2v_cmp_), (oln_decl_p2v_arith_), (oln_decl_p2b_bin_): Merge into... (oln_decl_binary_fun_): ...this new macro. (oln_decl_p2v_un_), (oln_decl_p2b_un_): Merge into... (oln_decl_unary_fun_): ...this new macro. (oln_decl_binary_op_), (oln_decl_binary_op_p2v_), (oln_decl_builtin_op_), (oln_decl_unary_op_): New. * oln/core/concept/iterator_on_points.hh (set_trait_): New. * oln/core/concept/function.hh (Function_p2v): Change inheritance to Function_v2v. (Function_p2b): Change inheritance to Function_p2v. (Function_p2p): Change inheritance to Function_p2v. (Function_v2w2v): New commentary. * oln/core/concept/point.hh (op_equal_, op_less_, op_plus_equal_): Remove. (op_minus_equal_, op_minus_): Remove. (operator): New. * oln/core/concept/dpoint.hh: Likewise. * oln/core/concept/operators.hh: Rewrite. * oln/value/builtin_traits.hh (set_trait_, set_utrait_): New specializations. core/concept/dpoint.hh | 185 +++++++++++++++---------- core/concept/function.hh | 36 ++-- core/concept/iterator_on_points.hh | 31 ++++ core/concept/operators.hh | 181 +++++++++++++++--------- core/concept/point.hh | 155 +++++++++++++-------- core/gen/constant.hh | 107 ++------------ core/gen/fun_ops.hh | 273 ++++++++++++++++--------------------- core/gen/traits.hh | 91 +++++++++++- core/gen/value.hh | 174 +++++++++++++++++++++++ value/builtin_traits.hh | 19 ++ 10 files changed, 798 insertions(+), 454 deletions(-) Index: oln/core/gen/constant.hh --- oln/core/gen/constant.hh (revision 961) +++ oln/core/gen/constant.hh (working copy) @@ -25,55 +25,26 @@ // reasons why the executable file might be covered by the GNU General // Public License. -#ifndef OLN_CORE_GEN_LITERAL_HH -# define OLN_CORE_GEN_LITERAL_HH +#ifndef OLN_CORE_GEN_CONSTANT_HH +# define OLN_CORE_GEN_CONSTANT_HH # include <oln/core/concept/generator.hh> # include <oln/core/concept/point.hh> -# include <oln/core/concept/value.hh> +# include <oln/core/gen/value.hh> namespace oln { - // ----------------------------- literal_<T> - - - template <typename T> - struct literal_ : public Generator< literal_<T> > - { - typedef const T& result; - - literal_(const T& val); - - const T& operator()() const; - - operator T() const; - - template <typename U> - operator literal_<U>() const; - - const T& value() const; - - private: - T val_; - }; - - - template <typename T> - literal_<T> literal(const T& val); - - - // ----------------------------- lit_p2v_<P,T> - + // constant_p2v_<P,T> template <typename P, typename V> - struct lit_p2v_ : public Function_p2v< lit_p2v_<P,V> > + struct constant_p2v_ : public Function_p2v< constant_p2v_<P,V> > { typedef P argument; typedef const V& result; - lit_p2v_(const V& val); + constant_p2v_(const V& val); const V& operator()(const P&) const; @@ -82,16 +53,15 @@ }; - // ----------------------------- lit_p2b_<P,B> - + // constant_p2b_<P,B> template <typename P, typename B> - struct lit_p2b_ : public Function_p2b< lit_p2b_<P,B> > + struct constant_p2b_ : public Function_p2b< constant_p2b_<P,B> > { typedef P argument; typedef const B& result; - lit_p2b_(const B& val); + constant_p2b_(const B& val); const B& operator()(const P&) const; @@ -104,78 +74,33 @@ # ifndef OLN_INCLUDE_ONLY - // literal_<T> - - template <typename T> - literal_<T>::literal_(const T& val) - : val_(val) - { - } - - template <typename T> - const T& - literal_<T>::operator()() const - { - return this->val_; - } - - template <typename T> - literal_<T>::operator T() const - { - return this->val_; - } - - template <typename T> - template <typename U> - literal_<T>::operator literal_<U>() const - { - literal_<U> tmp(this->val_); - return tmp; - } - - template <typename T> - const T& - literal_<T>::value() const - { - return this->val_; - } - - template <typename T> - literal_<T> - literal(const T& val) - { - literal_<T> tmp(val); - return tmp; - } - - - // lit_p2v_<P,V> + // constant_p2v_<P,V> template <typename P, typename V> - lit_p2v_<P,V>::lit_p2v_(const V& val) + constant_p2v_<P,V>::constant_p2v_(const V& val) : val_(val) { } template <typename P, typename V> const V& - lit_p2v_<P,V>::operator()(const P&) const + constant_p2v_<P,V>::operator()(const P&) const { return this->val_; } - //lit_p2b_<P,B> + //constant_p2b_<P,B> template <typename P, typename B> - lit_p2b_<P,B>::lit_p2b_(const B& val) + constant_p2b_<P,B>::constant_p2b_(const B& val) : val_(val) { } template <typename P, typename B> const B& - lit_p2b_<P,B>::operator()(const P&) const + constant_p2b_<P,B>::operator()(const P&) const { return this->val_; } @@ -185,4 +110,4 @@ } // end of namespace oln -#endif // ! OLN_CORE_GEN_LITERAL_HH +#endif // ! OLN_CORE_GEN_CONSTANT_HH Index: oln/core/gen/traits.hh --- oln/core/gen/traits.hh (revision 965) +++ oln/core/gen/traits.hh (working copy) @@ -48,6 +48,10 @@ # define oln_mod_trait(L, R) \ typename oln::get_trait_<L, oln::mod_id, R>::ret +# define oln_uminus_trait(T) \ + typename oln::get_utrait_<oln::uminus_id, T>::ret + + // cmp # define oln_eq_trait(L, R) \ @@ -56,6 +60,7 @@ # define oln_neq_trait(L, R) \ typename oln::get_trait_<L, oln::neq_id, R>::ret + // ord # define oln_less_trait(L, R) \ @@ -70,6 +75,7 @@ # define oln_greater_trait(L, R) \ typename oln::get_trait_<L, oln::greater_id, R>::ret + // logic # define oln_and_trait(L, R) \ @@ -81,6 +87,9 @@ # define oln_xor_trait(L, R) \ typename oln::get_trait_<L, oln::xor_id, R>::ret +# define oln_not_trait(T) \ + typename oln::get_utrait_<oln::not_id, T>::ret + @@ -111,8 +120,8 @@ namespace oln { - // set_trait_ + // set_trait_ for binary operators. template <template <class> class Cl, typename L, typename Op, @@ -130,8 +139,33 @@ template <template <class> class Cl, typename L, typename Op, template <class> class Cr, typename R> - struct set_trait_ // default is - : public set_trait_<Any, L, Op, Any, R> + struct set_trait_ + : // default is + public set_trait_<Any, L, Op, Any, R> + { + }; + + + + // set_utrait_ for unary operators. + + template <typename Op, + template <class> class C, typename T> + struct set_utrait_; + + + template <typename Op, typename T> + struct set_utrait_<Op, Any, T> + { + // nothing => do not compile + }; + + + template <typename Op, + template <class> class C, typename T> + struct set_utrait_ + : // default is + public set_utrait_<Op, Any, T> { }; @@ -145,6 +179,12 @@ struct div_id; struct mod_id; + struct uminus_id; + + struct plus_equal_id; + struct minus_equal_id; + struct modulus_equal_id; + struct eq_id; struct neq_id; @@ -156,6 +196,7 @@ struct and_id; struct or_id; struct xor_id; + struct not_id; @@ -181,6 +222,10 @@ oln_internal_specialize_bin_trait_T_(xor); + // Fwd decl. + template <typename T> struct value_; + + namespace internal { @@ -197,11 +242,49 @@ typedef typename oln::set_trait_< Cl, L, Op, Cr, R >::ret ret; }; + // get_utrait_cat_ + + template <typename Op, typename C, typename T> + struct get_utrait_cat__; + + template < typename Op, + template <class> class C, typename T > + struct get_utrait_cat__< Op, stc::is<C>, T > + { + typedef typename oln::set_utrait_< Op, C, T >::ret ret; + }; + + // clean_for_trait_ + + template <typename T> + struct clean_for_trait_ + { + typedef T ret; + }; + + template <typename T> + struct clean_for_trait_< const oln::value_<T> > { typedef T ret; }; + template <typename T> + struct clean_for_trait_< const oln::value_<T>& > { typedef T ret; }; + template <typename T> + struct clean_for_trait_< oln::value_<T>& > { typedef T ret; }; + + // FIXME: Add clean_for_trait_ for builtins? + } // end of namespace oln::internal template <typename L, typename Op, typename R> - struct get_trait_ : public internal::get_trait_cat__< oln_category_of_(L), L, Op, oln_category_of_(R), R > + struct get_trait_ : public internal::get_trait_cat__< oln_category_of_(L), + typename internal::clean_for_trait_<L>::ret, + Op, + oln_category_of_(R), + typename internal::clean_for_trait_<R>::ret > + { + }; + + template <typename Op, typename T> + struct get_utrait_ : public internal::get_utrait_cat__< Op, oln_category_of_(T), T > { }; Index: oln/core/gen/fun_ops.hh --- oln/core/gen/fun_ops.hh (revision 965) +++ oln/core/gen/fun_ops.hh (working copy) @@ -29,184 +29,171 @@ # define OLN_CORE_GEN_FUN_OPS_HH # include <oln/core/gen/fun.hh> -# include <oln/core/gen/literal.hh> +# include <oln/core/gen/constant.hh> -# define oln_decl_p2v_cmp_(Name, Sym) \ +# define oln_decl_binary_fun_(Kind, Name, Sym) \ \ template <typename L, typename R> \ - struct p2v_##Name##_ : public Function_p2b< p2v_##Name##_<L,R> > \ + struct Kind##_##Name##_ : public Function_##Kind< Kind##_##Name##_<L,R> > \ { \ - typedef oln_arg_of_(L) argument; \ - typedef bool result; /* FIXME: trait! */ \ + typedef oln_argument(L) argument; \ + typedef oln_##Name##_trait(oln_result(L), oln_result(R)) result; \ \ - p2v_##Name##_(const Function_p2v<L>& left, const Function_p2v<R>& right) \ - : left_(exact(left)), \ - right_(exact(right)) \ + Kind##_##Name##_(const L& left, const R& right) \ + : left_(left), \ + right_(right) \ { \ } \ - bool operator()(argument arg) const \ + \ + result operator()(argument arg) const \ { \ return this->left_(arg) Sym this->right_(arg); \ } \ + \ private: \ L left_; \ R right_; \ }; \ \ - template <typename L, typename R> \ - p2v_##Name##_<L,R> \ - operator Sym (const Function_p2v<L>& left, const Function_p2v<R>& right) \ + struct e_n_d___w_i_t_h___s_e_m_i_c_o_l_u_m_n + + + + +# define oln_decl_unary_fun_(Kind, Name, Sym) \ + \ + template <typename T> \ + struct Kind##_##Name##_ : public Function_##Kind< Kind##_##Name##_<T> > \ { \ - mlc::assert_< mlc_is_a(oln_argument(L), Point) >::check(); \ - mlc::assert_< mlc_is_a(oln_argument(R), Point) >::check(); \ - mlc::assert_equal_< oln_argument(L), oln_argument(R) >::check(); \ - p2v_##Name##_<L,R> tmp(left, right); \ - return tmp; \ - } \ + typedef oln_argument(T) argument; \ + typedef oln_##Name##_trait(oln_result(T)) result; \ \ - template <typename L, typename R> \ - p2v_##Name##_<L, lit_p2v_<oln_argument(L), R> > \ - operator Sym (const Function_p2v<L>& left, const literal_<R>& right) \ + Kind##_##Name##_(const T& oper) \ + : oper_(oper) \ { \ - mlc::assert_< mlc_is_a(oln_argument(L), Point) >::check(); \ - lit_p2v_<oln_argument(L), R> right_(right.value()); \ - p2v_##Name##_<L, lit_p2v_<oln_argument(L), R> > tmp(left, right_); \ - return tmp; \ } \ \ - template <typename L> \ - p2v_##Name##_<L, lit_p2v_<oln_argument(L), oln_result(L)> > \ - operator Sym (const Function_p2v<L>& left, const oln_result(L)& right) \ + result operator()(argument arg) const \ { \ - mlc::assert_< mlc_is_a(oln_argument(L), Point) >::check(); \ - lit_p2v_<oln_argument(L), oln_result(L)> right_(right); \ - p2v_##Name##_<L, lit_p2v_<oln_argument(L), oln_result(L)> > tmp(left, right_); \ - return tmp; \ + return Sym this->oper_(arg); \ } \ \ + private: \ + T oper_; \ + }; \ + \ struct e_n_d___w_i_t_h___s_e_m_i_c_o_l_u_m_n -# define oln_decl_p2v_arith_(Name, Sym) \ + +# define oln_decl_binary_op_(IKind, Name, Sym, OKind) \ + \ + \ + oln_decl_binary_fun_(OKind, Name, Sym); \ + \ \ template <typename L, typename R> \ - struct p2v_##Name##_ : public Function_p2v< p2v_##Name##_<L,R> > \ + struct set_trait_< Function_##IKind, L, Name##_id, Function_##IKind, R > \ { \ - typedef oln_arg_of_(L) argument; \ - typedef oln_res_of_(L) result; /* FIXME: trait! */ \ + typedef OKind##_##Name##_<L, R> ret; \ + }; \ \ - p2v_##Name##_(const Function_p2v<L>& left, const Function_p2v<R>& right) \ - : left_(exact(left)), \ - right_(exact(right)) \ + template <typename L, typename R> \ + oln_##Name##_trait(L, R) \ + operator Sym (const Function_##IKind<L>& left, const Function_##IKind<R>& right) \ { \ + mlc::assert_< mlc_is_a(oln_argument(L), Point) >::check(); \ + mlc::assert_< mlc_is_a(oln_argument(R), Point) >::check(); \ + mlc::assert_equal_< oln_argument(L), oln_argument(R) >::check(); \ + oln_##Name##_trait(L, R) tmp(exact(left), exact(right)); \ + return tmp; \ } \ - result operator()(argument arg) const \ + \ + \ + template <typename L, typename R> \ + struct set_trait_< Function_##IKind, L, Name##_id, Value, R > \ { \ - return this->left_(arg) Sym this->right_(arg); \ - } \ - private: \ - L left_; \ - R right_; \ + typedef OKind##_##Name##_<L, constant_##IKind##_<oln_argument(L), R> > ret; \ }; \ \ template <typename L, typename R> \ - p2v_##Name##_<L,R> \ - operator Sym (const Function_p2v<L>& left, const Function_p2v<R>& right) \ + oln_##Name##_trait(L, value_<R>) \ + operator Sym (const Function_##IKind<L>& left, const value_<R>& right) \ { \ mlc::assert_< mlc_is_a(oln_argument(L), Point) >::check(); \ - mlc::assert_< mlc_is_a(oln_argument(R), Point) >::check(); \ - p2v_##Name##_<L,R> tmp(left, right); \ + oln_##Name##_trait(L, value_<R>) tmp(exact(left), make_value(right)); \ return tmp; \ } \ \ + \ template <typename L, typename R> \ - p2v_##Name##_<L, lit_p2v_<oln_argument(L), R> > \ - operator Sym (const Function_p2v<L>& left, const literal_<R>& right) \ + struct set_trait_< Value, L, Name##_id, Function_##IKind, R > \ { \ - mlc::assert_< mlc_is_a(oln_argument(L), Point) >::check(); \ - lit_p2v_<oln_argument(L), R> right_(right.value()); \ - p2v_##Name##_<L, lit_p2v_<oln_argument(L), R> > tmp(left, right_); \ + typedef OKind##_##Name##_<constant_##IKind##_<oln_argument(R), L>, R> ret; \ + }; \ + \ + template <typename L, typename R> \ + oln_##Name##_trait(value_<L>, R) \ + operator Sym (const value_<L>& left, const Function_##IKind<R>& right) \ + { \ + mlc::assert_< mlc_is_a(oln_argument(R), Point) >::check(); \ + oln_##Name##_trait(value_<L>, R) tmp(make_value(left), exact(right)); \ return tmp; \ } \ \ + \ struct e_n_d___w_i_t_h___s_e_m_i_c_o_l_u_m_n -# define oln_decl_p2v_un_(Name, Sym) \ + + +# define oln_decl_unary_op_(IKind, Name, Sym, OKind) \ \ - template <typename T> \ - struct p2v_##Name##_ : public Function_p2v< p2v_##Name##_<T> > \ - { \ - typedef oln_arg_of_(T) argument; \ - typedef oln_res_of_(T) result; /* FIXME: trait! */ \ \ - p2v_##Name##_(const Function_p2v<T>& oper) \ - : oper_(exact(oper)) \ - { \ - } \ - result operator()(argument arg) const \ + oln_decl_unary_fun_(OKind, Name, Sym); \ + \ + \ + template <typename T> \ + struct set_utrait_< Name##_id, Function_##IKind, T > \ { \ - return Sym this->oper_(arg); \ - } \ - private: \ - T oper_; \ + typedef OKind##_##Name##_<T> ret; \ }; \ \ template <typename T> \ - p2v_##Name##_<T> \ - operator Sym (const Function_p2v<T>& oper) \ + oln_##Name##_trait(T) \ + operator Sym (const Function_##IKind<T>& oper) \ { \ - p2v_##Name##_<T> tmp(oper); \ + oln_##Name##_trait(T) tmp(exact(oper)); \ return tmp; \ } \ \ + \ struct e_n_d___w_i_t_h___s_e_m_i_c_o_l_u_m_n -# define oln_decl_p2b_bin_(Name, Sym) \ - \ - template <typename L, typename R> \ - struct p2b_##Name##_ : public Function_p2b< p2b_##Name##_<L,R> > \ - { \ - typedef oln_arg_of_(L) argument; \ - typedef oln_res_of_(L) result; \ - \ - p2b_##Name##_(const Function_p2b<L>& left, const Function_p2b<R>& right) \ - : left_(exact(left)), \ - right_(exact(right)) \ - { \ - } \ - result operator()(argument arg) const \ - { \ - return this->left_(arg) Sym this->right_(arg); \ - } \ - private: \ - L left_; \ - R right_; \ - }; \ + +# define oln_decl_builtin_op_(IKind, Name, Sym, Builtin) \ \ - template <typename L, typename R> \ - p2b_##Name##_<L,R> \ - operator Sym (const Function_p2b<L>& left, const Function_p2b<R>& right) \ + template <typename L> \ + oln_##Name##_trait(L, value_<Builtin>) \ + operator Sym (const Function_##IKind<L>& left, const Builtin& right) \ { \ mlc::assert_< mlc_is_a(oln_argument(L), Point) >::check(); \ - mlc::assert_< mlc_is_a(oln_argument(R), Point) >::check(); \ - p2b_##Name##_<L,R> tmp(left, right); \ + oln_##Name##_trait(L, value_<Builtin>) tmp(exact(left), make_value(right)); \ return tmp; \ } \ \ - template <typename L, typename R> \ - p2b_##Name##_<L, lit_p2b_<oln_argument(L), R> > \ - operator Sym (const Function_p2b<L>& left, const literal_<R>& right) \ + template <typename R> \ + oln_##Name##_trait(value_<Builtin>, R) \ + operator Sym (const Builtin& left, const Function_##IKind<R>& right) \ { \ - mlc::assert_< mlc_is_a(oln_argument(L), Point) >::check(); \ - lit_p2b_<oln_argument(L), R> right_(right.value()); \ - p2b_##Name##_<L, lit_p2b_<oln_argument(L), R> > tmp(left, right_); \ + mlc::assert_< mlc_is_a(oln_argument(R), Point) >::check(); \ + oln_##Name##_trait(value_<Builtin>, R) tmp(make_value(left), exact(right)); \ return tmp; \ } \ \ @@ -214,34 +201,14 @@ - -# define oln_decl_p2b_un_(Name, Sym) \ - \ - template <typename T> \ - struct p2b_##Name##_ : public Function_p2b< p2b_##Name##_<T> > \ - { \ - typedef oln_arg_of_(T) argument; \ - typedef oln_res_of_(T) result; /* FIXME: trait! */ \ +# define oln_decl_binary_op_p2v_(Name, Sym, OKind) \ \ - p2b_##Name##_(const Function_p2b<T>& oper) \ - : oper_(exact(oper)) \ - { \ - } \ - result operator()(argument arg) const \ - { \ - return Sym this->oper_(arg); \ - } \ - private: \ - T oper_; \ - }; \ + oln_decl_binary_op_( p2v, Name, Sym, OKind ); \ \ - template <typename T> \ - p2b_##Name##_<T> \ - operator Sym (const Function_p2b<T>& oper) \ - { \ - p2b_##Name##_<T> tmp(oper); \ - return tmp; \ - } \ + oln_decl_builtin_op_( p2v, Name, Sym, unsigned ); \ + oln_decl_builtin_op_( p2v, Name, Sym, int ); \ + oln_decl_builtin_op_( p2v, Name, Sym, float ); \ + oln_decl_builtin_op_( p2v, Name, Sym, double ); \ \ struct e_n_d___w_i_t_h___s_e_m_i_c_o_l_u_m_n @@ -250,30 +217,36 @@ namespace oln { - oln_decl_p2v_cmp_( eq, = ); - oln_decl_p2v_cmp_( not_eq, != ); - oln_decl_p2v_cmp_( less, < ); - oln_decl_p2v_cmp_( leq, <= ); - oln_decl_p2v_cmp_( greater, > ); - oln_decl_p2v_cmp_( geq, >= ); - - oln_decl_p2v_arith_( plus, + ); - oln_decl_p2v_arith_( minus, - ); - oln_decl_p2v_arith_( times, * ); - oln_decl_p2v_arith_( div, / ); - oln_decl_p2v_arith_( mod, % ); - - oln_decl_p2v_un_( uminus, - ); - - oln_decl_p2b_bin_( and, && ); - oln_decl_p2b_bin_( or, || ); - oln_decl_p2b_bin_( xor, ^ ); - // FIXME: nand, nor, xnor? + // input output + // vvv vvv + + oln_decl_binary_op_p2v_( eq, =, p2b ); + oln_decl_binary_op_p2v_( neq, !=, p2b ); + + oln_decl_binary_op_p2v_( less, < , p2b ); + oln_decl_binary_op_p2v_( leq, <=, p2b ); + oln_decl_binary_op_p2v_( greater, > , p2b ); + oln_decl_binary_op_p2v_( geq, >=, p2b ); + + oln_decl_binary_op_p2v_( plus, +, p2v ); + oln_decl_binary_op_p2v_( minus, -, p2v ); + oln_decl_binary_op_p2v_( times, *, p2v ); + oln_decl_binary_op_p2v_( div, /, p2v ); + oln_decl_binary_op_p2v_( mod, %, p2v ); + + oln_decl_unary_op_( p2v, uminus, -, p2v ); + + oln_decl_binary_op_( p2b, and, &&, p2b ); + oln_decl_binary_op_( p2b, or, ||, p2b ); + oln_decl_binary_op_( p2b, xor, ^, p2b ); - oln_decl_p2b_un_( not, ! ); + oln_decl_unary_op_( p2b, not, !, p2b ); } // end of namespace oln + // FIXME: nand, nor, xnor? + + #endif // ! OLN_CORE_GEN_FUN_OPS_HH Index: oln/core/gen/value.hh --- oln/core/gen/value.hh (revision 0) +++ oln/core/gen/value.hh (revision 0) @@ -0,0 +1,174 @@ +// Copyright (C) 2007 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, 51 Franklin Street, Fifth Floor, +// 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 OLN_CORE_GEN_VALUE_HH +# define OLN_CORE_GEN_VALUE_HH + +# include <oln/core/concept/value.hh> + + +namespace oln +{ + + // Fwd decl. + template <typename T> struct value_; + + + // Super trait. + template <typename T> + struct super_trait_< value_<T> > + { + typedef Value< value_<T> > ret; + }; + + + // Virtual types. + template <typename T> + struct vtypes< value_<T> > + { + typedef stc::is<Value> category; // FIXME: Temporary code. + }; + + + // Wrapper class for a value. + template <typename T> + struct value_ : public Value< value_<T> > + { + typedef T encoding; + + value_(); + + template <typename U> + value_(const U& v); + + template <typename U> + value_(const value_<U>& v); + + template <typename U> + value_<T>& operator=(const value_<U>& v); + + operator T() const; + + template <typename U> + operator U() const; + + template <typename U> + operator value_<U>() const; + + private: + T val_; + }; + + + // make_value + + template <typename T> + value_<T> make_value(const T& val); + + template <typename T> + value_<T> make_value(const value_<T>& val); + + + // traits + + template <typename L, typename Op, typename R> + struct set_trait_< Value, value_<L>, Op, Value, value_<R> > + { + typedef typename get_trait_<L, Op, R>::ret ret; + }; + + +# ifndef OLN_INCLUDE_ONLY + + template <typename T> + value_<T>::value_() + { + } + + template <typename T> + template <typename U> + value_<T>::value_(const U& v) + : val_(v) + { + } + + template <typename T> + template <typename U> + value_<T>::value_(const value_<U>& v) + : val_(U(v)) + { + } + + template <typename T> + template <typename U> + value_<T>& + value_<T>::operator=(const value_<U>& v) + { + this->val_ = U(v); + return *this; + } + + template <typename T> + value_<T>::operator T() const + { + return this->val_; + } + + template <typename T> + template <typename U> + value_<T>::operator U() const + { + return static_cast<U>(this->val_); + } + + template <typename T> + template <typename U> + value_<T>::operator value_<U>() const + { + value_<U> tmp = static_cast<U>(this->val_); + return tmp; + } + + template <typename T> + value_<T> make_value(const T& val) + { + value_<T> tmp = val; + return tmp; + } + + template <typename T> + value_<T> make_value(const value_<T>& val) + { + return val; + } + +# endif // ! OLN_INCLUDE_ONLY + +} // end of namespace oln + + +#endif // ! OLN_CORE_GEN_VALUE_HH Index: oln/core/concept/iterator_on_points.hh --- oln/core/concept/iterator_on_points.hh (revision 965) +++ oln/core/concept/iterator_on_points.hh (working copy) @@ -73,6 +73,37 @@ } // end of namespace oln::internal + + // \{ + // Operator - traits. + + template <typename P, typename It> + struct set_trait_< Point, P, minus_id, Iterator_on_Points, It > + { + typedef oln_point(It) Pit; + typedef oln_minus_trait(P, Pit) ret; + }; + + template <typename It, typename P> + struct set_trait_< Iterator_on_Points, It, minus_id, Point, P > + { + typedef oln_point(It) Pit; + typedef oln_minus_trait(Pit, P) ret; + }; + + template <typename It1, typename It2> + struct set_trait_< Iterator_on_Points, It1, minus_id, Iterator_on_Points, It2 > + { + typedef oln_point(It1) Pit1; + typedef oln_point(It2) Pit2; + typedef oln_minus_trait(Pit1, Pit2) ret; + }; + + // \} + + + + # ifndef OLN_INCLUDE_ONLY template <typename Exact> Index: oln/core/concept/function.hh --- oln/core/concept/function.hh (revision 965) +++ oln/core/concept/function.hh (working copy) @@ -45,10 +45,21 @@ }; + // Value -> Value. + + template <typename Exact> + struct Function_v2v : public Function<Exact> + { + typedef Function_v2v<void> category; + protected: + Function_v2v(); + }; + + // Point -> Value. template <typename Exact> - struct Function_p2v : public Function<Exact> + struct Function_p2v : public Function_v2v<Exact> { typedef Function_p2v<void> category; protected: @@ -59,7 +70,7 @@ // Point -> bool. template <typename Exact> - struct Function_p2b : public Function<Exact> + struct Function_p2b : public Function_p2v<Exact> { typedef Function_p2b<void> category; protected: @@ -67,21 +78,21 @@ }; - // Value -> Value. + // Point -> Point. template <typename Exact> - struct Function_v2v : public Function<Exact> + struct Function_p2p : public Function_p2v<Exact> { - typedef Function_v2v<void> category; + typedef Function_p2p<void> category; protected: - Function_v2v(); + Function_p2p(); }; // Value1 -> Value2 *and* Value2 -> Value1. template <typename Exact> - struct Function_v2w2v : public Function<Exact> + struct Function_v2w2v : public Function<Exact> // FIXME: public Function_v2v<Exact>? { typedef Function_v2w2v<void> category; protected: @@ -89,17 +100,6 @@ }; - // Point -> Point. - - template <typename Exact> - struct Function_p2p : public Function<Exact> - { - typedef Function_p2p<void> category; - protected: - Function_p2p(); - }; - - # ifndef OLN_INCLUDE_ONLY template <typename Exact> Index: oln/core/concept/point.hh --- oln/core/concept/point.hh (revision 965) +++ oln/core/concept/point.hh (working copy) @@ -40,6 +40,10 @@ namespace oln { + // Fwd decl. + template <typename Exact> struct Dpoint; + + /// Concept-class "Generalized_Point". template <typename Exact> @@ -57,62 +61,75 @@ }; - /// Concept-class "Point". + // Operator -. - template <typename Exact> - struct Point : public Generalized_Point<Exact> - { - stc_using_from(Generalized_Point, dpoint); + template <typename P1, typename P2> + oln_minus_trait(P1, P2) + operator - (const Generalized_Point<P1>& lhs, const Generalized_Point<P2>& rhs); - /// Operator =. - bool op_equal_(const Exact& rhs) const; + // Operator =. - /// Operator <. - bool op_less_(const Exact& rhs) const; + template <typename P1, typename P2> + bool operator = (const Generalized_Point<P1>& lhs, const Generalized_Point<P2>& rhs); - /// Operator +=. - Exact& op_plus_equal_(const dpoint& rhs); + // Operator <. - /// Operator -=. - Exact& op_minus_equal_(const dpoint& rhs); + template <typename P1, typename P2> + bool operator < (const Generalized_Point<P1>& lhs, const Generalized_Point<P2>& rhs); - /// Operator -. - dpoint op_minus_(const Exact& rhs) const; + // Operator +=. - protected: - Point(); + template <typename P, typename Dp> // Defined in oln/core/concept/dpoint.hh + P& operator += (Generalized_Point<P>& lhs, const Dpoint<Dp>& rhs); - }; // end of oln::Point<Exact> + // Operator -=. + template <typename P, typename Dp> // Defined in oln/core/concept/dpoint.hh + P& operator -= (Generalized_Point<P>& lhs, const Dpoint<Dp>& rhs); - /// Operator -. - template <typename P> - struct set_trait_< Point, P, minus_id, Point, P > - { - typedef typename P::dpoint ret; - }; + // \{ + // Invalid operators. + + template <typename P1, typename P2> + void operator + (const Generalized_Point<P1>& lhs, + const Generalized_Point<P2>& rhs); + + template <typename P1, typename P2> + void operator += (const Generalized_Point<P1>& lhs, + const Generalized_Point<P2>& rhs); template <typename P> - typename P::dpoint - operator - (const Point<P>& lhs, const Point<P>& rhs); + void operator - (const Generalized_Point<P>& rhs); + template <typename P1, typename P2> + void operator -= (const Generalized_Point<P1>& lhs, + const Generalized_Point<P2>& rhs); + // \} - /// \{ - /// Invalid operators. - template <typename P> - void operator-(const Point<P>& rhs) /* error */ ; - template <typename P1, typename P2> - void operator+(const Point<P1>& lhs, const Point<P2>& rhs) /* error */ ; + /// Concept-class "Point". - /// \} + template <typename Exact> + struct Point : public Generalized_Point<Exact> + { + protected: + Point(); + + }; // end of oln::Point<Exact> + template <typename P> + struct set_trait_< Point, P, minus_id, Point, P > + { + typedef oln_dpoint(P) ret; // FIXME: Wrong! (too restrictive) + }; + + namespace internal { @@ -147,41 +164,76 @@ # ifndef OLN_INCLUDE_ONLY + // Generalized_Point + template <typename Exact> Generalized_Point<Exact>::Generalized_Point() { } - template <typename Exact> - bool Point<Exact>::op_equal_(const Exact& rhs) const + template <typename P> + oln_minus_trait(P, P) + operator - (const Generalized_Point<P>& lhs, const Generalized_Point<P>& rhs) { - return exact(this)->impl_op_equal_(rhs); + oln_minus_trait(P, P) tmp; + tmp.vec() = exact(lhs).vec() - exact(rhs).vec(); + return tmp; } - template <typename Exact> - bool Point<Exact>::op_less_(const Exact& rhs) const + template <typename P1, typename P2> + bool + operator = (const Generalized_Point<P1>& lhs, const Generalized_Point<P2>& rhs) { - return exact(this)->impl_op_less_(rhs); + return exact(lhs).vec() = exact(rhs).vec(); } - template <typename Exact> - Exact& Point<Exact>::op_plus_equal_(const typename Point<Exact>::dpoint& rhs) + template <typename P1, typename P2> + bool + operator < (const Generalized_Point<P1>& lhs, const Generalized_Point<P2>& rhs) { - return exact(this)->impl_op_plus_equal_(rhs); + return exact(lhs).vec() < exact(rhs).vec(); } - template <typename Exact> - Exact& Point<Exact>::op_minus_equal_(const typename Point<Exact>::dpoint& rhs) + // Invalid operators. + + template <typename P1, typename P2> + void operator + (const Generalized_Point<P1>& lhs, + const Generalized_Point<P2>& rhs) { - return exact(this)->impl_op_minus_equal_(rhs); + mlc::abort_<P1, + ERROR::operator_< plus_id >::template _is_invalid_for_types_<P1, P2> + >::check(); } - template <typename Exact> - typename Point<Exact>::dpoint Point<Exact>::op_minus_(const Exact& rhs) const + template <typename P1, typename P2> + void operator += (const Generalized_Point<P1>& lhs, + const Generalized_Point<P2>& rhs) + { + mlc::abort_<P1, + ERROR::operator_< plus_equal_id >::template _is_invalid_for_types_<P1, P2> + >::check(); + } + + template <typename P1, typename P2> + void operator -= (const Generalized_Point<P1>& lhs, + const Generalized_Point<P2>& rhs) { - return exact(this)->impl_op_minus_(rhs); + mlc::abort_<P1, + ERROR::operator_< minus_equal_id >::template _is_invalid_for_types_<P1, P2> + >::check(); } + template <typename P> + void operator - (const Generalized_Point<P>& rhs) + { + mlc::abort_<P, + ERROR::operator_< uminus_id >::template _is_invalid_for_<P> + >::check(); + } + + + // Point + template <typename Exact> Point<Exact>::Point() { @@ -203,13 +255,6 @@ } // end of namespace oln::internal - template <typename P> - typename P::dpoint - operator-(const Point<P>& lhs, const Point<P>& rhs) - { - return lhs.op_minus_(exact(rhs)); - } - # endif // ! OLN_INCLUDE_ONLY } // end of namespace oln Index: oln/core/concept/dpoint.hh --- oln/core/concept/dpoint.hh (revision 965) +++ oln/core/concept/dpoint.hh (working copy) @@ -59,143 +59,190 @@ enum { n = mlc_value(dim) }; - /// Operator =. - bool op_equal_(const Exact& rhs) const; + protected: + Dpoint(); - /// Operator <. - bool op_less_(const Exact& rhs) const; + }; // end of oln::Dpoint<Exact> - /// Operator +=. - Exact& op_plus_equal_(const Exact& rhs); - /// Operator -=. - Exact& op_minus_equal_(const Exact& rhs); - /// Operator %=. - Exact& op_mod_equal_(const Exact& rhs); + // Operators on Dpoints. - /// Operator -. - Exact op_unary_minus_() const; + template <typename D1, typename D2> + bool operator = (const Dpoint<D1>& lhs, const Dpoint<D2>& rhs); - protected: - Dpoint(); + template <typename D1, typename D2> + bool operator < (const Dpoint<D1>& lhs, const Dpoint<D2>& rhs); - }; // end of oln::Dpoint<Exact> + template <typename D, typename D2> + D& operator += (Dpoint<D>& lhs, const Dpoint<D2>& rhs); + + template <typename D, typename D2> + D& operator -= (Dpoint<D>& lhs, const Dpoint<D2>& rhs); + + template <typename D> + D operator - (const Dpoint<D>& rhs); + template <typename D, typename D2> + D& operator %= (Dpoint<D>& lhs, const Dpoint<D2>& rhs); - /// \{ - /// Operator "Point - Dpoint". + + + // \{ + // Traits. template <typename P, typename D> - struct set_trait_< Point, P, minus_id, Dpoint, D > + struct set_trait_< Point, P, plus_id, Dpoint, D > { - typedef P ret; + typedef P ret; // FIXME: Wrong! (too restrictive) }; template <typename P, typename D> - P operator-(const Point<P>& lhs, const Dpoint<D>& rhs); + struct set_trait_< Point, P, minus_id, Dpoint, D > + { + typedef P ret; // FIXME: Wrong! (too restrictive) + }; - /// \} + // \} - /// \{ - /// Operator "Point + Dpoint". + + // Operators mixing Generalized_Point and Dpoint. template <typename P, typename D> - struct set_trait_< Point, P, plus_id, Dpoint, D > - { - typedef P ret; - }; + oln_plus_trait(P, D) + operator + (const Generalized_Point<P>& lhs, const Dpoint<D>& rhs); template <typename P, typename D> - P operator+(const Point<P>& lhs, const Dpoint<D>& rhs); + oln_minus_trait(P, D) + operator - (const Generalized_Point<P>& lhs, const Dpoint<D>& rhs); - /// \} - /// \{ - /// Invalid operators. + // \{ + // Invalid operators. template <typename D, typename P> - void operator-(const Dpoint<D>& lhs, const Point<P>& rhs) /* error */ ; + void operator - (const Dpoint<D>& lhs, const Generalized_Point<P>& rhs); template <typename D, typename P> - void operator+(const Dpoint<D>& lhs, const Point<P>& rhs) /* error */ ; + void operator + (const Dpoint<D>& lhs, const Generalized_Point<P>& rhs); - /// \} + // \} -# ifndef OLN_INCLUDE_ONLY +# ifndef OLN_INCLUDE_ONLY template <typename Exact> - bool Dpoint<Exact>::op_equal_(const Exact& rhs) const + Dpoint<Exact>::Dpoint() { - return exact(this)->impl_op_equal_(rhs); + // FIXME: Uncomment! + // mlc::assert_defined_< oln_vtype(Exact, grid) >::check(); + // mlc::assert_defined_< oln_vtype(Exact, point) >::check(); + // mlc::assert_defined_< oln_vtype(Exact, coord) >::check(); + // mlc::assert_defined_< oln_vtype(Exact, dim) >::check(); } - template <typename Exact> - bool Dpoint<Exact>::op_less_(const Exact& rhs) const + + // Operators on Dpoints. + + template <typename D1, typename D2> + bool operator = (const Dpoint<D1>& lhs, const Dpoint<D2>& rhs) { - return exact(this)->impl_op_less_(rhs); + return exact(lhs).vec() = exact(rhs).vec(); } - template <typename Exact> - Exact& Dpoint<Exact>::op_plus_equal_(const Exact& rhs) + template <typename D1, typename D2> + bool operator < (const Dpoint<D1>& lhs, const Dpoint<D2>& rhs) { - return exact(this)->impl_op_plus_equal_(rhs); + return exact(lhs).vec() < exact(rhs).vec(); } - template <typename Exact> - Exact& Dpoint<Exact>::op_minus_equal_(const Exact& rhs) + template <typename D, typename D2> + D& operator += (Dpoint<D>& lhs, const Dpoint<D2>& rhs) { - return exact(this)->impl_op_minus_equal_(rhs); + exact(lhs).vec() += exact(rhs).vec(); + return exact(lhs); } - template <typename Exact> - Exact& Dpoint<Exact>::op_mod_equal_(const Exact& rhs) + template <typename D, typename D2> + D& operator -= (Dpoint<D>& lhs, const Dpoint<D2>& rhs) { - return exact(this)->impl_op_mod_equal_(rhs); + exact(lhs).vec() -= exact(rhs).vec(); + return exact(lhs); } - template <typename Exact> - Exact Dpoint<Exact>::op_unary_minus_() const + template <typename D> + D operator - (const Dpoint<D>& rhs) { - return exact(this)->impl_op_unary_minus_(); + D tmp; + tmp.vec() = - exact(rhs).vec(); + return tmp; } - template <typename Exact> - Dpoint<Exact>::Dpoint() + template <typename D, typename D2> + D& operator %= (Dpoint<D>& lhs, const Dpoint<D2>& rhs) { - // FIXME: Uncomment! - // mlc::assert_defined_< oln_vtype(Exact, grid) >::check(); - // mlc::assert_defined_< oln_vtype(Exact, point) >::check(); - // mlc::assert_defined_< oln_vtype(Exact, coord) >::check(); - // mlc::assert_defined_< oln_vtype(Exact, dim) >::check(); + exact(lhs).vec() %= exact(rhs).vec(); + return exact(lhs); } - /// \{ - /// Operators. + // Operators mixing Generalized_Point and Dpoint. + + template <typename P, typename D> // from oln/core/concept/point.hh + P& operator += (Generalized_Point<P>& lhs, const Dpoint<D>& rhs) + { + exact(lhs).vec() += exact(rhs).vec(); + return exact(lhs); + } + + template <typename P, typename D> // from oln/core/concept/point.hh + P& operator -= (Generalized_Point<P>& lhs, const Dpoint<D>& rhs) + { + exact(lhs).vec() -= exact(rhs).vec(); + return exact(lhs); + } template <typename P, typename D> - P operator-(const Point<P>& lhs, const Dpoint<D>& rhs) + oln_plus_trait(P, D) + operator + (const Generalized_Point<P>& lhs, const Dpoint<D>& rhs) { - P tmp = exact(lhs); - return tmp -= rhs; + oln_plus_trait(P, D) tmp; + tmp.vec() = exact(lhs).vec() + exact(rhs).vec(); + return tmp; } template <typename P, typename D> - P operator+(const Point<P>& lhs, const Dpoint<D>& rhs) + oln_minus_trait(P, D) + operator - (const Generalized_Point<P>& lhs, const Dpoint<D>& rhs) { - P tmp = exact(lhs); - return tmp += rhs; + oln_minus_trait(P, D) tmp; + tmp.vec() = exact(lhs).vec() - exact(rhs).vec(); + return tmp; } - /// \} -# endif // ! OLN_INCLUDE_ONLY + // Invalid operators. + + template <typename D, typename P> + void operator + (const Dpoint<D>& lhs, const Generalized_Point<P>& rhs) + { + mlc::abort_<D, + ERROR::operator_< plus_id >::template _is_invalid_for_types_<D, P> + >::check(); + } + template <typename D, typename P> + void operator - (const Dpoint<D>& lhs, const Generalized_Point<P>& rhs) + { + mlc::abort_<D, + ERROR::operator_< minus_id >::template _is_invalid_for_types_<D, P> + >::check(); + } + +# endif // ! OLN_INCLUDE_ONLY } // end of namespace oln Index: oln/core/concept/operators.hh --- oln/core/concept/operators.hh (revision 965) +++ oln/core/concept/operators.hh (working copy) @@ -30,86 +30,112 @@ # include <oln/core/equipment.hh> # include <oln/core/gen/traits.hh> +# include <oln/core/gen/value.hh> namespace oln { - /// Operator = (default version). - template <typename L, typename R> - bool operator=(const Any<L>& lhs, const Any<R>& rhs); - /// Operator != (default version). + // Default versions for some operators. + template <typename L, typename R> - bool operator!=(const Any<L>& lhs, const Any<R>& rhs); + bool + operator != (const Any<L>& lhs, const Any<R>& rhs); // Using "=". - /// Operator < (default version). template <typename L, typename R> - bool operator< (const Any<L>& lhs, const Any<R>& rhs); + bool + operator > (const Any<L>& lhs, const Any<R>& rhs); // Using "<". - /// Operator > (default version). template <typename L, typename R> - bool operator> (const Any<L>& lhs, const Any<R>& rhs); + bool + operator <= (const Any<L>& lhs, const Any<R>& rhs); // Using "<". - /// Operator >= (default version). template <typename L, typename R> - bool operator>=(const Any<L>& lhs, const Any<R>& rhs); + bool + operator >= (const Any<L>& lhs, const Any<R>& rhs); // Using "<=". + + template <typename T> + T + operator + (const Any<T>& lhs, const Any<T>& rhs); // Using "+=". + + template <typename T> + T + operator - (const Any<T>& lhs, const Any<T>& rhs); // Using "+=". + + template <typename T> + T + operator % (const Any<T>& lhs, const Any<T>& rhs); // Using "%=". + + + + + + // FIXME: Add: template <typename T> T operator - (const Any<T>& rhs); + + - /// Operator <= (default version). + + namespace ERROR + { + + template <typename Op> + struct operator_ + { + // unary + template <typename T> struct _is_missing_for_; + template <typename T> struct _is_invalid_for_; + // binary + template <typename L, typename R> struct _is_missing_for_types_; + template <typename L, typename R> struct _is_invalid_for_types_; + }; + + } // end of namespace oln::ERROR + + + + // Guards. + // ---------------- + + // Operator =. template <typename L, typename R> - bool operator<=(const Any<L>& lhs, const Any<R>& rhs); + void operator = (const Any<L>& lhs, const Any<R>& rhs); - /// Operator += (default version). + // Operator <. template <typename L, typename R> - L& operator+=(Any<L>& lhs, const Any<R>& rhs); + void operator < (const Any<L>& lhs, const Any<R>& rhs); - /// Operator + (default version). + // Operator -. template <typename T> - T operator+ (const Any<T>& lhs, const Any<T>& rhs); + void operator - (const Any<T>& rhs); - /// Operator %= (default version). + // Operator +=. template <typename L, typename R> - L& operator%=(Any<L>& lhs, const Any<R>& rhs); + void operator += (const Any<L>& lhs, const Any<R>& rhs); - /// Operator % (default version). - template <typename T> - T operator% (const Any<T>& lhs, const Any<T>& rhs); + // Operator -=. + template <typename L, typename R> + void operator -= (const Any<L>& lhs, const Any<R>& rhs); - /// Operator -= (default version). + // Operator %=. template <typename L, typename R> - L& operator-=(Any<L>& lhs, const Any<R>& rhs); + void operator %= (const Any<L>& lhs, const Any<R>& rhs); - /// Operator - (default version). - template <typename T> - T operator- (const Any<T>& lhs, const Any<T>& rhs); + // ---------------- + // end of Guards. - /// Operator - (default version). - template <typename T> - T operator- (const Any<T>& rhs); # ifndef OLN_INCLUDE_ONLY template <typename L, typename R> - bool operator=(const Any<L>& lhs, const Any<R>& rhs) - { - return exact(lhs).op_equal_(exact(rhs)); - } - - template <typename L, typename R> bool operator!=(const Any<L>& lhs, const Any<R>& rhs) { return not (exact(lhs) = exact(rhs)); } template <typename L, typename R> - bool operator< (const Any<L>& lhs, const Any<R>& rhs) - { - return exact(lhs).op_less_(exact(rhs)); - } - - template <typename L, typename R> bool operator> (const Any<L>& lhs, const Any<R>& rhs) { return exact(rhs) < exact(lhs); // use "operator <" @@ -127,12 +153,6 @@ return exact(rhs) <= exact(lhs); // use "operator <=" } - template <typename L, typename R> - L& operator+=(Any<L>& lhs, const Any<R>& rhs) - { - return exact(lhs).op_plus_equal_(exact(rhs)); - } - template <typename T> T operator+ (const Any<T>& lhs, const Any<T>& rhs) { @@ -147,12 +167,6 @@ return tmp -= exact(rhs); } - template <typename L, typename R> - L& operator%=(Any<L>& lhs, const Any<R>& rhs) - { - return exact(lhs).op_mod_equal_(exact(rhs)); - } - template <typename T> T operator% (const Any<T>& lhs, const Any<T>& rhs) { @@ -160,35 +174,68 @@ return tmp %= exact(rhs); } + + + // Guards. + // ---------------- + + // Operator =. template <typename L, typename R> - L& operator-=(Any<L>& lhs, const Any<R>& rhs) + void operator = (const Any<L>& lhs, const Any<R>& rhs) { - return exact(lhs).op_minus_equal_(exact(rhs)); + mlc::abort_<L, + ERROR::operator_< eq_id >::template _is_missing_for_types_<L, R> + >::check(); } - template <typename T> - T operator- (const Any<T>& rhs) + // Operator <. + template <typename L, typename R> + void operator < (const Any<L>& lhs, const Any<R>& rhs) { - return exact(rhs).op_unary_minus_(); + mlc::abort_<L, + ERROR::operator_< less_id >::template _is_missing_for_types_<L, R> + >::check(); } - /* - - FIXME: Activate? + // Operator +=. + template <typename L, typename R> + void operator += (const Any<L>& lhs, const Any<R>& rhs) + { + mlc::abort_<L, + ERROR::operator_< plus_equal_id >::template _is_missing_for_types_<L, R> + >::check(); + } + // Operator -=. template <typename L, typename R> - xtd_op_plus_trait(L, R) operator+ (const Any<L>& lhs, const Any<R>& rhs) + void operator -= (const Any<L>& lhs, const Any<R>& rhs) { - return exact(lhs).op_plus_(exact(rhs)); + mlc::abort_<L, + ERROR::operator_< minus_equal_id >::template _is_missing_for_types_<L, R> + >::check(); } + // Operator %=. template <typename L, typename R> - xtd_op_minus_trait(L, R) operator- (const Any<L>& lhs, const Any<R>& rhs) + void operator %= (const Any<L>& lhs, const Any<R>& rhs) { - return exact(lhs).op_minus_(exact(rhs)); + mlc::abort_<L, + ERROR::operator_< modulus_equal_id >::template _is_missing_for_types_<L, R> + >::check(); } - */ + // Operator -. + template <typename T> + void operator - (const Any<T>& rhs) + { + mlc::abort_<T, + ERROR::operator_< uminus_id >::template _is_missing_for_<T> + >::check(); + } + + // ---------------- + // end of Guards. + # endif // ! OLN_INCLUDE_ONLY Index: oln/value/builtin_traits.hh --- oln/value/builtin_traits.hh (revision 965) +++ oln/value/builtin_traits.hh (working copy) @@ -42,11 +42,30 @@ }; template <typename Op> + struct set_trait_< Value, int, Op, Value, double > + { + typedef double ret; + }; + + template <typename Op> struct set_trait_< Value, float, Op, Value, int > { typedef float ret; }; + + template <typename Op> + struct set_trait_< Value, bool, Op, Value, bool > + { + typedef bool ret; + }; + + template <typename Op> + struct set_utrait_< Op, Boolean, bool > + { + typedef bool ret; + }; + // FIXME: To be continued...
participants (1)
-
Thierry Geraud