Belle II Software  release-08-01-10
Common.h
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 #pragma once
9 
10 namespace Belle2 {
15  namespace TrackFindingCDC {
16 
18  template <class AFunctor>
19  struct Common {
20 
21  private:
23  AFunctor m_functor;
24 
25  public:
31  template <class Ts, class Category = decltype(m_functor(*std::declval<Ts>().begin()))>
32  std::optional<Category> operator()(const Ts& ts) const
33  {
34  auto it = std::begin(ts);
35  auto itEnd = std::end(ts);
36  if (it == itEnd) return {}; // empty case
37  Category category = m_functor(*it);
38  for (; it != itEnd; ++it) {
39  if (category != m_functor(*it)) return {};
40  }
41  return {category};
42  }
43 
49  template<class T1, class T2, class Category = decltype(m_functor(std::declval<T1>()))>
50  std::optional<Category> operator()(const T1& t1, const T2& t2) const
51  {
52  Category cat1 = m_functor(t1);
53  Category cat2 = m_functor(t2);
54  if (cat1 == cat2) return {cat1};
55  return {};
56  }
57  };
58  }
60 }
Abstract base class for different kinds of events.
Adapter of a category function to find the common category of several objects.
Definition: Common.h:19
std::optional< Category > operator()(const T1 &t1, const T2 &t2) const
Returns the common category of two values.
Definition: Common.h:50
std::optional< Category > operator()(const Ts &ts) const
Returns the common category value of a range.
Definition: Common.h:32
AFunctor m_functor
Memory for the nested functor.
Definition: Common.h:23