2018-12-07 20:54:20 +00:00
|
|
|
//============================================================================
|
|
|
|
// Copyright (c) Kitware, Inc.
|
|
|
|
// All rights reserved.
|
|
|
|
// See LICENSE.txt for details.
|
2019-04-15 23:24:21 +00:00
|
|
|
//
|
2018-12-07 20:54:20 +00:00
|
|
|
// This software is distributed WITHOUT ANY WARRANTY; without even
|
|
|
|
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
// PURPOSE. See the above copyright notice for more information.
|
|
|
|
//============================================================================
|
|
|
|
#include <vtkm/cont/ArrayHandle.h>
|
|
|
|
#include <vtkm/cont/ArrayHandleVirtualCoordinates.h>
|
|
|
|
|
|
|
|
#include <vtkm/cont/CellSetExplicit.h>
|
|
|
|
#include <vtkm/cont/CellSetStructured.h>
|
|
|
|
#include <vtkm/cont/CoordinateSystem.h>
|
|
|
|
#include <vtkm/cont/DataSet.h>
|
|
|
|
#include <vtkm/cont/Field.h>
|
|
|
|
|
2019-01-01 19:57:54 +00:00
|
|
|
#include <vtkm/Bitset.h>
|
|
|
|
#include <vtkm/Bounds.h>
|
|
|
|
#include <vtkm/Pair.h>
|
|
|
|
#include <vtkm/Range.h>
|
|
|
|
|
2019-12-05 17:55:57 +00:00
|
|
|
#include <vtkm/TypeList.h>
|
2018-12-07 20:54:20 +00:00
|
|
|
#include <vtkm/cont/testing/Testing.h>
|
|
|
|
|
|
|
|
#include <type_traits>
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
2019-01-01 19:57:54 +00:00
|
|
|
|
2018-12-07 20:54:20 +00:00
|
|
|
// clang-format off
|
|
|
|
template<typename T>
|
|
|
|
void is_noexcept_movable()
|
|
|
|
{
|
|
|
|
constexpr bool valid = std::is_nothrow_move_constructible<T>::value &&
|
|
|
|
std::is_nothrow_move_assignable<T>::value;
|
|
|
|
|
|
|
|
std::string msg = typeid(T).name() + std::string(" should be noexcept moveable");
|
|
|
|
VTKM_TEST_ASSERT(valid, msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
void is_triv_noexcept_movable()
|
|
|
|
{
|
|
|
|
constexpr bool valid =
|
2018-12-11 14:29:08 +00:00
|
|
|
#if !(defined(__GNUC__) && (__GNUC__ <= 5))
|
|
|
|
//GCC 4.X and compilers that act like it such as Intel 17.0
|
|
|
|
//don't have implementations for is_trivially_*
|
2018-12-07 20:54:20 +00:00
|
|
|
std::is_trivially_move_constructible<T>::value &&
|
|
|
|
std::is_trivially_move_assignable<T>::value &&
|
|
|
|
#endif
|
|
|
|
std::is_nothrow_move_constructible<T>::value &&
|
2019-01-01 19:57:54 +00:00
|
|
|
std::is_nothrow_move_assignable<T>::value &&
|
|
|
|
std::is_nothrow_constructible<T, T&&>::value;
|
2018-12-07 20:54:20 +00:00
|
|
|
|
|
|
|
std::string msg = typeid(T).name() + std::string(" should be noexcept moveable");
|
|
|
|
VTKM_TEST_ASSERT(valid, msg);
|
|
|
|
}
|
2019-01-01 19:57:54 +00:00
|
|
|
// clang-format on
|
2018-12-07 20:54:20 +00:00
|
|
|
|
|
|
|
struct IsTrivNoExcept
|
|
|
|
{
|
|
|
|
template <typename T>
|
|
|
|
void operator()(T) const
|
|
|
|
{
|
|
|
|
is_triv_noexcept_movable<T>();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct IsNoExceptHandle
|
|
|
|
{
|
|
|
|
template <typename T>
|
|
|
|
void operator()(T) const
|
|
|
|
{
|
2018-11-06 16:40:39 +00:00
|
|
|
using HandleType = vtkm::cont::ArrayHandle<T>;
|
|
|
|
using VirtualType = vtkm::cont::ArrayHandleVirtual<T>;
|
|
|
|
|
|
|
|
//verify the handle type
|
2018-12-11 13:56:08 +00:00
|
|
|
is_noexcept_movable<HandleType>();
|
2018-11-06 16:40:39 +00:00
|
|
|
is_noexcept_movable<VirtualType>();
|
|
|
|
|
|
|
|
//verify the input portals of the handle
|
2020-01-21 20:18:03 +00:00
|
|
|
is_noexcept_movable<decltype(std::declval<HandleType>().PrepareForInput(
|
|
|
|
vtkm::cont::DeviceAdapterTagSerial{}, std::declval<vtkm::cont::Token&>()))>();
|
|
|
|
is_noexcept_movable<decltype(std::declval<VirtualType>().PrepareForInput(
|
|
|
|
vtkm::cont::DeviceAdapterTagSerial{}, std::declval<vtkm::cont::Token&>()))>();
|
2018-11-06 16:40:39 +00:00
|
|
|
|
|
|
|
//verify the output portals of the handle
|
2020-01-21 20:18:03 +00:00
|
|
|
is_noexcept_movable<decltype(std::declval<HandleType>().PrepareForOutput(
|
|
|
|
2, vtkm::cont::DeviceAdapterTagSerial{}, std::declval<vtkm::cont::Token&>()))>();
|
|
|
|
is_noexcept_movable<decltype(std::declval<VirtualType>().PrepareForOutput(
|
|
|
|
2, vtkm::cont::DeviceAdapterTagSerial{}, std::declval<vtkm::cont::Token&>()))>();
|
2018-12-07 20:54:20 +00:00
|
|
|
}
|
|
|
|
};
|
2019-01-01 19:57:54 +00:00
|
|
|
|
2019-12-05 21:38:41 +00:00
|
|
|
using vtkmComplexCustomTypes = vtkm::List<vtkm::Vec<vtkm::Vec<float, 3>, 3>,
|
|
|
|
vtkm::Pair<vtkm::UInt64, vtkm::UInt64>,
|
|
|
|
vtkm::Bitset<vtkm::UInt64>,
|
|
|
|
vtkm::Bounds,
|
|
|
|
vtkm::Range>;
|
2018-12-07 20:54:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
void TestContDataTypesHaveMoveSemantics()
|
|
|
|
{
|
|
|
|
//verify the Vec types are triv and noexcept
|
2019-12-05 17:55:57 +00:00
|
|
|
vtkm::testing::Testing::TryTypes(IsTrivNoExcept{}, vtkm::TypeListVecCommon{});
|
2019-01-01 19:57:54 +00:00
|
|
|
//verify that vtkm::Pair, Bitset, Bounds, and Range are triv and noexcept
|
|
|
|
vtkm::testing::Testing::TryTypes(IsTrivNoExcept{}, vtkmComplexCustomTypes{});
|
2018-12-07 20:54:20 +00:00
|
|
|
|
|
|
|
|
2018-11-06 16:40:39 +00:00
|
|
|
//verify that ArrayHandles and related portals are noexcept movable
|
2018-12-07 20:54:20 +00:00
|
|
|
//allowing for efficient storage in containers such as std::vector
|
2019-12-05 17:55:57 +00:00
|
|
|
vtkm::testing::Testing::TryTypes(IsNoExceptHandle{}, vtkm::TypeListAll{});
|
2019-01-01 19:57:54 +00:00
|
|
|
|
|
|
|
vtkm::testing::Testing::TryTypes(IsNoExceptHandle{}, ::vtkmComplexCustomTypes{});
|
2018-12-07 20:54:20 +00:00
|
|
|
|
2018-11-06 16:40:39 +00:00
|
|
|
//verify the DataSet, Field, CoordinateSystem, and ArrayHandleVirtualCoordinates
|
2018-12-07 20:54:20 +00:00
|
|
|
//all have efficient storage in containers such as std::vector
|
|
|
|
is_noexcept_movable<vtkm::cont::DataSet>();
|
|
|
|
is_noexcept_movable<vtkm::cont::Field>();
|
|
|
|
is_noexcept_movable<vtkm::cont::CoordinateSystem>();
|
2018-11-06 16:40:39 +00:00
|
|
|
is_noexcept_movable<vtkm::cont::ArrayHandleVirtualCoordinates>();
|
2018-12-07 20:54:20 +00:00
|
|
|
|
|
|
|
//verify the CellSetStructured, and CellSetExplicit
|
|
|
|
//have efficient storage in containers such as std::vector
|
|
|
|
is_noexcept_movable<vtkm::cont::CellSetStructured<2>>();
|
|
|
|
is_noexcept_movable<vtkm::cont::CellSetStructured<3>>();
|
|
|
|
is_noexcept_movable<vtkm::cont::CellSetExplicit<>>();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2019-01-01 22:19:02 +00:00
|
|
|
int UnitTestMoveConstructors(int argc, char* argv[])
|
2018-12-07 20:54:20 +00:00
|
|
|
{
|
2019-01-01 22:19:02 +00:00
|
|
|
return vtkm::cont::testing::Testing::Run(TestContDataTypesHaveMoveSemantics, argc, argv);
|
2018-12-07 20:54:20 +00:00
|
|
|
}
|