//============================================================================ // Copyright (c) Kitware, Inc. // All rights reserved. // See LICENSE.txt for details. // // 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 #include #include #include #include #include #include #include #include #include #include #include #include #include namespace { // clang-format off template void is_noexcept_movable() { constexpr bool valid = std::is_nothrow_move_constructible::value && std::is_nothrow_move_assignable::value; std::string msg = typeid(T).name() + std::string(" should be noexcept moveable"); VTKM_TEST_ASSERT(valid, msg); } template void is_triv_noexcept_movable() { constexpr bool valid = #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_* std::is_trivially_move_constructible::value && std::is_trivially_move_assignable::value && #endif std::is_nothrow_move_constructible::value && std::is_nothrow_move_assignable::value && std::is_nothrow_constructible::value; std::string msg = typeid(T).name() + std::string(" should be noexcept moveable"); VTKM_TEST_ASSERT(valid, msg); } // clang-format on struct IsTrivNoExcept { template void operator()(T) const { is_triv_noexcept_movable(); } }; struct IsNoExceptHandle { template void operator()(T) const { using HandleType = vtkm::cont::ArrayHandle; using VirtualType = vtkm::cont::ArrayHandleVirtual; //verify the handle type is_noexcept_movable(); is_noexcept_movable(); //verify the input portals of the handle is_noexcept_movable().PrepareForInput(vtkm::cont::DeviceAdapterTagSerial{}))>(); is_noexcept_movable().PrepareForInput(vtkm::cont::DeviceAdapterTagSerial{}))>(); //verify the output portals of the handle is_noexcept_movable().PrepareForOutput(2, vtkm::cont::DeviceAdapterTagSerial{}))>(); is_noexcept_movable().PrepareForOutput(2, vtkm::cont::DeviceAdapterTagSerial{}))>(); } }; using vtkmComplexCustomTypes = vtkm::List, 3>, vtkm::Pair, vtkm::Bitset, vtkm::Bounds, vtkm::Range>; } //----------------------------------------------------------------------------- void TestContDataTypesHaveMoveSemantics() { //verify the Vec types are triv and noexcept vtkm::testing::Testing::TryTypes(IsTrivNoExcept{}, vtkm::TypeListVecCommon{}); //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::TypeListAll{}); vtkm::testing::Testing::TryTypes(IsNoExceptHandle{}, ::vtkmComplexCustomTypes{}); //verify the DataSet, Field, CoordinateSystem, and ArrayHandleVirtualCoordinates //all have efficient storage in containers such as std::vector is_noexcept_movable(); is_noexcept_movable(); is_noexcept_movable(); is_noexcept_movable(); //verify the CellSetStructured, and CellSetExplicit //have efficient storage in containers such as std::vector is_noexcept_movable>(); is_noexcept_movable>(); is_noexcept_movable>(); } //----------------------------------------------------------------------------- int UnitTestMoveConstructors(int argc, char* argv[]) { return vtkm::cont::testing::Testing::Run(TestContDataTypesHaveMoveSemantics, argc, argv); }