Commit a41728d7 authored by Jens Petit's avatar Jens Petit

noexcept for DataContainer move ctor/assignment (#9)

parent 7749b287
Pipeline #171100 passed with stages
in 27 minutes and 26 seconds
......@@ -43,26 +43,24 @@ namespace elsa {
}
template <typename data_t>
DataContainer<data_t>::DataContainer(DataContainer<data_t> &&other)
DataContainer<data_t>::DataContainer(DataContainer<data_t> &&other) noexcept
: _dataDescriptor{std::move(other._dataDescriptor)},
_dataHandler{std::move(other._dataHandler)}
{
// make sure to leave other in a valid state (since we do not check for empty pointers!)
IndexVector_t numCoeff(1); numCoeff << 1;
other._dataDescriptor = std::make_unique<DataDescriptor>(numCoeff);
other._dataHandler = createDataHandler(DataHandlerType::CPU, other._dataDescriptor->getNumberOfCoefficients());
// leave other in a valid state
other._dataDescriptor = nullptr;
other._dataHandler = nullptr;
}
template <typename data_t>
DataContainer<data_t>& DataContainer<data_t>::operator=(DataContainer<data_t>&& other)
DataContainer<data_t>& DataContainer<data_t>::operator=(DataContainer<data_t>&& other) noexcept
{
_dataDescriptor = std::move(other._dataDescriptor);
_dataHandler = std::move(other._dataHandler);
// make sure to leave other in a valid state (since we do not check for empty pointers!)
IndexVector_t numCoeff(1); numCoeff << 1;
other._dataDescriptor = std::make_unique<DataDescriptor>(numCoeff);
other._dataHandler = createDataHandler(DataHandlerType::CPU, other._dataDescriptor->getNumberOfCoefficients());
// leave other in a valid state
other._dataDescriptor = nullptr;
other._dataHandler = nullptr;
return *this;
}
......
......@@ -85,15 +85,23 @@ namespace elsa
* \brief Move constructor for DataContainer
*
* \param[in] other DataContainer to move from
*
* The moved-from objects remains in a valid state. However, as preconditions are not
* fulfilled for any member functions, the object should not be used. After move- or copy-
* assignment, this is possible again.
*/
DataContainer(DataContainer<data_t>&& other);
DataContainer(DataContainer<data_t>&& other) noexcept;
/**
* \brief Move assignment for DataContainer
*
* \param[in] other DataContainer to move from
*
* The moved-from objects remains in a valid state. However, as preconditions are not
* fulfilled for any member functions, the object should not be used. After move- or copy-
* assignment, this is possible again.
*/
DataContainer<data_t>& operator=(DataContainer<data_t>&& other);
DataContainer<data_t>& operator=(DataContainer<data_t>&& other) noexcept;
/// return the current DataDescriptor
const DataDescriptor& getDataDescriptor() const;
......
......@@ -105,8 +105,7 @@ SCENARIO("Constructing DataContainers") {
}
THEN("the moved from object is still valid (but empty)") {
REQUIRE(otherDc.getSize() == 1);
REQUIRE(otherDc[0] == 0);
otherDc = dc;
}
}
......@@ -123,8 +122,7 @@ SCENARIO("Constructing DataContainers") {
}
THEN("the moved from object is still valid (but empty)") {
REQUIRE(otherDc.getSize() == 1);
REQUIRE(otherDc[0] == 0);
otherDc = dc;
}
}
}
......
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