diff --git a/include/gp/containers/vector.hpp b/include/gp/containers/vector.hpp index 510d830..7713a97 100644 --- a/include/gp/containers/vector.hpp +++ b/include/gp/containers/vector.hpp @@ -24,11 +24,21 @@ namespace gp{ using associated_riterator = pointer_iterator; using associated_const_riterator = const_pointer_iterator; + /** + * @brief Construct a new vector object from an allocator + * + * @param v the allocator + */ vector(allocator& v) : ary() , alloc(v) {} + /** + * @brief Construct a new vector object from another vector, copying it + * + * @param oth the other vector + */ vector(vector& oth) : alloc(oth.alloc) { @@ -46,6 +56,11 @@ namespace gp{ } } + /** + * @brief Construct a new vector object by moving objects out of another vector + * + * @param oth + */ vector(vector&& oth) : ary(oth.ary) , sz(oth.sz) @@ -55,6 +70,12 @@ namespace gp{ oth.ary = nullptr; } + /** + * @brief Copy assignment + * + * @param oth + * @return vector& the reference to this changed vector + */ vector& operator=(vector& oth) { gp_config::assertion(reserve(oth.size()), "could not reserve space on assign"); @@ -75,12 +96,37 @@ namespace gp{ return *this; } + /** + * @brief Move assignment + * + * Will not change the allocator of the local vector, is EXPENSIVE if the both vectors have different allocators + * + * @param oth + * @return vector& + */ vector& operator=(vector&& oth) { - gp::swap(ary, oth.ary); - gp::swap(alloc, oth.alloc); - gp::swap(sz, oth.sz); - gp::swap(cap, oth.cap); + if(&alloc.get() == &oth.alloc.get()) + { + gp::swap(ary, oth.ary); + gp::swap(sz, oth.sz); + gp::swap(cap, oth.cap); + } else { + for(auto& elem : *this) { + elem->~T(); + } + sz = 0; + if(capacity()