Belle II Software  release-05-02-19
SortedRange.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 <tracking/trackFindingCDC/utilities/Range.h>
13 
14 #include <algorithm>
15 #include <iterator>
16 #include <utility>
17 
18 namespace Belle2 {
23  namespace TrackFindingCDC {
24 
26  template<class AIterator>
27  class SortedRange : public Range<AIterator> {
28 
29  private:
31  using Super = Range<AIterator>;
32 
33  public:
35  using Iterator = AIterator;
36 
38  using Reference = typename std::iterator_traits<AIterator>::reference;
39 
40  public:
42  template<class AOtherIterator>
43  explicit SortedRange(const std::pair<AOtherIterator, AOtherIterator>& itPair)
44  : Super(AIterator(itPair.first), AIterator(itPair.second))
45  {}
46 
48  template<class Ts, class ItT = GetIterator<Ts>>
49  explicit SortedRange(const Ts& ts)
50  : Super(AIterator(std::begin(ts)), AIterator(std::end(ts)))
51  {}
52 
54  using Super::Super;
55 
57  template<class T>
58  SortedRange<AIterator> equal_range(const T& t) const
59  { return SortedRange<AIterator>(std::equal_range(this->begin(), this->end(), t)); }
60 
62  template<class T>
63  SortedRange<AIterator> upper_bound(const T& t) const
64  { return SortedRange<AIterator>(std::upper_bound(this->begin(), this->end(), t)); }
65 
67  template<class T>
68  SortedRange<AIterator> lowers_bound(const T& t) const
69  { return SortedRange<AIterator>(std::lower_bound(this->begin(), this->end(), t)); }
70 
72  bool count(Reference t) const
73  {
74  Range<AIterator> relevant_range = this->equal_range(t);
75  return relevant_range.count(t);
76  }
77 
78  };
79  }
81 }
Belle2::TrackFindingCDC::Range::begin
Iterator begin() const
Begin of the range for range based for.
Definition: Range.h:74
Belle2::TrackFindingCDC::SortedRange::Reference
typename std::iterator_traits< AIterator >::reference Reference
The type the iterator references.
Definition: SortedRange.h:46
Belle2::TrackFindingCDC::Range::Reference
typename std::iterator_traits< AIterator >::reference Reference
The type the iterator references.
Definition: Range.h:49
Belle2::TrackFindingCDC::Range::end
Iterator end() const
End of the range for range based for.
Definition: Range.h:78
Belle2::TrackFindingCDC::SortedRange::lowers_bound
SortedRange< AIterator > lowers_bound(const T &t) const
Access to a lower bound to mimic the behaviour of a sorted container.
Definition: SortedRange.h:76
Belle2::TrackFindingCDC::SortedRange::upper_bound
SortedRange< AIterator > upper_bound(const T &t) const
Access to a upper bound to mimic the behaviour of a sorted container.
Definition: SortedRange.h:71
Belle2::TrackFindingCDC::SortedRange::equal_range
SortedRange< AIterator > equal_range(const T &t) const
Access to a sub range to mimic the behaviour of a sorted container.
Definition: SortedRange.h:66
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::TrackFindingCDC::Range::Iterator
AIterator Iterator
Iterator type of the range.
Definition: Range.h:43
Belle2::TrackFindingCDC::SortedRange::Super
Range< AIterator > Super
Type of the base class.
Definition: SortedRange.h:39
Belle2::TrackFindingCDC::Range::Super
std::pair< AIterator, AIterator > Super
Type of the base class.
Definition: Range.h:39
Belle2::TrackFindingCDC::SortedRange::SortedRange
SortedRange(const std::pair< AOtherIterator, AOtherIterator > &itPair)
Constructor to adapt a pair as returned by e.g. std::equal_range.
Definition: SortedRange.h:51
Belle2::TrackFindingCDC::SortedRange::count
bool count(Reference t) const
Counts the number of equivalent items in the range.
Definition: SortedRange.h:80
Belle2::TrackFindingCDC::SortedRange
A pair of iterators usable with the range base for loop.
Definition: SortedRange.h:35