Commit 8237db20 authored by Robert Maynard's avatar Robert Maynard Committed by Kitware Robot
Browse files

Merge topic 'noexcept_move_constructors'

c66a6e48 Provided vtkm::cont::Storage with move schematics
1f86878f

 Make the ArrayHandle move constructors noexcept.
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Acked-by: default avatarAllison Vacanti <allison.vacanti@kitware.com>
Merge-request: !1439
parents e549cea8 c66a6e48
......@@ -294,7 +294,7 @@ public:
/// with CUDA), then the automatically generated move constructor could be
/// created for all devices, and it would not be valid for all devices.
///
ArrayHandle(vtkm::cont::ArrayHandle<ValueType, StorageTag>&& src);
ArrayHandle(vtkm::cont::ArrayHandle<ValueType, StorageTag>&& src) noexcept;
/// Special constructor for subclass specializations that need to set the
/// initial state of the control array. When this constructor is used, it
......@@ -307,7 +307,7 @@ public:
/// initial state of the control array. When this constructor is used, it
/// is assumed that the control array is valid.
///
ArrayHandle(StorageType&& storage);
ArrayHandle(StorageType&& storage) noexcept;
/// Destructs an empty ArrayHandle.
///
......@@ -328,7 +328,7 @@ public:
///
VTKM_CONT
vtkm::cont::ArrayHandle<ValueType, StorageTag>& operator=(
vtkm::cont::ArrayHandle<ValueType, StorageTag>&& src);
vtkm::cont::ArrayHandle<ValueType, StorageTag>&& src) noexcept;
/// Like a pointer, two \c ArrayHandles are considered equal if they point
/// to the same location in memory.
......
......@@ -38,7 +38,7 @@ ArrayHandle<T, S>::ArrayHandle(const ArrayHandle<T, S>& src)
}
template <typename T, typename S>
ArrayHandle<T, S>::ArrayHandle(ArrayHandle<T, S>&& src)
ArrayHandle<T, S>::ArrayHandle(ArrayHandle<T, S>&& src) noexcept
: Internals(std::move(src.Internals))
{
}
......@@ -53,7 +53,7 @@ ArrayHandle<T, S>::ArrayHandle(const typename ArrayHandle<T, S>::StorageType& st
}
template <typename T, typename S>
ArrayHandle<T, S>::ArrayHandle(typename ArrayHandle<T, S>::StorageType&& storage)
ArrayHandle<T, S>::ArrayHandle(typename ArrayHandle<T, S>::StorageType&& storage) noexcept
: Internals(new InternalStruct)
{
this->Internals->ControlArray = std::move(storage);
......@@ -74,7 +74,7 @@ ArrayHandle<T, S>& ArrayHandle<T, S>::operator=(const ArrayHandle<T, S>& src)
}
template <typename T, typename S>
ArrayHandle<T, S>& ArrayHandle<T, S>::operator=(ArrayHandle<T, S>&& src)
ArrayHandle<T, S>& ArrayHandle<T, S>::operator=(ArrayHandle<T, S>&& src) noexcept
{
this->Internals = std::move(src.Internals);
return *this;
......
......@@ -122,6 +122,11 @@ public:
///
using PortalConstType = ::vtkm::cont::internal::ArrayPortalFromIterators<const ValueType*>;
VTKM_CONT Storage(const Storage& src);
VTKM_CONT Storage(Storage&& src) noexcept;
VTKM_CONT Storage& operator=(const Storage& src);
VTKM_CONT Storage& operator=(Storage&& src);
/// Returns a portal to the array.
///
VTKM_CONT
......
......@@ -118,11 +118,11 @@ StorageBasicBase::~StorageBasicBase()
this->ReleaseResources();
}
StorageBasicBase::StorageBasicBase(StorageBasicBase&& src)
: Array(src.Array)
, AllocatedByteSize(src.AllocatedByteSize)
, NumberOfValues(src.NumberOfValues)
, DeleteFunction(src.DeleteFunction)
StorageBasicBase::StorageBasicBase(StorageBasicBase&& src) noexcept
: Array(src.Array),
AllocatedByteSize(src.AllocatedByteSize),
NumberOfValues(src.NumberOfValues),
DeleteFunction(src.DeleteFunction)
{
src.Array = nullptr;
......@@ -146,7 +146,7 @@ StorageBasicBase::StorageBasicBase(const StorageBasicBase& src)
}
}
StorageBasicBase StorageBasicBase::operator=(StorageBasicBase&& src)
StorageBasicBase& StorageBasicBase::operator=(StorageBasicBase&& src) noexcept
{
this->ReleaseResources();
this->Array = src.Array;
......@@ -161,7 +161,7 @@ StorageBasicBase StorageBasicBase::operator=(StorageBasicBase&& src)
return *this;
}
StorageBasicBase StorageBasicBase::operator=(const StorageBasicBase& src)
StorageBasicBase& StorageBasicBase::operator=(const StorageBasicBase& src)
{
if (src.DeleteFunction)
{
......
......@@ -83,10 +83,10 @@ public:
VTKM_CONT ~StorageBasicBase();
VTKM_CONT StorageBasicBase(StorageBasicBase&& src);
VTKM_CONT StorageBasicBase(StorageBasicBase&& src) noexcept;
VTKM_CONT StorageBasicBase(const StorageBasicBase& src);
VTKM_CONT StorageBasicBase operator=(StorageBasicBase&& src);
VTKM_CONT StorageBasicBase operator=(const StorageBasicBase& src);
VTKM_CONT StorageBasicBase& operator=(StorageBasicBase&& src) noexcept;
VTKM_CONT StorageBasicBase& operator=(const StorageBasicBase& src);
/// \brief Return the number of bytes allocated for this storage object(Capacity).
///
......@@ -178,6 +178,8 @@ public:
public:
/// \brief construct storage that VTK-m is responsible for
VTKM_CONT Storage();
VTKM_CONT Storage(const Storage<ValueT, vtkm::cont::StorageTagBasic>& src);
VTKM_CONT Storage(Storage<ValueT, vtkm::cont::StorageTagBasic>&& src) noexcept;
/// \brief construct storage that VTK-m is not responsible for
VTKM_CONT Storage(const ValueType* array, vtkm::Id numberOfValues);
......@@ -186,6 +188,9 @@ public:
/// responsible for
VTKM_CONT Storage(const ValueType* array, vtkm::Id numberOfValues, void (*deleteFunction)(void*));
VTKM_CONT Storage& operator=(const Storage<ValueT, vtkm::cont::StorageTagBasic>& src);
VTKM_CONT Storage& operator=(Storage<ValueT, vtkm::cont::StorageTagBasic>&& src);
VTKM_CONT void Allocate(vtkm::Id numberOfValues);
VTKM_CONT PortalType GetPortal();
......
......@@ -29,12 +29,25 @@ namespace cont
namespace internal
{
template <typename T>
Storage<T, vtkm::cont::StorageTagBasic>::Storage()
: StorageBasicBase()
{
}
template <typename T>
Storage<T, vtkm::cont::StorageTagBasic>::Storage(const Storage<T, vtkm::cont::StorageTagBasic>& src)
: StorageBasicBase(src)
{
}
template <typename T>
Storage<T, vtkm::cont::StorageTagBasic>::Storage(
Storage<T, vtkm::cont::StorageTagBasic>&& src) noexcept : StorageBasicBase(std::move(src))
{
}
template <typename T>
Storage<T, vtkm::cont::StorageTagBasic>::Storage(const T* array, vtkm::Id numberOfValues)
: StorageBasicBase(const_cast<T*>(array), numberOfValues, sizeof(T))
......@@ -49,6 +62,22 @@ Storage<T, vtkm::cont::StorageTagBasic>::Storage(const T* array,
{
}
template <typename T>
Storage<T, vtkm::cont::StorageTagBasic>& Storage<T, vtkm::cont::StorageTagBasic>::Storage::
operator=(const Storage<T, vtkm::cont::StorageTagBasic>& src)
{
return static_cast<Storage<T, vtkm::cont::StorageTagBasic>&>(StorageBasicBase::operator=(src));
}
template <typename T>
Storage<T, vtkm::cont::StorageTagBasic>& Storage<T, vtkm::cont::StorageTagBasic>::Storage::
operator=(Storage<T, vtkm::cont::StorageTagBasic>&& src)
{
return static_cast<Storage<T, vtkm::cont::StorageTagBasic>&>(
StorageBasicBase::operator=(std::move(src)));
}
template <typename T>
void Storage<T, vtkm::cont::StorageTagBasic>::Allocate(vtkm::Id numberOfValues)
{
......
......@@ -55,6 +55,9 @@ namespace internal
template <class ArrayPortalType>
class Storage<typename ArrayPortalType::ValueType, StorageTagImplicit<ArrayPortalType>>
{
using ClassType =
Storage<typename ArrayPortalType::ValueType, StorageTagImplicit<ArrayPortalType>>;
public:
using ValueType = typename ArrayPortalType::ValueType;
using PortalConstType = ArrayPortalType;
......@@ -74,6 +77,11 @@ public:
{
}
VTKM_CONT Storage(const ClassType& src) = default;
VTKM_CONT Storage(ClassType&& src) = default;
VTKM_CONT ClassType& operator=(const ClassType& src) = default;
VTKM_CONT ClassType& operator=(ClassType&& src) = default;
// All these methods do nothing but raise errors.
VTKM_CONT
PortalType GetPortal() { throw vtkm::cont::ErrorBadValue("Implicit arrays are read-only."); }
......
......@@ -239,15 +239,15 @@ public:
VTKM_CONT ArrayHandle();
VTKM_CONT ArrayHandle(const Thisclass& src);
VTKM_CONT ArrayHandle(Thisclass&& src);
VTKM_CONT ArrayHandle(Thisclass&& src) noexcept;
VTKM_CONT ArrayHandle(const StorageType& storage);
VTKM_CONT ArrayHandle(StorageType&& storage);
VTKM_CONT ArrayHandle(const StorageType& storage) noexcept;
VTKM_CONT ArrayHandle(StorageType&& storage) noexcept;
VTKM_CONT ~ArrayHandle();
VTKM_CONT Thisclass& operator=(const Thisclass& src);
VTKM_CONT Thisclass& operator=(Thisclass&& src);
VTKM_CONT Thisclass& operator=(Thisclass&& src) noexcept;
VTKM_CONT bool operator==(const Thisclass& rhs) const;
VTKM_CONT bool operator!=(const Thisclass& rhs) const;
......
......@@ -40,19 +40,19 @@ ArrayHandle<T, StorageTagBasic>::ArrayHandle(const Thisclass& src)
}
template <typename T>
ArrayHandle<T, StorageTagBasic>::ArrayHandle(Thisclass&& src)
ArrayHandle<T, StorageTagBasic>::ArrayHandle(Thisclass&& src) noexcept
: Internals(std::move(src.Internals))
{
}
template <typename T>
ArrayHandle<T, StorageTagBasic>::ArrayHandle(const StorageType& storage)
ArrayHandle<T, StorageTagBasic>::ArrayHandle(const StorageType& storage) noexcept
: Internals(new internal::ArrayHandleImpl(storage))
{
}
template <typename T>
ArrayHandle<T, StorageTagBasic>::ArrayHandle(StorageType&& storage)
ArrayHandle<T, StorageTagBasic>::ArrayHandle(StorageType&& storage) noexcept
: Internals(new internal::ArrayHandleImpl(std::move(storage)))
{
}
......@@ -70,7 +70,8 @@ ArrayHandle<T, StorageTagBasic>& ArrayHandle<T, StorageTagBasic>::operator=(cons
}
template <typename T>
ArrayHandle<T, StorageTagBasic>& ArrayHandle<T, StorageTagBasic>::operator=(Thisclass&& src)
ArrayHandle<T, StorageTagBasic>& ArrayHandle<T, StorageTagBasic>::operator=(
Thisclass&& src) noexcept
{
this->Internals = std::move(src.Internals);
return *this;
......
Supports Markdown
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