Belle II Software  release-06-00-14
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 #include <boost/optional.hpp>
11 
12 namespace Belle2 {
17  namespace TrackFindingCDC {
18 
20  template <class AFunctor>
21  struct Common {
22 
23  private:
25  AFunctor m_functor;
26 
27  public:
33  template <class Ts, class Category = decltype(m_functor(*std::declval<Ts>().begin()))>
34  boost::optional<Category> operator()(const Ts& ts) const
35  {
36  auto it = std::begin(ts);
37  auto itEnd = std::end(ts);
38  if (it == itEnd) return {}; // empty case
39  Category category = m_functor(*it);
40  for (; it != itEnd; ++it) {
41  if (category != m_functor(*it)) return {};
42  }
43  return {category};
44  }
45 
51  template<class T1, class T2, class Category = decltype(m_functor(std::declval<T1>()))>
52  boost::optional<Category> operator()(const T1& t1, const T2& t2) const
53  {
54  Category cat1 = m_functor(t1);
55  Category cat2 = m_functor(t2);
56  if (cat1 == cat2) return {cat1};
57  return {};
58  }
59  };
60  }
62 }
Abstract base class for different kinds of events.
Adapter of a category function to find the common category of several objects.
Definition: Common.h:21
boost::optional< Category > operator()(const T1 &t1, const T2 &t2) const
Returns the common category of two values.
Definition: Common.h:52
boost::optional< Category > operator()(const Ts &ts) const
Returns the common category value of a range.
Definition: Common.h:34
AFunctor m_functor
Memory for the nested functor.
Definition: Common.h:25