Cadabra
Computer algebra system for field theory problems
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
MultiIndex.hh
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include <vector>
5 
9 
10 template<class T>
11 class MultiIndex {
12  public:
13  typedef std::vector<T> values_type;
14  std::vector<values_type> values;
15 
16  void start()
17  {
18  current_pos=std::vector<std::size_t>(values.size(), 0);
19  end_=false;
20  }
21 
22  bool end() const
23  {
24  return end_;
25  }
26 
28  {
29  current_pos[0]++;
30  std::size_t ci=0;
31  while(current_pos[ci] == values[ci].size()) {
32  if(ci==current_pos.size()-1) {
33  end_=true;
34  return *this;
35  }
36  current_pos[ci++]=0;
37  current_pos[ci]++;
38  }
39  return *this;
40  }
41 
42  const T& operator[](std::size_t i)
43  {
44  return values[i][current_pos[i]];
45  }
46 
47  private:
48  std::vector<std::size_t> current_pos;
49  bool end_;
50 };
51 
52 
std::vector< std::size_t > current_pos
Definition: MultiIndex.hh:48
std::vector< values_type > values
Definition: MultiIndex.hh:14
MultiIndex & operator++()
Definition: MultiIndex.hh:27
std::vector< T > values_type
Definition: MultiIndex.hh:13
bool end() const
Definition: MultiIndex.hh:22
const T & operator[](std::size_t i)
Definition: MultiIndex.hh:42
void start()
Definition: MultiIndex.hh:16
bool end_
Definition: MultiIndex.hh:49
A class to help iterating over all values of multiple objects.
Definition: MultiIndex.hh:11