Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
amdis
amdis-core
Commits
7aa4106a
Commit
7aa4106a
authored
Dec 22, 2020
by
Praetorius, Simon
Browse files
Readd missing Map algorithm
parent
d5e52d52
Changes
2
Hide whitespace changes
Inline
Side-by-side
amdis/Operator.hpp
View file @
7aa4106a
...
...
@@ -124,7 +124,7 @@ auto makeOperator(Op op, GV const& gridView)
template
<
class
Container
>
auto
localOperators
(
Container
const
&
c
)
{
return
Recursive
::
ap
ply
([](
auto
const
&
op
)
{
return
localOperator
(
op
);
},
c
);
return
Recursive
::
m
ap
([](
auto
const
&
op
)
{
return
localOperator
(
op
);
},
c
);
}
...
...
amdis/algorithm/Map.hpp
0 → 100644
View file @
7aa4106a
#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
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment