Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
dumux
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
dumux-repositories
dumux
Commits
8bcf6897
Commit
8bcf6897
authored
4 years ago
by
Timo Koch
Browse files
Options
Downloads
Patches
Plain Diff
[common] Add Python-like enumerate function for ranges
parent
d0a45437
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!2270
Feature/enumerate
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
dumux/common/CMakeLists.txt
+1
-0
1 addition, 0 deletions
dumux/common/CMakeLists.txt
dumux/common/enumerate.hh
+64
-0
64 additions, 0 deletions
dumux/common/enumerate.hh
with
65 additions
and
0 deletions
dumux/common/CMakeLists.txt
+
1
−
0
View file @
8bcf6897
...
@@ -17,6 +17,7 @@ doubleexpintegrationconstants.hh
...
@@ -17,6 +17,7 @@ doubleexpintegrationconstants.hh
doubleexpintegrator.hh
doubleexpintegrator.hh
dumuxmessage.hh
dumuxmessage.hh
entitymap.hh
entitymap.hh
enumerate.hh
exceptions.hh
exceptions.hh
fixedlengthspline_.hh
fixedlengthspline_.hh
fvproblem.hh
fvproblem.hh
...
...
This diff is collapsed.
Click to expand it.
dumux/common/enumerate.hh
0 → 100644
+
64
−
0
View file @
8bcf6897
// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
// vi: set et ts=4 sw=4 sts=4:
/*****************************************************************************
* See the file COPYING for full copying permissions. *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*****************************************************************************/
/*!
* \file
* \brief A Python-like enumerate function
*/
#ifndef DUMUX_COMMON_ENUMERATE_HH
#define DUMUX_COMMON_ENUMERATE_HH
#include
<tuple>
namespace
Dumux
{
/*!
* \brief A Python-like enumerate function
* \param iterable Some iterable type with begin/end (e.g. std::vector)
* \note From Nathan Reed (CC BY 4.0): http://reedbeta.com/blog/python-like-enumerate-in-cpp17/
*
* Usage example: for (const auto& [i, item] : enumerate(list))
*/
template
<
typename
Range
,
typename
RangeIterator
=
decltype
(
std
::
begin
(
std
::
declval
<
Range
>())),
typename
=
decltype
(
std
::
end
(
std
::
declval
<
Range
>
()))
>
constexpr
auto
enumerate
(
Range
&&
iterable
)
{
struct
Iterator
{
std
::
size_t
i
;
RangeIterator
iter
;
bool
operator
!=
(
const
Iterator
&
other
)
const
{
return
iter
!=
other
.
iter
;
}
void
operator
++
()
{
++
i
;
++
iter
;
}
auto
operator
*
()
const
{
return
std
::
tie
(
i
,
*
iter
);
}
};
struct
Iteratable
{
Range
iterable
;
auto
begin
()
{
return
Iterator
{
0
,
std
::
begin
(
iterable
)
};
}
auto
end
()
{
return
Iterator
{
0
,
std
::
end
(
iterable
)
};
}
};
return
Iteratable
{
std
::
forward
<
Range
>
(
iterable
)
};
}
}
// end namespace Dumux
#endif
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment