Belle II Software development
Scalar.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 <type_traits>
11
12namespace Belle2 {
17 namespace TrackFindingCDC {
18
27 template<class T>
28 class Scalar {
29 public:
31 explicit Scalar(T obj)
32 : m_obj(obj)
33 {
34 }
35
37 operator T& ()& {
38 return m_obj;
39 }
40
42 operator T const& () const&
43 {
44 return m_obj;
45 }
46
48 T operator->() const
49 {
50 return m_obj;
51 }
52
54 typename std::remove_pointer<T>::type& operator*() const
55 {
56 return *m_obj;
57 }
58
60 bool operator<(const Scalar<T>& rhs) const
61 {
62 return m_obj < rhs.m_obj;
63 }
64
66 bool operator==(const Scalar<T>& rhs) const
67 {
68 return m_obj == rhs.m_obj;
69 }
70
71 private:
74 };
75
77 template<class T, bool a_isScalar = false>
80 using type = T;
81 };
82
84 template<class T>
85 struct ScalarToClassImpl<T, true> {
87 using type = Scalar<T>;
88 };
89
91 template<class T>
92 using ScalarToClass = typename ScalarToClassImpl<T, std::is_scalar<T>::value>::type;
93 }
95}
Class wrapping a scalar type (for which std::is_scalar is true).
Definition: Scalar.h:28
bool operator<(const Scalar< T > &rhs) const
Transport ordering.
Definition: Scalar.h:60
T m_obj
Memory for the underlying scalar type.
Definition: Scalar.h:73
bool operator==(const Scalar< T > &rhs) const
Transport equality.
Definition: Scalar.h:66
std::remove_pointer< T >::type & operator*() const
Dereferencing access for the case that T is a pointer.
Definition: Scalar.h:54
T operator->() const
Mimic the original item pointer access for the cast that T is a pointer.
Definition: Scalar.h:48
Scalar(T obj)
Wrap scalar type as an object.
Definition: Scalar.h:31
Abstract base class for different kinds of events.
Helper type function to replace a T with Scalar<T> when std::is_scalar<T>.
Definition: Scalar.h:78
T type
Base implementation just forwards the original type.
Definition: Scalar.h:80