pixled-lib  1.0
arithmetic.h
1 #ifndef PIXLED_FUNCTIONNAL_ARITHMETIC_H
2 #define PIXLED_FUNCTIONNAL_ARITHMETIC_H
3 
4 #include "../function.h"
5 
6 namespace pixled {
7  namespace arithmetic {
19  template<typename R, typename P1, typename P2>
20  class Plus : public Function<Plus<R, P1, P2>, R, P1, P2> {
21 
22  public:
23  using Function<Plus<R, P1, P2>, R, P1, P2>::Function;
24 
25  R operator()(led l, time t) const override {
26  return this->template call<0>(l, t) + this->template call<1>(l, t);
27  }
28  };
29  }
30 
45  template<typename Arg1, typename Arg2,
46  typename std::enable_if<
49  >::type = true>
50  arithmetic::Plus<
51  // R
52  typename std::common_type<
53  typename std::remove_reference<Arg1>::type::Type,
54  typename std::remove_reference<Arg2>::type::Type
55  >::type,
56  // P1
57  typename std::remove_reference<Arg1>::type::Type,
58  // P2
59  typename std::remove_reference<Arg2>::type::Type
60  > operator+(Arg1&& f1, Arg2&& f2) {
61  return {std::forward<Arg1>(f1), std::forward<Arg2>(f2)};
62  }
78  template<typename Arg1, typename Arg2,
79  typename std::enable_if<
82  >::type = true>
83  arithmetic::Plus<
84  // R
85  typename std::common_type<
86  typename std::remove_reference<Arg1>::type,
87  typename std::remove_reference<Arg2>::type::Type
88  >::type,
89  // P1
90  typename std::remove_reference<Arg1>::type,
91  // P2
92  typename std::remove_reference<Arg2>::type::Type> operator+(Arg1&& c1, Arg2&& f2) {
93  return {c1, std::forward<Arg2>(f2)};
94  }
95 
111  template<typename Arg1, typename Arg2,
112  typename std::enable_if<
115  >::type = true>
116  arithmetic::Plus<
117  // R
118  typename std::common_type<
119  typename std::remove_reference<Arg1>::type::Type,
120  typename std::remove_reference<Arg2>::type
121  >::type,
122  // P1
123  typename std::remove_reference<Arg1>::type::Type,
124  // P2
125  typename std::remove_reference<Arg2>::type> operator+(Arg1&& f1, Arg2&& c2) {
126  return {std::forward<Arg1>(f1), c2};
127  }
128 
129  namespace arithmetic {
141  template<typename R, typename P1, typename P2>
142  class Minus : public Function<Minus<R, P1, P2>, R, P1, P2> {
143 
144  public:
145  using Function<Minus<R, P1, P2>, R, P1, P2>::Function;
146 
147  R operator()(led l, time t) const override {
148  return this->template call<0>(l, t) - this->template call<1>(l, t);
149  }
150  };
151  }
152 
167  template<typename Arg1, typename Arg2,
168  typename std::enable_if<
171  >::type = true>
172  arithmetic::Minus<
173  // R
174  typename std::common_type<
175  typename std::remove_reference<Arg1>::type::Type,
176  typename std::remove_reference<Arg2>::type::Type
177  >::type,
178  // P1
179  typename std::remove_reference<Arg1>::type::Type,
180  // P2
181  typename std::remove_reference<Arg2>::type::Type
182  > operator-(Arg1&& f1, Arg2&& f2) {
183  return {std::forward<Arg1>(f1), std::forward<Arg2>(f2)};
184  }
185 
201  template<typename Arg1, typename Arg2,
202  typename std::enable_if<
205  >::type = true>
206  arithmetic::Minus<
207  // R
208  typename std::common_type<
209  typename std::remove_reference<Arg1>::type,
210  typename std::remove_reference<Arg2>::type::Type
211  >::type,
212  // P1
213  typename std::remove_reference<Arg1>::type,
214  // P2
215  typename std::remove_reference<Arg2>::type::Type> operator-(Arg1&& c1, Arg2&& f2) {
216  return {c1, std::forward<Arg2>(f2)};
217  }
218 
234  template<typename Arg1, typename Arg2,
235  typename std::enable_if<
238  >::type = true>
239  arithmetic::Minus<
240  // R
241  typename std::common_type<
242  typename std::remove_reference<Arg1>::type::Type,
243  typename std::remove_reference<Arg2>::type
244  >::type,
245  // P1
246  typename std::remove_reference<Arg1>::type::Type,
247  // P2
248  typename std::remove_reference<Arg2>::type> operator-(Arg1&& f1, Arg2&& c2) {
249  return {std::forward<Arg1>(f1), c2};
250  }
251 
252  namespace arithmetic {
264  template<typename R, typename P1, typename P2>
265  class Multiplies : public Function<Multiplies<R, P1, P2>, R, P1, P2> {
266  public:
268 
269  R operator()(led l, time t) const override {
270  return this->template call<0>(l, t) * this->template call<1>(l, t);
271  }
272  };
273  }
274 
289  template<typename Arg1, typename Arg2,
290  typename std::enable_if<
293  >::type = true>
294  arithmetic::Multiplies<
295  // R
296  typename std::common_type<
297  typename std::remove_reference<Arg1>::type::Type,
298  typename std::remove_reference<Arg2>::type::Type
299  >::type,
300  // P1
301  typename std::remove_reference<Arg1>::type::Type,
302  // P2
303  typename std::remove_reference<Arg2>::type::Type
304  > operator*(Arg1&& f1, Arg2&& f2) {
305  return {std::forward<Arg1>(f1), std::forward<Arg2>(f2)};
306  }
322  template<typename Arg1, typename Arg2,
323  typename std::enable_if<
326  >::type = true>
327  arithmetic::Multiplies<
328  // R
329  typename std::common_type<
330  typename std::remove_reference<Arg1>::type,
331  typename std::remove_reference<Arg2>::type::Type
332  >::type,
333  // P1
334  typename std::remove_reference<Arg1>::type,
335  // P2
336  typename std::remove_reference<Arg2>::type::Type
337  > operator*(Arg1&& c1, Arg2&& f2) {
338  return {c1, std::forward<Arg2>(f2)};
339  }
340 
356  template<typename Arg1, typename Arg2,
357  typename std::enable_if<
360  >::type = true>
361  arithmetic::Multiplies<
362  // R
363  typename std::common_type<
364  typename std::remove_reference<Arg1>::type::Type,
365  typename std::remove_reference<Arg2>::type
366  >::type,
367  // P1
368  typename std::remove_reference<Arg1>::type::Type,
369  // P2
370  typename std::remove_reference<Arg2>::type> operator*(Arg1&& f1, Arg2&& c2) {
371  return {std::forward<Arg1>(f1), c2};
372  }
373 
374  namespace arithmetic {
390  template<typename R, typename P1, typename P2>
391  class Divides : public Function<Divides<R, P1, P2>, R, P1, P2> {
392  public:
393  using Function<Divides<R, P1, P2>, R, P1, P2>::Function;
394 
395  R operator()(led l, time t) const override {
396  return this->template call<0>(l, t) / this->template call<1>(l, t);
397  }
398  };
399  }
400 
415  template<typename Arg1, typename Arg2,
416  typename std::enable_if<
419  >::type = true>
420  arithmetic::Divides<
421  // R
422  typename std::common_type<
423  typename std::remove_reference<Arg1>::type::Type,
424  typename std::remove_reference<Arg2>::type::Type
425  >::type,
426  // P1
427  typename std::remove_reference<Arg1>::type::Type,
428  // P2
429  typename std::remove_reference<Arg2>::type::Type
430  > operator/(Arg1&& f1, Arg2&& f2) {
431  return {std::forward<Arg1>(f1), std::forward<Arg2>(f2)};
432  }
448  template<typename Arg1, typename Arg2,
449  typename std::enable_if<
452  >::type = true>
453  arithmetic::Divides<
454  // R
455  typename std::common_type<
456  typename std::remove_reference<Arg1>::type,
457  typename std::remove_reference<Arg2>::type::Type
458  >::type,
459  // P1
460  typename std::remove_reference<Arg1>::type,
461  // P2
462  typename std::remove_reference<Arg2>::type::Type
463  > operator/(Arg1&& c1, Arg2&& f2) {
464  return {c1, std::forward<Arg2>(f2)};
465  }
481  template<typename Arg1, typename Arg2,
482  typename std::enable_if<
485  >::type = true>
486  arithmetic::Divides<
487  // R
488  typename std::common_type<
489  typename std::remove_reference<Arg1>::type::Type,
490  typename std::remove_reference<Arg2>::type
491  >::type,
492  // P1
493  typename std::remove_reference<Arg1>::type::Type,
494  // P2
495  typename std::remove_reference<Arg2>::type
496  > operator/(Arg1&& f1, Arg2&& c2) {
497  return {std::forward<Arg1>(f1), c2};
498  }
499 
500  namespace arithmetic {
512  template<typename R, typename P1, typename P2>
513  class Modulus : public Function<Modulus<R, P1, P2>, R, P1, P2> {
514  public:
515  using Function<Modulus<R, P1, P2>, R, P1, P2>::Function;
516 
517  R operator()(led l, time t) const override {
518  return this->template call<0>(l, t) % this->template call<1>(l, t);
519  }
520  };
521  }
537  template<typename Arg1, typename Arg2,
538  typename std::enable_if<
541  >::type = true>
542  arithmetic::Modulus<
543  // R
544  typename std::common_type<
545  typename std::remove_reference<Arg1>::type::Type,
546  typename std::remove_reference<Arg2>::type::Type
547  >::type,
548  // P1
549  typename std::remove_reference<Arg1>::type::Type,
550  // P2
551  typename std::remove_reference<Arg2>::type::Type
552  > operator%(Arg1&& f1, Arg2&& f2) {
553  return {std::forward<Arg1>(f1), std::forward<Arg2>(f2)};
554  }
570  template<typename Arg1, typename Arg2,
571  typename std::enable_if<
574  >::type = true>
575  arithmetic::Modulus<
576  // R
577  typename std::common_type<
578  typename std::remove_reference<Arg1>::type,
579  typename std::remove_reference<Arg2>::type::Type
580  >::type,
581  // P1
582  typename std::remove_reference<Arg1>::type,
583  // P2
584  typename std::remove_reference<Arg2>::type::Type
585  > operator%(Arg1&& c1, Arg2&& f2) {
586  return {c1, std::forward<Arg2>(f2)};
587  }
603  template<typename Arg1, typename Arg2,
604  typename std::enable_if<
607  >::type = true>
608  arithmetic::Modulus<
609  // R
610  typename std::common_type<
611  typename std::remove_reference<Arg1>::type::Type,
612  typename std::remove_reference<Arg2>::type
613  >::type,
614  // P1
615  typename std::remove_reference<Arg1>::type::Type,
616  // P2
617  typename std::remove_reference<Arg2>::type
618  > operator%(Arg1&& f1, Arg2&& c2) {
619  return {std::forward<Arg1>(f1), c2};
620  }
621 }
622 #endif
Definition: function.h:349
Function(Fcts &&... fcts)
Definition: function.h:383
Definition: arithmetic.h:391
R operator()(led l, time t) const override
Definition: arithmetic.h:395
Definition: arithmetic.h:142
R operator()(led l, time t) const override
Definition: arithmetic.h:147
Definition: arithmetic.h:513
R operator()(led l, time t) const override
Definition: arithmetic.h:517
Definition: arithmetic.h:265
R operator()(led l, time t) const override
Definition: arithmetic.h:269
Definition: arithmetic.h:20
R operator()(led l, time t) const override
Definition: arithmetic.h:25
Definition: animation.cpp:3
arithmetic::Minus< typename std::common_type< typename std::remove_reference< Arg1 >::type::Type, typename std::remove_reference< Arg2 >::type::Type >::type, typename std::remove_reference< Arg1 >::type::Type, typename std::remove_reference< Arg2 >::type::Type > operator-(Arg1 &&f1, Arg2 &&f2)
Definition: arithmetic.h:182
arithmetic::Multiplies< typename std::common_type< typename std::remove_reference< Arg1 >::type::Type, typename std::remove_reference< Arg2 >::type::Type >::type, typename std::remove_reference< Arg1 >::type::Type, typename std::remove_reference< Arg2 >::type::Type > operator*(Arg1 &&f1, Arg2 &&f2)
Definition: arithmetic.h:304
arithmetic::Modulus< typename std::common_type< typename std::remove_reference< Arg1 >::type::Type, typename std::remove_reference< Arg2 >::type::Type >::type, typename std::remove_reference< Arg1 >::type::Type, typename std::remove_reference< Arg2 >::type::Type > operator%(Arg1 &&f1, Arg2 &&f2)
Definition: arithmetic.h:552
arithmetic::Plus< typename std::common_type< typename std::remove_reference< Arg1 >::type::Type, typename std::remove_reference< Arg2 >::type::Type >::type, typename std::remove_reference< Arg1 >::type::Type, typename std::remove_reference< Arg2 >::type::Type > operator+(Arg1 &&f1, Arg2 &&f2)
Definition: arithmetic.h:60
unsigned long time
Definition: time.h:10
arithmetic::Divides< typename std::common_type< typename std::remove_reference< Arg1 >::type::Type, typename std::remove_reference< Arg2 >::type::Type >::type, typename std::remove_reference< Arg1 >::type::Type, typename std::remove_reference< Arg2 >::type::Type > operator/(Arg1 &&f1, Arg2 &&f2)
Definition: arithmetic.h:430
static constexpr bool value
Definition: function.h:82
Definition: mapping.h:19