Commit 4e9b4c37 authored by Robert Maynard's avatar Robert Maynard

Verify more core vtkm types have proper move semantics.

parent ee6917a5
......@@ -36,11 +36,6 @@ namespace vtkm
template <typename MaskType>
struct Bitset
{
VTKM_EXEC_CONT Bitset()
: Mask(0)
{
}
VTKM_EXEC_CONT void set(vtkm::Id bitIndex)
{
this->Mask = this->Mask | (static_cast<MaskType>(1) << bitIndex);
......@@ -62,7 +57,7 @@ struct Bitset
}
private:
MaskType Mask;
MaskType Mask = 0;
};
} // namespace vtkm
......
......@@ -74,7 +74,9 @@ struct Pair
}
VTKM_EXEC_CONT
Pair(FirstType&& firstSrc, SecondType&& secondSrc)
Pair(FirstType&& firstSrc,
SecondType&& secondSrc) noexcept(noexcept(FirstType{ std::declval<FirstType&&>() },
SecondType{ std::declval<SecondType&&>() }))
: first(std::move(firstSrc))
, second(std::move(secondSrc))
{
......@@ -91,7 +93,8 @@ struct Pair
}
template <typename U1, typename U2>
VTKM_EXEC_CONT Pair(vtkm::Pair<U1, U2>&& src)
VTKM_EXEC_CONT Pair(vtkm::Pair<U1, U2>&& src) noexcept(noexcept(U1{ std::declval<U1&&>() },
U2{ std::declval<U2&&>() }))
: first(std::move(src.first))
, second(std::move(src.second))
{
......@@ -105,7 +108,8 @@ struct Pair
}
template <typename U1, typename U2>
VTKM_EXEC_CONT Pair(std::pair<U1, U2>&& src)
VTKM_EXEC_CONT Pair(std::pair<U1, U2>&& src) noexcept(noexcept(U1{ std::declval<U1&&>() },
U2{ std::declval<U2&&>() }))
: first(std::move(src.first))
, second(std::move(src.second))
{
......
......@@ -50,6 +50,7 @@ struct Range
}
Range(const Range&) = default;
Range(Range&&) = default;
template <typename T1, typename T2>
VTKM_EXEC_CONT Range(const T1& min, const T2& max)
......@@ -59,6 +60,7 @@ struct Range
}
vtkm::Range& operator=(const vtkm::Range& src) = default;
vtkm::Range& operator=(vtkm::Range&& src) = default;
/// \b Determine if the range is valid (i.e. has at least one valid point).
///
......
......@@ -26,6 +26,11 @@
#include <vtkm/cont/DataSet.h>
#include <vtkm/cont/Field.h>
#include <vtkm/Bitset.h>
#include <vtkm/Bounds.h>
#include <vtkm/Pair.h>
#include <vtkm/Range.h>
#include <vtkm/TypeListTag.h>
#include <vtkm/cont/testing/Testing.h>
......@@ -33,6 +38,7 @@
namespace
{
// clang-format off
template<typename T>
void is_noexcept_movable()
......@@ -55,12 +61,13 @@ void is_triv_noexcept_movable()
std::is_trivially_move_assignable<T>::value &&
#endif
std::is_nothrow_move_constructible<T>::value &&
std::is_nothrow_move_assignable<T>::value;
std::is_nothrow_move_assignable<T>::value &&
std::is_nothrow_constructible<T, T&&>::value;
std::string msg = typeid(T).name() + std::string(" should be noexcept moveable");
VTKM_TEST_ASSERT(valid, msg);
}
// clang-format o
// clang-format on
struct IsTrivNoExcept
{
......@@ -96,19 +103,30 @@ struct IsNoExceptHandle
std::declval<VirtualType>().PrepareForOutput(2, vtkm::cont::DeviceAdapterTagSerial{}))>();
}
};
struct vtkmComplexCustomTypes : vtkm::ListTagBase<vtkm::Vec<vtkm::Vec<float, 3>, 3>,
vtkm::Pair<vtkm::UInt64, vtkm::UInt64>,
vtkm::Bitset<vtkm::UInt64>,
vtkm::Bounds,
vtkm::Range>
{
};
}
//-----------------------------------------------------------------------------
void TestContDataTypesHaveMoveSemantics()
{
//verify the Vec types are triv and noexcept
vtkm::testing::Testing::TryTypes( IsTrivNoExcept{}, vtkm::TypeListTagVecCommon{} );
is_triv_noexcept_movable<vtkm::Vec<vtkm::Vec<float,3>,3>>();
vtkm::testing::Testing::TryTypes(IsTrivNoExcept{}, vtkm::TypeListTagVecCommon{});
//verify that vtkm::Pair, Bitset, Bounds, and Range are triv and noexcept
vtkm::testing::Testing::TryTypes(IsTrivNoExcept{}, vtkmComplexCustomTypes{});
//verify that ArrayHandles and related portals are noexcept movable
//allowing for efficient storage in containers such as std::vector
vtkm::testing::Testing::TryTypes( IsNoExceptHandle{}, vtkm::TypeListTagAll{} );
vtkm::testing::Testing::TryTypes(IsNoExceptHandle{}, vtkm::TypeListTagAll{});
vtkm::testing::Testing::TryTypes(IsNoExceptHandle{}, ::vtkmComplexCustomTypes{});
//verify the DataSet, Field, CoordinateSystem, and ArrayHandleVirtualCoordinates
//all have efficient storage in containers such as std::vector
......
......@@ -20,6 +20,7 @@
#ifndef vtk_m_testing_Testing_h
#define vtk_m_testing_Testing_h
#include <vtkm/Bitset.h>
#include <vtkm/Bounds.h>
#include <vtkm/CellShape.h>
#include <vtkm/Math.h>
......@@ -109,6 +110,9 @@ VTK_M_BASIC_TYPE(vtkm::UInt32);
VTK_M_BASIC_TYPE(vtkm::Int64);
VTK_M_BASIC_TYPE(vtkm::UInt64);
VTK_M_BASIC_TYPE(vtkm::Bounds);
VTK_M_BASIC_TYPE(vtkm::Range);
#undef VTK_M_BASIC_TYPE
template <typename T, vtkm::IdComponent Size>
......@@ -133,6 +137,17 @@ struct TypeName<vtkm::Pair<T, U>>
}
};
template <typename T>
struct TypeName<vtkm::Bitset<T>>
{
static std::string Name()
{
std::stringstream stream;
stream << "vtkm::Bitset< " << TypeName<T>::Name() << " >";
return stream.str();
}
};
namespace detail
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment