Skip to content
Snippets Groups Projects
Commit 8f751593 authored by graeser's avatar graeser
Browse files

Merge branch 'feature/assert-coefficient-deduction' into 'master'

Use static assertion to ensure a coefficient deduction in HierarchicVectorWrapper

See merge request staging/dune-functions!102
parents 6b1053e3 4d15693e
Branches
Tags
No related merge requests found
...@@ -57,6 +57,13 @@ namespace Imp { ...@@ -57,6 +57,13 @@ namespace Imp {
using type = typename DefaultCoefficientTypeHelper<V, getStaticSizeOrZero<MultiIndex>()>::type; using type = typename DefaultCoefficientTypeHelper<V, getStaticSizeOrZero<MultiIndex>()>::type;
}; };
// This tag class is used as Coefficient template parameter
// for HierarchicVectorWrapper if the coefficient type should
// be deduced.
struct DeducedCoefficientTag {};
} // namespace Imp } // namespace Imp
...@@ -81,11 +88,11 @@ namespace Imp { ...@@ -81,11 +88,11 @@ namespace Imp {
* \tparam V Type of the raw wrapper vector * \tparam V Type of the raw wrapper vector
* \tparam CO Coefficient type * \tparam CO Coefficient type
*/ */
template<class V, class CO=void> template<class V, class CO=Imp::DeducedCoefficientTag>
class HierarchicVectorWrapper class HierarchicVectorWrapper
{ {
template<class MultiIndex> template<class MultiIndex>
using Coefficient = typename std::conditional< std::is_same<void,CO>::value and HasStaticSize<MultiIndex>::value, using Coefficient = typename std::conditional< std::is_same<Imp::DeducedCoefficientTag,CO>::value and HasStaticSize<MultiIndex>::value,
typename Imp::CoefficientType<V, MultiIndex>::type, typename Imp::CoefficientType<V, MultiIndex>::type,
CO CO
>::type; >::type;
...@@ -178,24 +185,28 @@ public: ...@@ -178,24 +185,28 @@ public:
template<class MultiIndex> template<class MultiIndex>
const Entry<MultiIndex>& operator[](const MultiIndex& index) const const Entry<MultiIndex>& operator[](const MultiIndex& index) const
{ {
static_assert(not std::is_same<Imp::DeducedCoefficientTag,Entry<MultiIndex>>::value, "Coefficient type for HierarchicVectorWrapper and given multi-index type cannot be determined automatically!");
return hybridMultiIndexAccess<const Entry<MultiIndex>&>(*vector_, index); return hybridMultiIndexAccess<const Entry<MultiIndex>&>(*vector_, index);
} }
template<class MultiIndex> template<class MultiIndex>
Entry<MultiIndex>& operator[](const MultiIndex& index) Entry<MultiIndex>& operator[](const MultiIndex& index)
{ {
static_assert(not std::is_same<Imp::DeducedCoefficientTag,Entry<MultiIndex>>::value, "Coefficient type for HierarchicVectorWrapper and given multi-index type cannot be determined automatically!");
return hybridMultiIndexAccess<Entry<MultiIndex>&>(*vector_, index); return hybridMultiIndexAccess<Entry<MultiIndex>&>(*vector_, index);
} }
template<class MultiIndex> template<class MultiIndex>
const Entry<MultiIndex>& operator()(const MultiIndex& index) const const Entry<MultiIndex>& operator()(const MultiIndex& index) const
{ {
static_assert(not std::is_same<Imp::DeducedCoefficientTag,Entry<MultiIndex>>::value, "Coefficient type for HierarchicVectorWrapper and given multi-index type cannot be determined automatically!");
return (*this)[index]; return (*this)[index];
} }
template<class MultiIndex> template<class MultiIndex>
Entry<MultiIndex>& operator()(const MultiIndex& index) Entry<MultiIndex>& operator()(const MultiIndex& index)
{ {
static_assert(not std::is_same<Imp::DeducedCoefficientTag,Entry<MultiIndex>>::value, "Coefficient type for HierarchicVectorWrapper and given multi-index type cannot be determined automatically!");
return (*this)[index]; return (*this)[index];
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment