Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
amdis-core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
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
amdis
amdis-core
Merge requests
!255
Move all recursive algorithms to algorithm subdirectory
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Move all recursive algorithms to algorithm subdirectory
feature/algorithms
into
master
Overview
0
Commits
4
Changes
2
Merged
Praetorius, Simon
requested to merge
feature/algorithms
into
master
4 years ago
Overview
0
Commits
4
Changes
2
Expand
0
0
Merge request reports
Viewing commit
7aa4106a
Prev
Next
Show latest version
2 files
+
104
−
1
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
2
Search (e.g. *.vue) (Ctrl+P)
7aa4106a
Readd missing Map algorithm
· 7aa4106a
Praetorius, Simon
authored
4 years ago
amdis/algorithm/Map.hpp
0 → 100644
+
103
−
0
Options
#pragma once
#include
<array>
#include
<tuple>
#include
<vector>
#include
<dune/common/tuplevector.hh>
#include
<amdis/common/Apply.hpp>
namespace
AMDiS
{
namespace
Recursive
{
template
<
class
T
>
struct
Map
;
/// \brief Recursive application of a transformation functor `f` to a hierarchic
/// container of containers, returning the transformed container.
/**
* This utility function applies the given functor `f` to the "leaf" entries in
* a hierarchic container that returns a transformed container. Therefore, the
* container is traversed recursively, using specializations of the `Map<Container>::impl`
* class method. If no specialization is provided, the function is applied to the
* whole container or leaf entry, respectively.
**/
template
<
class
F
,
class
T
>
auto
map
(
F
&&
f
,
T
const
&
t
)
{
return
Map
<
T
>::
impl
(
f
,
t
);
}
// specializations for container types
/// Default implementation of the recursive \ref map function.
template
<
class
T
>
struct
Map
{
template
<
class
F
>
static
auto
impl
(
F
&&
f
,
T
const
&
t
)
{
return
f
(
t
);
}
};
template
<
class
T
,
std
::
size_t
n
>
struct
Map
<
std
::
array
<
T
,
n
>>
{
template
<
class
F
>
static
auto
impl
(
F
&&
f
,
std
::
array
<
T
,
n
>
const
&
a
)
{
return
Ranges
::
applyIndices
<
n
>
([
&
](
auto
...
ii
)
{
return
std
::
array
{
Recursive
::
map
(
f
,
a
[
ii
])...};
});
}
};
template
<
class
...
TT
>
struct
Map
<
std
::
tuple
<
TT
...
>>
{
template
<
class
F
>
static
auto
impl
(
F
&&
f
,
std
::
tuple
<
TT
...
>
const
&
t
)
{
return
Ranges
::
apply
([
&
](
auto
const
&
...
ti
)
{
return
std
::
tuple
{
Recursive
::
map
(
f
,
ti
)...};
},
t
);
}
};
template
<
class
T1
,
class
T2
>
struct
Map
<
std
::
pair
<
T1
,
T2
>>
{
template
<
class
F
>
static
auto
impl
(
F
&&
f
,
std
::
pair
<
T1
,
T2
>
const
&
t
)
{
return
std
::
pair
{
Recursive
::
map
(
f
,
t
.
first
),
Recursive
::
map
(
f
,
t
.
second
)};
}
};
template
<
class
...
TT
>
struct
Map
<
Dune
::
TupleVector
<
TT
...
>>
{
template
<
class
F
>
static
auto
impl
(
F
&&
f
,
Dune
::
TupleVector
<
TT
...
>
const
&
t
)
{
return
Ranges
::
apply
([
&
](
auto
const
&
...
ti
)
{
return
Dune
::
makeTupleVector
(
Recursive
::
map
(
f
,
ti
)...);
},
t
);
}
};
template
<
class
T
>
struct
Map
<
std
::
vector
<
T
>>
{
template
<
class
F
>
static
auto
impl
(
F
&&
f
,
std
::
vector
<
T
>
const
&
v
)
{
using
U
=
TYPEOF
(
Recursive
::
map
(
f
,
std
::
declval
<
T
>
()));
std
::
vector
<
U
>
out
;
out
.
reserve
(
v
.
size
());
for
(
std
::
size_t
i
=
0
;
i
<
v
.
size
();
++
i
)
out
.
emplace_back
(
Recursive
::
map
(
f
,
v
[
i
]));
return
out
;
}
};
}}
// end namespace AMDiS::Recursive
Loading