Documentation of MARTY
A Modern ARtificial Theoretical phYsicist
iterable.h
Go to the documentation of this file.
1 // This file is part of MARTY.
2 //
3 // MARTY is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
7 //
8 // MARTY is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with MARTY. If not, see <https://www.gnu.org/licenses/>.
15 
23 #ifndef ITERABLE_H_INCLUDED
24 #define ITERABLE_H_INCLUDED
25 
26 #include <cstddef>
27 #include <vector>
28 #include "mrtError.h"
29 #include "mrtUtils.h"
30 
31 namespace mty {
32 
33 template<typename Value_Type, class Containor = std::vector<Value_Type>>
35 
36  typedef typename Containor::const_iterator c_iter;
37  typedef typename Containor::const_reverse_iterator c_riter;
38 
39  private:
40 
41  const Containor& iterable;
42 
43  const size_t custom_begin;
44  const size_t custom_end;
45 
46  public:
47 
48  iterable_view(const Containor& t_iterable)
49  :iterable(t_iterable),
50  custom_begin(0),
51  custom_end(t_iterable.size())
52  {
53 
54  }
55 
56  iterable_view(const Containor& t_iterable,
57  size_t b,
58  size_t e)
59  :iterable(t_iterable),
60  custom_begin(b),
61  custom_end(e)
62  {
63  if (not (0 <= b and b <= e and e <= iterable.size()))
64  CallHEPError(mty::error::TypeError,
65  "Wrong positions in construction of custom_iterable_view()."
66  + toString(b) + " and " + toString(e) + " for a containor "
67  + "of size " + toString(iterable.size()));
68  }
69 
70  bool empty() const {
71  return end() == begin();
72  }
73 
74  size_t size() const {
75  return distance(begin(), end());
76  }
77 
78  c_iter begin() const {
79  return iterable.begin() + custom_begin;
80  }
81 
82  c_iter end() const {
83  return iterable.begin() + custom_end;
84  }
85 
86  c_riter rbegin() const {
87  return iterable.rbegin() + iterable.size() - custom_end;
88  }
89 
90  c_riter rend() const {
91  return iterable.rend() - custom_begin;
92  }
93 
94  Value_Type operator[](size_t i) const {
95  return iterable[custom_begin + i];
96  }
97 };
98 
99 } // End of namespace mty
100 
101 #endif
Definition: iterable.h:34
Namespace of MARTY.
Definition: 2HDM.h:31