Skip to content
Snippets Groups Projects
Commit 4d15693e authored by graeser's avatar graeser
Browse files

Use static assertion to ensure that a coefficient deduction

If HierarchicVectorView is not passed the coefficient type
directly, it will try to deduce it which fails for dynamically
sized multi-indices. This is e.g. the case for non flat indices
if you do not create the wrapper manually.

This problem is now captured by a static_assert. In order to see
this in the error message the default coefficient type used to indicate
that it should be deduced had to be changed from void to a named
type. Otherwise you get errors for code using the result before
even seeing the failed assertion error. Using a named type here
is a good idea anyway.
parent 2aade3f1
No related branches found
No related tags found
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