Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Copy constructor.
- Grid(const Grid &other) : memory(nullptr)
- {
- //Note: Both Reserve() and copyElements() can throw exceptions. If they succeed properly, they will save the new state
- //to member-variables - but no member-variables should be manually altered within this function before their call.
- //Reserve enough memory.
- this->Reserve(other.capacity);
- //Copy-construct the elements.
- this->copyElements(other.memory, other.capacity, this->memory, this->capacity, other.bounds, CopyMode::CopyConstructor);
- //Save the new bounds (once we are sure copyElements() didn't throw).
- this->bounds = other.bounds;
- }
- //Move constructor.
- Grid(Grid &&other) : memory(nullptr)
- {
- this->operator=(std::forward<Grid>(other));
- }
- //Assignment operator
- Grid &operator=(const Grid &other)
- {
- Grid<Type> temp(other);
- this->Swap(temp);
- return *this;
- }
- //Move-assignment.
- Grid &operator=(Grid &&other)
- {
- this->Swap(other);
- return *this;
- }
- //Swaps the contents of this grid with 'other'.
- void Swap(Grid &other) throw()
- {
- //Swap pointers.
- std::swap(this->memory, other.memory);
- //Swap bounds and capacity.
- std::swap(this->bounds, other.bounds);
- std::swap(this->capacity, other.capacity);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement