Belle II Software  release-05-01-25
Scalar.h
1 /**************************************************************************
2 * BASF2 (Belle Analysis Framework 2) *
3 * Copyright(C) 2015 - 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 <type_traits>
13 
14 namespace Belle2 {
19  namespace TrackFindingCDC {
20 
29  template<class T>
30  class Scalar {
31  public:
33  explicit Scalar(T obj)
34  : m_obj(obj)
35  {
36  }
37 
39  operator T& ()& {
40  return m_obj;
41  }
42 
44  operator T const& () const&
45  {
46  return m_obj;
47  }
48 
50  T operator->() const
51  {
52  return m_obj;
53  }
54 
56  typename std::remove_pointer<T>::type& operator*() const
57  {
58  return *m_obj;
59  }
60 
62  bool operator<(const Scalar<T>& rhs) const
63  {
64  return m_obj < rhs.m_obj;
65  }
66 
68  bool operator==(const Scalar<T>& rhs) const
69  {
70  return m_obj == rhs.m_obj;
71  }
72 
73  private:
75  T m_obj;
76  };
77 
79  template<class T, bool a_isScalar = false>
80  struct ScalarToClassImpl {
82  using type = T;
83  };
84 
86  template<class T>
87  struct ScalarToClassImpl<T, true> {
89  using type = Scalar<T>;
90  };
91 
93  template<class T>
94  using ScalarToClass = typename ScalarToClassImpl<T, std::is_scalar<T>::value>::type;
95  }
97 }
Belle2::TrackFindingCDC::Scalar::operator<
bool operator<(const Scalar< T > &rhs) const
Transport ordering.
Definition: Scalar.h:70
Belle2::TrackFindingCDC::Scalar::operator->
T operator->() const
Mimic the original item pointer access for the cast that T is a pointer.
Definition: Scalar.h:58
Belle2::TrackFindingCDC::ScalarToClassImpl::type
T type
Base implementation just forwards the original type.
Definition: Scalar.h:90
Belle2::TrackFindingCDC::Scalar::m_obj
T m_obj
Memory for the underlying scalar type.
Definition: Scalar.h:83
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::TrackFindingCDC::ScalarToClassImpl
Helper type function to replace a T with Scalar<T> when std::is_scalar<T>.
Definition: Scalar.h:88
Belle2::TrackFindingCDC::Scalar::Scalar
Scalar(T obj)
Wrap scalar type as an object.
Definition: Scalar.h:41
Belle2::TrackFindingCDC::Scalar::operator==
bool operator==(const Scalar< T > &rhs) const
Transport equality.
Definition: Scalar.h:76
Belle2::TrackFindingCDC::Scalar
Class wrapping a scalar type (for which std::is_scalar is true).
Definition: Scalar.h:38
Belle2::TrackFindingCDC::Scalar::operator*
std::remove_pointer< T >::type & operator*() const
Dereferencing access for the case that T is a pointer.
Definition: Scalar.h:64