diff --git a/vtkm/VecFlat.h b/vtkm/VecFlat.h index 8f5101861..01d2b5028 100644 --- a/vtkm/VecFlat.h +++ b/vtkm/VecFlat.h @@ -42,6 +42,13 @@ struct TotalNumComponents static constexpr vtkm::IdComponent value = 1; }; +template +using FlattenVec = vtkm::Vec::BaseComponentType, + vtkm::internal::TotalNumComponents::value>; + +template +using IsFlatVec = typename std::is_same>::type; + namespace detail { @@ -191,15 +198,6 @@ VTKM_EXEC_CONT void CopyVecFlatToNested(const vtkm::Vec& flatVec, NestedVe } // namespace internal -namespace detail -{ - -template -using VecFlatSuperclass = vtkm::Vec::BaseComponentType, - vtkm::internal::TotalNumComponents::value>; - -} // namespace detail - /// \brief Treat a `Vec` or `Vec`-like object as a flat `Vec`. /// /// The `VecFlat` template wraps around another object that is a nested `Vec` object @@ -222,10 +220,14 @@ using VecFlatSuperclass = vtkm::Vec::BaseComponentTy /// the `IsSizeStatic` field is `vtkm::VecTraitsTagSizeStatic` (that is, the `NUM_COMPONENTS` /// constant is defined). /// +template ::value> +class VecFlat; + +// Case where T is not a vtkm::Vec where T is not a Vec. template -class VecFlat : public detail::VecFlatSuperclass +class VecFlat : public internal::FlattenVec { - using Superclass = detail::VecFlatSuperclass; + using Superclass = internal::FlattenVec; public: using Superclass::Superclass; @@ -247,6 +249,32 @@ public: } }; +// Specialization of VecFlat where the Vec is already flat Vec +template +class VecFlat : public T +{ +public: + using T::T; + VecFlat() = default; + + VTKM_EXEC_CONT VecFlat(const T& src) + : T(src) + { + } + + VTKM_EXEC_CONT VecFlat& operator=(const T& src) + { + this->T::operator=(src); + return *this; + } + + VTKM_EXEC_CONT VecFlat& operator=(T&& src) + { + this->T::operator=(std::move(src)); + return *this; + } +}; + /// \brief Converts a `Vec`-like object to a `VecFlat`. /// template @@ -256,12 +284,12 @@ VTKM_EXEC_CONT vtkm::VecFlat make_VecFlat(const T& vec) } template -struct TypeTraits> : TypeTraits> +struct TypeTraits> : TypeTraits> { }; template -struct VecTraits> : VecTraits> +struct VecTraits> : VecTraits> { };