pixled-lib  1.0
conditional.h
1 #ifndef PIXLED_FUNCTIONNAL_COMPARISONS_H
2 #define PIXLED_FUNCTIONNAL_COMPARISONS_H
3 
4 #include "../function.h"
5 #include <type_traits>
6 
7 namespace pixled {
8  namespace conditional {
32  template<typename T>
33  class If : public Function<If<T>, T, bool, T, T> {
34  public:
35  using Function<If<T>, T, bool, T, T>::Function;
36 
37  T operator()(led l, time t) const override {
38  if(this->template call<0>(l, t))
39  return this->template call<1>(l, t);
40  else
41  return this->template call<2>(l, t);
42  }
43  };
44 
55  template<typename P1, typename P2>
56  class Equal : public Function<Equal<P1, P2>, bool, P1, P2> {
57  public:
58  using Function<Equal<P1, P2>, bool, P1, P2>::Function;
59 
60  bool operator()(led l, time t) const override {
61  return this->template call<0>(l, t) == this->template call<1>(l, t);
62  };
63  };
64  }
65 
79  template<typename Arg1, typename Arg2,
80  typename std::enable_if<
83  , bool>::type = true>
84  conditional::Equal<
85  // P1
86  typename std::remove_reference<Arg1>::type::Type,
87  // P2
88  typename std::remove_reference<Arg2>::type::Type
89  > operator==(Arg1&& f1, Arg2&& f2) {
90  return {std::forward<Arg1>(f1), std::forward<Arg2>(f2)};
91  }
92 
107  template<typename Arg1, typename Arg2,
108  typename std::enable_if<
111  , bool>::type = true>
112  conditional::Equal<
113  // P1
114  typename std::remove_reference<Arg1>::type::Type,
115  // P2
116  typename std::remove_reference<Arg2>::type
117  > operator==(Arg1&& f1, Arg2&& c2) {
118  return {std::forward<Arg1>(f1), std::forward<Arg2>(c2)};
119  }
120 
135  template<typename Arg1, typename Arg2,
136  typename std::enable_if<
139  , bool>::type = true>
140  conditional::Equal<
141  // P1
142  typename std::remove_reference<Arg1>::type,
143  // P2
144  typename std::remove_reference<Arg2>::type::Type
145  > operator==(Arg1&& c1, Arg2&& f2) {
146  return {std::forward<Arg1>(c1), std::forward<Arg2>(f2)};
147  }
148 
149  namespace conditional {
160  template<typename P1, typename P2>
161  class NotEqual : public Function<NotEqual<P1, P2>, bool, P1, P2> {
162  public:
163  using Function<NotEqual<P1, P2>, bool, P1, P2>::Function;
164 
165  bool operator()(led l, time t) const override {
166  return this->template call<0>(l, t) != this->template call<1>(l, t);
167  };
168  };
169  }
170 
184  template<typename Arg1, typename Arg2,
185  typename std::enable_if<
188  , bool>::type = true>
189  conditional::NotEqual<
190  // P1
191  typename std::remove_reference<Arg1>::type::Type,
192  // P2
193  typename std::remove_reference<Arg2>::type::Type
194  > operator!=(Arg1&& f1, Arg2&& f2) {
195  return {std::forward<Arg1>(f1), std::forward<Arg2>(f2)};
196  }
197 
212  template<typename Arg1, typename Arg2,
213  typename std::enable_if<
216  , bool>::type = true>
217  conditional::NotEqual<
218  // P1
219  typename std::remove_reference<Arg1>::type::Type,
220  // P2
221  typename std::remove_reference<Arg2>::type
222  > operator!=(Arg1&& f1, Arg2&& c2) {
223  return {std::forward<Arg1>(f1), std::forward<Arg2>(c2)};
224  }
225 
240  template<typename Arg1, typename Arg2,
241  typename std::enable_if<
244  , bool>::type = true>
245  conditional::NotEqual<
246  // P1
247  typename std::remove_reference<Arg1>::type,
248  // P2
249  typename std::remove_reference<Arg2>::type::Type
250  > operator!=(Arg1&& c1, Arg2&& f2) {
251  return {std::forward<Arg1>(c1), std::forward<Arg2>(f2)};
252  }
253 
254  namespace conditional {
265  template<typename P1, typename P2>
266  class LessThan : public Function<LessThan<P1, P2>, bool, P1, P2> {
267  public:
268  using Function<LessThan<P1, P2>, bool, P1, P2>::Function;
269 
270  bool operator()(led l, time t) const override {
271  return this->template call<0>(l, t) < this->template call<1>(l, t);
272  };
273  };
274  }
275 
289  template<typename Arg1, typename Arg2,
290  typename std::enable_if<
293  , bool>::type = true>
294  conditional::LessThan<
295  // P1
296  typename std::remove_reference<Arg1>::type::Type,
297  // P2
298  typename std::remove_reference<Arg2>::type::Type
299  > operator<(Arg1&& f1, Arg2&& f2) {
300  return {std::forward<Arg1>(f1), std::forward<Arg2>(f2)};
301  }
302 
317  template<typename Arg1, typename Arg2,
318  typename std::enable_if<
321  , bool>::type = true>
322  conditional::LessThan<
323  // P1
324  typename std::remove_reference<Arg1>::type::Type,
325  // P2
326  typename std::remove_reference<Arg2>::type
327  > operator<(Arg1&& f1, Arg2&& c2) {
328  return {std::forward<Arg1>(f1), std::forward<Arg2>(c2)};
329  }
330 
345  template<typename Arg1, typename Arg2,
346  typename std::enable_if<
349  , bool>::type = true>
350  conditional::LessThan<
351  // P1
352  typename std::remove_reference<Arg1>::type,
353  // P2
354  typename std::remove_reference<Arg2>::type::Type
355  > operator<(Arg1&& c1, Arg2&& f2) {
356  return {std::forward<Arg1>(c1), std::forward<Arg2>(f2)};
357  }
358 
359  namespace conditional {
370  template<typename P1, typename P2>
371  class LessThanOrEqual : public Function<LessThanOrEqual<P1, P2>, bool, P1, P2> {
372  public:
373  using Function<LessThanOrEqual<P1, P2>, bool, P1, P2>::Function;
374 
375  bool operator()(led l, time t) const override {
376  return this->template call<0>(l, t) <= this->template call<1>(l, t);
377  };
378  };
379  }
380 
394  template<typename Arg1, typename Arg2,
395  typename std::enable_if<
398  , bool>::type = true>
399  conditional::LessThanOrEqual<
400  // P1
401  typename std::remove_reference<Arg1>::type::Type,
402  // P2
403  typename std::remove_reference<Arg2>::type::Type
404  > operator<=(Arg1&& f1, Arg2&& f2) {
405  return {std::forward<Arg1>(f1), std::forward<Arg2>(f2)};
406  }
407 
422  template<typename Arg1, typename Arg2,
423  typename std::enable_if<
426  , bool>::type = true>
427  conditional::LessThanOrEqual<
428  // P1
429  typename std::remove_reference<Arg1>::type::Type,
430  // P2
431  typename std::remove_reference<Arg2>::type
432  > operator<=(Arg1&& f1, Arg2&& c2) {
433  return {std::forward<Arg1>(f1), std::forward<Arg2>(c2)};
434  }
435 
450  template<typename Arg1, typename Arg2,
451  typename std::enable_if<
454  , bool>::type = true>
455  conditional::LessThanOrEqual<
456  // P1
457  typename std::remove_reference<Arg1>::type,
458  // P2
459  typename std::remove_reference<Arg2>::type::Type
460  > operator<=(Arg1&& c1, Arg2&& f2) {
461  return {std::forward<Arg1>(c1), std::forward<Arg2>(f2)};
462  }
463 
464  namespace conditional {
475  template<typename P1, typename P2>
476  class GreaterThan : public Function<GreaterThan<P1, P2>, bool, P1, P2> {
477  public:
478  using Function<GreaterThan<P1, P2>, bool, P1, P2>::Function;
479 
480  bool operator()(led l, time t) const override {
481  return this->template call<0>(l, t) > this->template call<1>(l, t);
482  };
483  };
484  }
485 
499  template<typename Arg1, typename Arg2,
500  typename std::enable_if<
503  , bool>::type = true>
504  conditional::GreaterThan<
505  // P1
506  typename std::remove_reference<Arg1>::type::Type,
507  // P2
508  typename std::remove_reference<Arg2>::type::Type
509  > operator>(Arg1&& f1, Arg2&& f2) {
510  return {std::forward<Arg1>(f1), std::forward<Arg2>(f2)};
511  }
512 
527  template<typename Arg1, typename Arg2,
528  typename std::enable_if<
531  , bool>::type = true>
532  conditional::GreaterThan<
533  // P1
534  typename std::remove_reference<Arg1>::type::Type,
535  // P2
536  typename std::remove_reference<Arg2>::type
537  > operator>(Arg1&& f1, Arg2&& c2) {
538  return {std::forward<Arg1>(f1), std::forward<Arg2>(c2)};
539  }
540 
555  template<typename Arg1, typename Arg2,
556  typename std::enable_if<
559  , bool>::type = true>
560  conditional::GreaterThan<
561  // P1
562  typename std::remove_reference<Arg1>::type,
563  // P2
564  typename std::remove_reference<Arg2>::type::Type
565  > operator>(Arg1&& c1, Arg2&& f2) {
566  return {std::forward<Arg1>(c1), std::forward<Arg2>(f2)};
567  }
568 
569  namespace conditional {
580  template<typename P1, typename P2>
581  class GreaterThanOrEqual : public Function<GreaterThanOrEqual<P1, P2>, bool, P1, P2> {
582  public:
584 
585  bool operator()(led l, time t) const override {
586  return this->template call<0>(l, t) >= this->template call<1>(l, t);
587  };
588  };
589  }
590 
604  template<typename Arg1, typename Arg2,
605  typename std::enable_if<
608  , bool>::type = true>
609  conditional::GreaterThanOrEqual<
610  // P1
611  typename std::remove_reference<Arg1>::type::Type,
612  // P2
613  typename std::remove_reference<Arg2>::type::Type
614  > operator>=(Arg1&& f1, Arg2&& f2) {
615  return {std::forward<Arg1>(f1), std::forward<Arg2>(f2)};
616  }
617 
632  template<typename Arg1, typename Arg2,
633  typename std::enable_if<
636  , bool>::type = true>
637  conditional::GreaterThanOrEqual<
638  // P1
639  typename std::remove_reference<Arg1>::type::Type,
640  // P2
641  typename std::remove_reference<Arg2>::type
642  > operator>=(Arg1&& f1, Arg2&& c2) {
643  return {std::forward<Arg1>(f1), std::forward<Arg2>(c2)};
644  }
645 
660  template<typename Arg1, typename Arg2,
661  typename std::enable_if<
664  , bool>::type = true>
665  conditional::GreaterThanOrEqual<
666  // P1
667  typename std::remove_reference<Arg1>::type,
668  // P2
669  typename std::remove_reference<Arg2>::type::Type
670  > operator>=(Arg1&& c1, Arg2&& f2) {
671  return {std::forward<Arg1>(c1), std::forward<Arg2>(f2)};
672  }
673 
674 }
675 #endif
Definition: function.h:349
Function(Fcts &&... fcts)
Definition: function.h:383
Definition: chrono.h:14
Definition: conditional.h:56
bool operator()(led l, time t) const override
Definition: conditional.h:60
Definition: conditional.h:581
bool operator()(led l, time t) const override
Definition: conditional.h:585
Definition: conditional.h:476
bool operator()(led l, time t) const override
Definition: conditional.h:480
Definition: conditional.h:33
T operator()(led l, time t) const override
Definition: conditional.h:37
Definition: conditional.h:371
bool operator()(led l, time t) const override
Definition: conditional.h:375
Definition: conditional.h:266
bool operator()(led l, time t) const override
Definition: conditional.h:270
Definition: conditional.h:161
bool operator()(led l, time t) const override
Definition: conditional.h:165
Definition: animation.cpp:3
conditional::LessThan< typename std::remove_reference< Arg1 >::type::Type, typename std::remove_reference< Arg2 >::type::Type > operator<(Arg1 &&f1, Arg2 &&f2)
Definition: conditional.h:299
conditional::GreaterThanOrEqual< typename std::remove_reference< Arg1 >::type::Type, typename std::remove_reference< Arg2 >::type::Type > operator>=(Arg1 &&f1, Arg2 &&f2)
Definition: conditional.h:614
conditional::LessThanOrEqual< typename std::remove_reference< Arg1 >::type::Type, typename std::remove_reference< Arg2 >::type::Type > operator<=(Arg1 &&f1, Arg2 &&f2)
Definition: conditional.h:404
conditional::NotEqual< typename std::remove_reference< Arg1 >::type::Type, typename std::remove_reference< Arg2 >::type::Type > operator!=(Arg1 &&f1, Arg2 &&f2)
Definition: conditional.h:194
unsigned long time
Definition: time.h:10
conditional::GreaterThan< typename std::remove_reference< Arg1 >::type::Type, typename std::remove_reference< Arg2 >::type::Type > operator>(Arg1 &&f1, Arg2 &&f2)
Definition: conditional.h:509
bool operator==(const color &c1, const color &c2)
Definition: color.cpp:181
static constexpr bool value
Definition: function.h:82
Definition: mapping.h:19