mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-08 13:23:51 +00:00
Merge topic 'variant-no-ref'
878a5e5ae Disallow references in Variant Acked-by: Kitware Robot <kwrobot@kitware.com> Acked-by: Li-Ta Lo <ollie@lanl.gov> Merge-request: !2428
This commit is contained in:
commit
58bd890c9c
@ -55,6 +55,19 @@ struct VariantDestroyFunctor
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct VariantCheckType
|
||||
{
|
||||
// We are currently not allowing reference types (e.g. FooType&) or pointer types (e.g. FooType*)
|
||||
// in Variant objects. References and pointers can fail badly when things are passed around
|
||||
// devices. If you get a compiler error here, consider removing the reference or using something
|
||||
// like std::decay to remove qualifiers on the type. (We may decide to do that automatically in
|
||||
// the future.)
|
||||
VTKM_STATIC_ASSERT_MSG(!std::is_reference<T>::value,
|
||||
"References are not allowed in VTK-m Variant.");
|
||||
VTKM_STATIC_ASSERT_MSG(!std::is_pointer<T>::value, "Pointers are not allowed in VTK-m Variant.");
|
||||
};
|
||||
|
||||
template <typename... Ts>
|
||||
struct AllTriviallyCopyable;
|
||||
|
||||
@ -306,6 +319,9 @@ class Variant : detail::VariantConstructorImpl<Variant<Ts...>>
|
||||
{
|
||||
using Superclass = detail::VariantConstructorImpl<Variant<Ts...>>;
|
||||
|
||||
// Type not used, but has the compiler check all the types for validity.
|
||||
using CheckTypes = vtkm::List<detail::VariantCheckType<Ts>...>;
|
||||
|
||||
public:
|
||||
/// Returns the index of the type of object this variant is storing. If no object is currently
|
||||
/// stored (i.e. the `Variant` is invalid), an invalid is returned.
|
||||
|
Loading…
Reference in New Issue
Block a user