Vafo / calculator-task

0 stars 0 forks source link

Rework assignment and deletion #2

Closed Vafo closed 11 months ago

Vafo commented 11 months ago

Add

Idea of copy-and-swap

void swap(vector_t<T>& other) {using std::swap; swap every data member, by koening lookup}
operator=(vector_t& other) {
 vector_t tmp(other);
 this→swap(tmp);
 return *this;
}

ref: https://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/Copy-and-swap

Checked delete ref:https://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/Checked_delete

Vafo commented 11 months ago

One of solutions of applying ADL on calling unqualified swap link: https://stackoverflow.com/questions/5695548/public-friend-swap-member-function

(Is it really fine to have code like swap(*this, other) Is there other way around?)