Belle II Software  release-05-02-19
Common.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2016 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Oliver Frost *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 #pragma once
11 
12 #include <boost/optional.hpp>
13 
14 namespace Belle2 {
19  namespace TrackFindingCDC {
20 
22  template <class AFunctor>
23  struct Common {
24 
25  private:
27  AFunctor m_functor;
28 
29  public:
35  template <class Ts, class Category = decltype(m_functor(*std::declval<Ts>().begin()))>
36  boost::optional<Category> operator()(const Ts& ts) const
37  {
38  auto it = std::begin(ts);
39  auto itEnd = std::end(ts);
40  if (it == itEnd) return {}; // empty case
41  Category category = m_functor(*it);
42  for (; it != itEnd; ++it) {
43  if (category != m_functor(*it)) return {};
44  }
45  return {category};
46  }
47 
53  template<class T1, class T2, class Category = decltype(m_functor(std::declval<T1>()))>
54  boost::optional<Category> operator()(const T1& t1, const T2& t2) const
55  {
56  Category cat1 = m_functor(t1);
57  Category cat2 = m_functor(t2);
58  if (cat1 == cat2) return {cat1};
59  return {};
60  }
61  };
62  }
64 }
Belle2::TrackFindingCDC::Common::operator()
boost::optional< Category > operator()(const Ts &ts) const
Returns the common category value of a range.
Definition: Common.h:44
Belle2::TrackFindingCDC::Common::m_functor
AFunctor m_functor
Memory for the nested functor.
Definition: Common.h:35
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19