 |
Belle II Software
release-05-02-19
|
12 #include <tracking/trackFindingCDC/utilities/FunctorTag.h>
14 #include <type_traits>
24 namespace TrackFindingCDC {
29 operator FunctorTag();
35 return std::forward<T>(t);
68 template<class T, class SFINAE = std::enable_if_t<not isFunctor<T>()> >
75 template<class AFunctor, class SFINAE = std::enable_if_t<isFunctor<AFunctor>()> >
76 constexpr
const AFunctor & toFunctor(
const AFunctor& get)
83 using ToFunctor =
typename std::decay<decltype(toFunctor(std::declval<T>()))>::type;
88 template <
class AFunctor1,
class AFunctor2>
91 operator FunctorTag();
104 Composition(
const AFunctor1& functor1,
const AFunctor2& functor2)
128 template <
class ABinaryOp,
class AFunctor1,
class AFunctor2 = AFunctor1>
138 BinaryJoin(
const ABinaryOp& binaryOp,
const AFunctor1& functor1,
const AFunctor2& functor2)
147 BinaryJoin(
const AFunctor1& functor1,
const AFunctor2& functor2)
166 template <
class T1,
class T2>
181 template <
class AFunctor1,
class AFunctor2>
200 Alternation(
const AFunctor1& functor1,
const AFunctor2& functor2 = AFunctor2())
208 template <
class... T>
209 auto impl(
int favouredTag __attribute__((unused)), T&& ... t)
const
210 -> decltype(
m_functor1(std::forward<T>(t)...))
216 template <
class... T>
217 auto impl(
long disfavouredTag __attribute__((unused)), T&& ... t)
const
218 -> decltype(
m_functor2(std::forward<T>(t)...))
225 template <
class... T>
226 auto operator()(T&& ... t)
const -> decltype(this->
impl(0, std::forward<T>(t)...))
229 return impl(dispatchTag, std::forward<T>(t)...);
243 void operator()(T&& t __attribute__((unused)))
const
249 template <
class AFunctor = Id>
250 using VoidOf = Composition<Void, AFunctor>;
253 template <
class AFunctor>
257 template<
class AFunction,
class... T>
258 void invokeIfApplicable(AFunction&&
function, T&& ... t)
261 invokeIfApplicableImpl(std::forward<T>(t)...);
265 template<
class ADefault,
class AFunctor,
class T>
266 ADefault getIfApplicable(AFunctor&&
function, T&& obj, ADefault value)
269 return getIfApplicableImpl(std::forward<T>(obj));
279 operator FunctorTag();
283 auto operator()(
const T& t)
const -> decltype(std::get<I>(t))
291 template <
int I,
class AFunctor = Id>
302 template<
class AFunctor = Id>
313 template<
class AFunctor = Id>
326 auto operator()(
const T& t)
const -> decltype(t.size())
333 template <
class AFunctor = Id>
346 auto operator()(T& t)
const -> decltype(t.clear())
353 template <
class AFunctor = Id>
371 auto operator()(
const T& t)
const -> decltype(not t)
378 template <
class AFunctor = Id>
382 template <class AFunctor, class SFINAE = std::enable_if_t<isFunctor<AFunctor>()> >
398 auto operator()(
const T& t)
const -> decltype(*t)
405 auto operator()(
const T* t)
const -> decltype(*t)
407 assert(t !=
nullptr);
413 template <
class AFunctor = Id>
417 template <
class AFunctor = Id>
429 auto operator()(
const T& t)
const -> decltype(*(t.operator->()))
431 assert(t.operator->() !=
nullptr);
432 return *(t.operator->());
439 assert(t !=
nullptr);
445 template <
class AFunctor = Id>
449 template <
class AFunctor = Id>
456 template <
class AFunctor>
468 template<
class T1,
class T2>
469 auto operator()(
const T1& t1,
const T2& t2)
const -> decltype(t1 < t2)
476 template <
class AFunctor1 = Id,
class AFunctor2 = AFunctor1>
480 template <class ALHS, class ARHS, class SFINAE = std::enable_if_t<isFunctor<ALHS>() or isFunctor<ARHS>()>>
481 LessOf<ToFunctor<ALHS>, ToFunctor<ARHS> > operator<(const ALHS& lhs, const ARHS& rhs)
483 return {toFunctor(lhs), toFunctor(rhs)};
496 template<
class T1,
class T2>
497 auto operator()(
const T1& t1,
const T2& t2)
const -> decltype(t1 > t2)
504 template <
class AFunctor1 = Id,
class AFunctor2 = AFunctor1>
508 template <class ALHS, class ARHS, class SFINAE = std::enable_if_t<isFunctor<ALHS>() or isFunctor<ARHS>()>>
509 GreaterOf<ToFunctor<ALHS>, ToFunctor<ARHS> > operator>(const ALHS& lhs, const ARHS& rhs)
511 return {toFunctor(lhs), toFunctor(rhs)};
522 template<
class T1,
class T2>
523 auto operator()(
const T1& t1,
const T2& t2)
const -> decltype(t1 == t2)
530 template <
class AFunctor1 = Id,
class AFunctor2 = AFunctor1>
534 template <class ALHS, class ARHS, class SFINAE = std::enable_if_t<isFunctor<ALHS>() or isFunctor<ARHS>()>>
535 EqualOf<ToFunctor<ALHS>, ToFunctor<ARHS> > operator==(const ALHS& lhs, const ARHS& rhs)
537 return {toFunctor(lhs), toFunctor(rhs)};
549 return std::isnan(t);
AFunctor2 m_functor2
Memory for the nested functor.
ABinaryOp m_binaryOp
Memory for the binary operation.
auto operator()(const T &t) const -> decltype(m_functor1(m_functor2(t)))
Operator getting the result of the function composition.
Functor factory turning a binary functor and two functors into a new functor which executes the binar...
Composition()=default
Allow default construction.
AFunctor1 m_functor1
Memory for the nested functor.
void operator()(T &&t __attribute__((unused))) const
Operator always returning void.
Binary functor for equality comparision of abitrary objects - equivalent to std::equal_to<> (c++14)
Alternation()=default
Allow default construction.
Generic functor to try to functors and choose the first to be applicable.
Functor to get the I part (as of std::get<I>) from an abitrary objects.
auto operator()(const T &t) const -> decltype(not t)
Operator getting the logical negation of an abitrary object.
BinaryJoin()=default
Allow default construction.
AFunctor1 m_functor1
Memory for the first nested functor.
AFunctor2 m_functor2
Memory for the second nested functor.
auto operator()(T &&... t) const -> decltype(this->impl(0, std::forward< T >(t)...))
Operator to dispatch to the two functors and returns the first applicable option.
auto operator()(const T1 &t1, const T2 &t2) const -> decltype(m_binaryOp(m_functor1(t1), m_functor2(t2)))
Operator getting the result of the binary operation from two objects transformed by the two functors.
AFunctor1 m_functor1
Memory for the first nested functor.
T && operator()(T &&t) const
Operator that just returns the object itself - gets me.
auto impl(int favouredTag __attribute__((unused)), T &&... t) const -> decltype(m_functor1(std::forward< T >(t)...))
Implementation applying the first functor. Favoured option.
Generic functor to wrap a constant as a function.
Abstract base class for different kinds of events.
Functor to get the .size() from an abitrary objects.
T m_t
Memory for the constant to be returned.
Tag class to facilitate marking of class as a functor in the sense of this code.
auto operator()(T &t) const -> decltype(t.clear())
Operator getting the .clear() of an abitrary object.
auto operator()(const T1 &t1, const T2 &t2) const -> decltype(t1==t2)
Operator for equality comparision of an abitrary object.
auto operator()(const T &t) const -> decltype(*(t.operator->()))
Operator getting the indirection of an abitrary object.
Functor returning void from an abitrary objects.
Filter< OperatorNot, Filter< types... >, VoidObserver > operator!(const Filter< types... > &filter)
Definition of the NOT operator ! for the Filter class.
auto operator()(const T &t) const -> decltype(std::get< I >(t))
Operator getting the I part (as of std::get<I>) of an abitrary object.
auto operator()(const T &t) const -> decltype(t.size())
Operator getting the .size() of an abitrary object.
Functor to get the referenced object from an abitrary objects.
auto operator()(const T1 &t1, const T2 &t2) const -> decltype(t1 > t2)
Operator for greater comparision of an abitrary object.
auto operator()(const T &t) const -> decltype(*t)
Operator getting the referenced object of an abitrary object.
Binary functor for greater comparision of abitrary objects - equivalent to std::greater<> (c++14)
auto operator()(const T1 &t1, const T2 &t2) const -> decltype(t1< t2)
Operator for less comparision of an abitrary object.
AFunctor2 m_functor2
Memory for the second nested functor.
Functor factory from the functional composition of two functors.
constexpr const T & operator()(const S &) const
Operator returning the constant.
Binary functor for less comparision of abitrary objects - equivalent to std::less<> (c++14)
Functor to get the logical negation from an abitrary objects.
Functor to get the .clear() from an abitrary objects.
bool operator()(const T &t) const
Operator for equality comparision to NaN.
Unary functor for equality comparison to NAN.
Functor to get the indirection from an abitrary objects.