Cadabra
Computer algebra system for field theory problems
Loading...
Searching...
No Matches
MultiIndex.hh
Go to the documentation of this file.
1
2#pragma once
3
4#include <vector>
5
9
10template<class T>
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
A class to help iterating over all values of multiple objects.
Definition MultiIndex.hh:11
std::vector< std::size_t > current_pos
Definition MultiIndex.hh:48
std::vector< values_type > values
Definition MultiIndex.hh:14
std::vector< T > values_type
Definition MultiIndex.hh:13
const T & operator[](std::size_t i)
Definition MultiIndex.hh:42
bool end() const
Definition MultiIndex.hh:22
void start()
Definition MultiIndex.hh:16
MultiIndex & operator++()
Definition MultiIndex.hh:27
bool end_
Definition MultiIndex.hh:49