Dune Core Modules (2.8.0)

multiindex.hh
Go to the documentation of this file.
1#ifndef DUNE_GRID_UTILITY_MULTIINDEX_HH
2#define DUNE_GRID_UTILITY_MULTIINDEX_HH
3
9#include<array>
10
11namespace Dune
12{
13 namespace FactoryUtilities
14 {
15 template<std::size_t dim>
16 class MultiIndex : public std::array<unsigned int,dim>
17 {
18 // The range of each component
19 std::array<unsigned int,dim> limits_;
20
21 public:
23 MultiIndex(const std::array<unsigned int,dim>& limits) : limits_(limits)
24 {
25 std::fill(this->begin(), this->end(), 0);
26 }
27
29 MultiIndex<dim>& operator++()
30 {
31 for (std::size_t i=0; i<dim; i++)
32 {
33 // Augment digit
34 (*this)[i]++;
35
36 // If there is no carry-over we can stop here
37 if ((*this)[i]<limits_[i])
38 break;
39
40 (*this)[i] = 0;
41 }
42 return *this;
43 }
44
46 size_t cycle() const
47 {
48 size_t result = 1;
49 for (std::size_t i=0; i<dim; i++)
50 result *= limits_[i];
51 return result;
52 }
53 };
54 }
55}
56
57#endif
Dune namespace.
Definition: alignedallocator.hh:11
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 21, 23:30, 2024)