Disable ArrayHandleCounting for invalid value types

`ArrayHandleCounting` only works with values that support basic
arithmetic. The concept of counting makes little sense for types that
are not well defined for addition and multiplication like `bool`,
`string` and other custom types.
This commit is contained in:
Kenneth Moreland 2021-01-11 16:28:26 -07:00
parent 0b2dbfdda1
commit 66fbc99b09

@ -12,6 +12,7 @@
#include <vtkm/cont/ArrayHandleImplicit.h>
#include <vtkm/TypeTraits.h>
#include <vtkm/VecTraits.h>
namespace vtkm
@ -72,12 +73,48 @@ private:
vtkm::Id NumberOfValues;
};
namespace detail
{
template <typename T, typename UseVecTraits = vtkm::HasVecTraits<T>>
struct CanCountImpl;
template <typename T>
struct CanCountImpl<T, std::false_type>
{
using TTraits = vtkm::TypeTraits<T>;
static constexpr bool IsNumeric =
!std::is_same<typename TTraits::NumericTag, vtkm::TypeTraitsUnknownTag>::value;
static constexpr bool value = IsNumeric;
};
template <typename T>
struct CanCountImpl<T, std::true_type>
{
using VTraits = vtkm::VecTraits<T>;
using BaseType = typename VTraits::BaseComponentType;
static constexpr bool IsBool = std::is_same<BaseType, bool>::value;
static constexpr bool value = CanCountImpl<BaseType, std::false_type>::value && !IsBool;
};
} // namespace detail
// Not all types can be counted.
template <typename T>
struct CanCount
{
static constexpr bool value = detail::CanCountImpl<T>::value;
};
template <typename T>
using StorageTagCountingSuperclass =
vtkm::cont::StorageTagImplicit<internal::ArrayPortalCounting<T>>;
template <typename T>
struct Storage<T, vtkm::cont::StorageTagCounting> : Storage<T, StorageTagCountingSuperclass<T>>
struct Storage<T, typename std::enable_if<CanCount<T>::value, vtkm::cont::StorageTagCounting>::type>
: Storage<T, StorageTagCountingSuperclass<T>>
{
};