Belle II Software  release-05-02-19
DiscreteValue.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 <array>
13 #include <vector>
14 #include <iostream>
15 
16 namespace Belle2 {
21  namespace TrackFindingCDC {
22 
24  template<class T, class ATag = T>
25  class DiscreteValue : public std::vector<T>::const_iterator {
26 
27  private:
29  using Super = typename std::vector<T>::const_iterator;
30 
32  using This = DiscreteValue<T, ATag>;
33 
34  public:
36  using Super::Super;
37 
39  DiscreteValue() = default;
40 
42  explicit DiscreteValue(const Super& iter) : Super(iter) {}
43 
46  explicit DiscreteValue(T& value) : Super(&value) {}
47 
49  explicit operator const T& () const
50  { return **this; }
51 
53  friend std::ostream& operator<<(std::ostream& output, const This& discreteValue)
54  { return output << *discreteValue; }
55 
57  using Array = std::vector<T>;
58 
60  static
61  std::array<This, 2> getRange(Array& values)
62  { return {{ This(values.front()), This(values.back()) }}; }
63  };
64 
65  }
67 }
Belle2::TrackFindingCDC::DiscreteValue::Super
typename std::vector< T >::const_iterator Super
Type of the base class.
Definition: DiscreteValue.h:37
Belle2::TrackFindingCDC::DiscreteValue::This
DiscreteValue< T, ATag > This
Type of this class.
Definition: DiscreteValue.h:40
Belle2::TrackFindingCDC::DiscreteValue::getRange
static std::array< This, 2 > getRange(Array &values)
Extract the range from an array providing the discrete values.
Definition: DiscreteValue.h:69
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::TrackFindingCDC::DiscreteValue::DiscreteValue
DiscreteValue()=default
Default constructor for to obtain a valid object in all contexts.
Belle2::TrackFindingCDC::DiscreteValue::operator<<
friend std::ostream & operator<<(std::ostream &output, const This &discreteValue)
Output operator for debugging.
Definition: DiscreteValue.h:61
Belle2::TrackFindingCDC::DiscreteValue::Array
std::vector< T > Array
The type of the array which contains the underlying values.
Definition: DiscreteValue.h:65