5#ifndef DUNE_FUNCTIONS_BACKENDS_CONTAINERFACTORY_HH
6#define DUNE_FUNCTIONS_BACKENDS_CONTAINERFACTORY_HH
14#include <dune/common/indices.hh>
17#include <dune/functions/functionspacebases/containerdescriptors.hh>
19namespace Dune::Functions {
20namespace ContainerDescriptors {
24struct ContainerFactory
26 void operator() (
const Unknown& descriptor,
const T& defaultValue)
const
31 template<
class... ChildDescriptor>
32 auto operator() (
const Tuple<ChildDescriptor...>& descriptor,
const T& defaultValue)
const
35 return Dune::TupleVector<
decltype((*this)(descriptor[ii], defaultValue))...>{(*this)(descriptor[ii], defaultValue)...};
36 }, std::make_index_sequence<
sizeof...(ChildDescriptor)>());
39 template<
class ChildDescriptor, std::
size_t n>
40 auto operator() (
const Array<ChildDescriptor,n>& descriptor,
const T& defaultValue)
const
42 using ChildContainer =
decltype((*this)(descriptor[0], defaultValue));
44 return std::array<ChildContainer, n>{(*this)(descriptor[ii], defaultValue)...};
45 }, std::make_index_sequence<n>());
48 template<
class ChildDescriptor>
49 auto operator() (
const Vector<ChildDescriptor>& descriptor,
const T& defaultValue)
const
51 using ChildContainer =
decltype((*this)(descriptor[0], defaultValue));
52 auto result = std::vector<ChildContainer>();
53 result.reserve(descriptor.size());
54 for (std::size_t i = 0; i < descriptor.size(); ++i)
55 result.emplace_back((*
this)(descriptor[i], defaultValue));
59 template<
class ChildDescriptor, std::
size_t n>
60 auto operator() (
const UniformArray<ChildDescriptor,n>& descriptor,
const T& defaultValue)
const
62 using ChildContainer =
decltype((*this)(descriptor[0], defaultValue));
63 auto childContainer = (*this)(descriptor[0], defaultValue);
65 return std::array<ChildContainer, n>{((void)(ii),childContainer)...};
66 }, std::make_index_sequence<n>());
69 template<
class ChildDescriptor>
70 auto operator() (
const UniformVector<ChildDescriptor>& descriptor,
const T& defaultValue)
const
72 using ChildContainer =
decltype((*this)(descriptor[0], defaultValue));
73 auto childContainer = (*this)(descriptor[0], defaultValue);
74 return std::vector<ChildContainer>(descriptor.size(), childContainer);
79 auto operator() (
const Value& descriptor,
const T& defaultValue)
const
81 return T(defaultValue);
101template<
class T,
class ContainerDescriptor>
102auto makeContainer (
const ContainerDescriptor& descriptor,
const T& defaultValue)
104 auto factory = ContainerDescriptors::Impl::ContainerFactory<T>{};
105 return factory(descriptor, defaultValue);
118template<
class T,
class ContainerDescriptor>
119auto makeContainer (
const ContainerDescriptor& descriptor)
121 return makeContainer<T>(descriptor, T());
Default exception for dummy implementations.
Definition: exceptions.hh:357
A class augmenting std::tuple by element access via operator[].
Definition: tuplevector.hh:35
A few common exception classes.
Implements a vector constructed from a given type representing a field and a compile-time given size.
decltype(auto) constexpr unpackIntegerSequence(F &&f, std::integer_sequence< I, i... > sequence)
Unpack an std::integer_sequence<I,i...> to std::integral_constant<I,i>...
Definition: indices.hh:124
#define DUNE_THROW(E,...)
Definition: exceptions.hh:314
Provides the TupleVector class that augments std::tuple by operator[].