27 #ifndef MLN_CORE_ROUTINE_OPS_HH
28 # define MLN_CORE_ROUTINE_OPS_HH
92 # include <mln/trait/op/all.hh>
93 # include <mln/core/concept/object.hh>
94 # include <mln/metal/converts_to.hh>
101 namespace literal {
struct zero_t;
struct one_t; }
111 template <
typename O>
112 struct set_unary_< op::uplus, Object,O > {
typedef O ret; };
115 template <
typename O>
116 struct set_unary_< op::uminus, Object,O > {
typedef mln_trait_op_minus(O, O) ret; };
119 template <typename O>
120 struct set_unary_< op::preinc, Object,O > {
typedef O& ret; };
123 template <
typename O>
124 struct set_unary_< op::predec, Object,O > {
typedef O& ret; };
127 template <
typename O>
128 struct set_unary_< op::postinc, Object,O > {
typedef O ret; };
131 template <
typename O>
132 struct set_unary_< op::postdec, Object,O > {
typedef O ret; };
138 template <
typename O1,
typename O2>
139 struct set_binary_< op::eq, Object,O1, Object,O2 > {
typedef bool ret; };
141 template <
typename O1,
typename O2>
142 struct set_binary_< op::neq, Object,O1, Object,O2 >
145 typedef mln_trait_op_eq(O1, O2) B_;
146 typedef mln_trait_op_not(B_) ret;
149 template <typename O1, typename O2>
150 struct set_binary_< op::less, Object,O1, Object,O2 > {
typedef bool ret; };
152 template <
typename O1,
typename O2>
153 struct set_binary_< op::leq, Object,O1, Object,O2 >
156 typedef mln_trait_op_less(O2, O1) B_;
157 typedef mln_trait_op_not(B_) ret;
160 template <typename O1, typename O2>
161 struct set_binary_< op::geq, Object,O1, Object,O2 >
164 typedef mln_trait_op_leq(O2, O1) ret;
167 template <typename O1, typename O2>
168 struct set_binary_< op::greater, Object,O1, Object,O2 >
171 typedef mln_trait_op_less(O2, O1) ret;
180 template< template <class> class Name,
182 struct set_precise_unary_< Name, const O >
184 typedef mln_trait_unary(Name, O) ret;
187 template< template <class,class> class Name,
188 typename O1, typename O2 >
189 struct set_precise_binary_< Name, O1, const O2 >
191 typedef mln_trait_binary(Name, O1, O2) ret;
194 template< template <class,class> class Name,
195 typename O1, typename O2 >
196 struct set_precise_binary_< Name, const O1, O2 >
198 typedef mln_trait_binary(Name, O1, O2) ret;
201 template< template <class,class> class Name,
202 typename O1, typename O2 >
203 struct set_precise_binary_< Name, const O1, const O2 >
205 typedef mln_trait_binary(Name, O1, O2) ret;
222 template <typename O1, typename O2>
224 operator!=(const Object<O1>& lhs, const Object<O2>& rhs);
236 template <typename O1, typename O2>
237 mln_trait_op_greater(O1, O2)
238 operator>(const Object<O1>& lhs, const Object<O2>& rhs);
251 template <typename O1, typename O2>
252 mln_trait_op_geq(O1, O2)
253 operator>=(const Object<O1>& lhs, const Object<O2>& rhs);
266 template <typename O1, typename O2>
267 mln_trait_op_leq(O1, O2)
268 operator<=(const Object<O1>& lhs, const Object<O2>& rhs);
275 template <typename O>
276 O operator++(Object<O>& lhs,
int);
283 template <typename O>
284 O operator--(Object<O>& lhs,
int);
291 template <typename O>
292 O& operator++(Object<O>& rhs);
299 template <typename O>
300 O& operator--(Object<O>& rhs);
308 template <typename O>
309 O operator+(const Object<O>& rhs);
319 template <typename O>
320 mln_trait_op_minus(O, O)
321 operator-(const Object<O>& rhs);
332 template <typename L, typename R>
334 operator+=(Object<L>& lhs, const Object<R>& rhs);
345 template <typename L, typename R>
347 operator-=(Object<L>& lhs, const Object<R>& rhs);
358 template <typename L, typename R>
360 operator*=(Object<L>& lhs, const Object<R>& rhs);
371 template <typename L, typename R>
373 operator/=(Object<L>& lhs, const Object<R>& rhs);
384 template <typename L, typename R>
386 operator%=(Object<L>& lhs, const Object<R>& rhs);
390 # ifndef MLN_INCLUDE_ONLY
394 template <
typename L,
typename R>
397 operator+=(Object<L>& lhs,
const Object<R>& rhs)
399 typedef mln_trait_op_plus(L, R) P;
400 mlc_converts_to(P, L)::check();
401 return exact(lhs) = static_cast<L>(exact(lhs) + exact(rhs));
406 template <typename L, typename R>
409 operator-=(Object<L>& lhs, const Object<R>& rhs)
411 typedef mln_trait_op_minus(L, R) M;
412 mlc_converts_to(M, L)::check();
413 return exact(lhs) = static_cast<L>(exact(lhs) - exact(rhs));
418 template <typename L, typename R>
421 operator*=(Object<L>& lhs, const Object<R>& rhs)
423 typedef mln_trait_op_times(L, R) T;
424 mlc_converts_to(T, L)::check();
425 return exact(lhs) = static_cast<L>(exact(lhs) * exact(rhs));
430 template <typename L, typename R>
433 operator/=(Object<L>& lhs, const Object<R>& rhs)
435 typedef mln_trait_op_div(L, R) D;
436 mlc_converts_to(D, L)::check();
442 return exact(lhs) = static_cast<L>(exact(lhs) / exact(rhs));
447 template <typename L, typename R>
450 operator%=(Object<L>& lhs, const Object<R>& rhs)
452 typedef mln_trait_op_mod(L, R) M;
453 mlc_converts_to(M, L)::check();
454 return exact(lhs) = static_cast<L>(exact(lhs) % exact(rhs));
459 template <typename O>
462 operator+(const Object<O>& rhs)
469 template <
typename O>
471 mln_trait_op_minus(O, O)
472 operator-(const Object<O>& rhs)
474 mlc_converts_to(literal::zero_t, O)::check();
475 literal::zero_t* p_zero = 0;
476 return O(*p_zero) - exact(rhs);
481 template <
typename O>
484 operator++(Object<O>& lhs,
int)
494 template <
typename O>
497 operator--(Object<O>& lhs,
int)
507 template <
typename O>
510 operator--(Object<O>& rhs)
512 literal::one_t* p_one;
513 exact(rhs) -= *p_one;
519 template <
typename O>
522 operator++(Object<O>& rhs)
524 literal::one_t* p_one;
525 exact(rhs) += *p_one;
531 template <
typename O1,
typename O2>
534 operator!=(const Object<O1>& lhs, const Object<O2>& rhs)
536 return ! (exact(lhs) == exact(rhs));
539 template <
typename O1,
typename O2>
541 mln_trait_op_greater(O1, O2)
542 operator>(const Object<O1>& lhs, const Object<O2>& rhs)
544 return exact(rhs) < exact(lhs);
547 template <
typename O1,
typename O2>
549 mln_trait_op_geq(O1, O2)
550 operator>=(const Object<O1>& lhs, const Object<O2>& rhs)
552 return exact(rhs) <= exact(lhs);
555 template <
typename O1,
typename O2>
557 mln_trait_op_leq(O1, O2)
558 operator<=(const Object<O1>& lhs, const Object<O2>& rhs)
561 return ! (exact(rhs) < exact(lhs));
564 # endif // ! MLN_INCLUDE_ONLY
569 #endif // ! MLN_CORE_ROUTINE_OPS_HH