Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dune-common
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
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
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
Core Modules
dune-common
Commits
c125f8fd
Commit
c125f8fd
authored
1 year ago
by
Simon Praetorius
Browse files
Options
Downloads
Patches
Plain Diff
Constrain the default constructor of IndexedIterator and add constexpr to members
parent
90baaddf
No related branches found
No related tags found
1 merge request
!1366
Add mixin class for an indexed iterator
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
dune/common/indexediterator.hh
+19
-11
19 additions, 11 deletions
dune/common/indexediterator.hh
with
19 additions
and
11 deletions
dune/common/indexediterator.hh
+
19
−
11
View file @
c125f8fd
...
...
@@ -21,35 +21,43 @@ namespace Dune
* or decremented. Especially the dereference and comparison operators are not
* modified by this mixin class.
*
* \tparam Iter An iterator type the `IndexedIterator` will
inherit from
.
* \tparam Iter An iterator type
from which
the `IndexedIterator` will
be derived
.
*/
template
<
class
Iter
>
template
<
class
Iter
>
class
IndexedIterator
:
public
Iter
{
using
Traits
=
std
::
iterator_traits
<
Iter
>
;
static_assert
(
std
::
is_copy_constructible_v
<
Iter
>
);
static_assert
(
std
::
is_base_of_v
<
std
::
forward_iterator_tag
,
typename
Traits
::
iterator_category
>
);
public:
//! Type used for storing the traversal index
using
size_type
=
typename
Traits
::
difference_type
;
//! Default constructor default-constructs the `Iter` base type and the index by 0.
IndexedIterator
()
=
default
;
template
<
class
I
=
Iter
,
std
::
enable_if_t
<
std
::
is_default_constructible_v
<
I
>,
bool
>
=
true
>
constexpr
IndexedIterator
()
noexcept
(
std
::
is_nothrow_default_constructible_v
<
Iter
>
)
{}
//! Construct the `Iter` base type by `it` and the index by the given starting index.
IndexedIterator
(
Iter
it
,
size_type
index
=
0
)
//! Note that this constructor allows implicit conversion from `Iter` type.
constexpr
IndexedIterator
(
Iter
it
,
size_type
index
=
0
)
noexcept
(
std
::
is_nothrow_copy_constructible_v
<
Iter
>
)
:
Iter
(
it
)
,
index_
(
index
)
{}
//! Return the enumeration index.
size_type
index
()
const
[[
nodiscard
]]
constexpr
size_type
index
()
const
noexcept
{
return
index_
;
}
//! Increment the iterator and the index.
IndexedIterator
&
operator
++
()
constexpr
IndexedIterator
&
operator
++
()
{
Iter
::
operator
++
();
++
index_
;
...
...
@@ -57,7 +65,7 @@ namespace Dune
}
//! Increment the iterator and the index.
IndexedIterator
operator
++
(
int
)
constexpr
IndexedIterator
operator
++
(
int
)
{
IndexedIterator
tmp
(
*
this
);
this
->
operator
++
();
...
...
@@ -67,7 +75,7 @@ namespace Dune
//! Decrement the iterator and the index.
template
<
class
I
=
Iter
,
decltype
(
--
std
::
declval
<
I
&
>(),
bool
{})
=
true
>
IndexedIterator
&
operator
--
()
constexpr
IndexedIterator
&
operator
--
()
{
Iter
::
operator
--
();
--
index_
;
...
...
@@ -77,7 +85,7 @@ namespace Dune
//! Decrement the iterator and the index.
template
<
class
I
=
Iter
,
decltype
(
std
::
declval
<
I
&
>()
--
,
bool
{})
=
true
>
IndexedIterator
operator
--
(
int
)
constexpr
IndexedIterator
operator
--
(
int
)
{
IndexedIterator
tmp
(
*
this
);
this
->
operator
--
();
...
...
@@ -87,7 +95,7 @@ namespace Dune
//! Increment the iterator and the index.
template
<
class
I
=
Iter
,
decltype
(
std
::
declval
<
I
&
>()
+=
1
,
bool
{})
=
true
>
IndexedIterator
&
operator
+=
(
typename
Iter
::
difference_type
n
)
constexpr
IndexedIterator
&
operator
+=
(
typename
Iter
::
difference_type
n
)
{
Iter
::
operator
+=
(
n
);
index_
+=
n
;
...
...
@@ -97,7 +105,7 @@ namespace Dune
//! Decrement the iterator and the index.
template
<
class
I
=
Iter
,
decltype
(
std
::
declval
<
I
&
>()
-=
1
,
bool
{})
=
true
>
IndexedIterator
&
operator
-=
(
typename
Iter
::
difference_type
n
)
constexpr
IndexedIterator
&
operator
-=
(
typename
Iter
::
difference_type
n
)
{
Iter
::
operator
-=
(
n
);
index_
-=
n
;
...
...
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