Commit 820c74a2 authored by Praetorius, Simon's avatar Praetorius, Simon
Browse files

Fix commit after rebase

parent b8e147e3
Pipeline #6064 failed with stage
in 105 minutes and 16 seconds
......@@ -33,7 +33,6 @@ dune-git-istl-gcc:
dune-git-istl-blocked-gcc:
image: registry.dune-project.org/docker/ci/dune-pdelab-deps:git-debian-10-gcc-8-17
variables:
DUNECI_CMAKE_FLAGS: "-DBACKEND=ISTL"
DUNECI_CXXFLAGS: "-Wno-deprecated-declarations -Wno-cpp"
DUNECI_CMAKE_FLAGS: "-DBACKEND=ISTL_BLOCKED"
before_script:
......
#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 Apply;
/// \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 `Apply<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 apply(F&& f, T const& t)
{
return Apply<T>::impl(f,t);
}
// specializations for container types
/// Default implementation of the recursive \ref map function.
template <class T>
struct Apply
{
template <class F>
static auto impl(F&& f, T const& t)
{
return f(t);
}
};
template <class T, std::size_t n>
struct Apply<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::apply(f,a[ii])...}; });
}
};
template <class... TT>
struct Apply<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::apply(f,ti)...}; }, t);
}
};
template <class T1, class T2>
struct Apply<std::pair<T1,T2>>
{
template <class F>
static auto impl(F&& f, std::pair<T1,T2> const& t)
{
return std::pair{Recursive::apply(f,t.first), Recursive::apply(f,t.second)};
}
};
template <class... TT>
struct Apply<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::apply(f,ti)...); }, t);
}
};
template <class T>
struct Apply<std::vector<T>>
{
template <class F>
static auto impl(F&& f, std::vector<T> const& v)
{
using U = TYPEOF(Recursive::apply(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::apply(f,v[i]));
return out;
}
};
}} // end namespace AMDiS::Recursive
\ No newline at end of file
......@@ -101,8 +101,5 @@ namespace AMDiS
template <class T>
struct InnerProduct<MTLVector<T>> : InnerProduct<VectorBase<MTLVector<T>>> {};
template <class T>
struct InnerProduct<ISTLBlockVector<T>> : InnerProduct<VectorBase<ISTLBlockVector<T>>> {};
} // end namespace Recursive
} // end namespace AMDiS
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment