DUNE PDELab (git)

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