Skip to content
Snippets Groups Projects
Commit 8fc27230 authored by Carsten Gräser's avatar Carsten Gräser
Browse files

[bugfix] Use std::decay_t to make IsIntegralConstant more robust

parent 3cfe25c4
No related branches found
No related tags found
No related merge requests found
Pipeline #
......@@ -4,6 +4,7 @@
#define DUNE_SOLVERS_COMMON_ALGORITHM_HH
#include <dune/common/typeutilities.hh>
namespace Dune {
namespace Solvers {
......@@ -33,17 +34,22 @@ struct StaticForLoop<ST, end, end>
// Check if T is an integral constant
template<class T>
struct IsIntegralConstant
struct IsIntegralConstantHelper
{
static const bool value = false;
};
template<class T, T t>
struct IsIntegralConstant<std::integral_constant<T, t>>
struct IsIntegralConstantHelper<std::integral_constant<T, t>>
{
static const bool value = true;
};
// Check if T is an integral constant
template<class T>
struct IsIntegralConstant : public IsIntegralConstantHelper<std::decay_t<T>>
{};
} //end namespace Imp
......@@ -139,6 +145,14 @@ constexpr auto staticSize(const T*, const PriorityTag<2>&)
return {};
}
// Try if tuple_size is implemented for class
template<class T, int i>
constexpr auto staticSize(const Dune::FieldVector<T, i>*, const PriorityTag<3>&)
-> decltype(std::integral_constant<std::size_t,i>())
{
return {};
}
template<class T>
constexpr std::false_type hasStaticSize(const T* t, const PriorityTag<0>& p)
{
......@@ -200,7 +214,7 @@ struct StaticSize :
*/
template<class T,
std::enable_if_t<HasStaticSize<T>::value, int> = 0>
auto hybridSize(const T& t)
constexpr auto hybridSize(const T& t)
{
return Imp::staticSize((T*)(nullptr), PriorityTag<42>());
}
......@@ -221,7 +235,7 @@ auto hybridSize(const T& t)
*/
template<class T,
std::enable_if_t<not HasStaticSize<T>::value, int> = 0>
auto hybridSize(const T& t)
constexpr auto hybridSize(const T& t)
{
return t.size();
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment