namespace lasd { template Vector::Vector(const ulong newsize){ Elements = new Data[newsize]{}; size = newsize; } template Vector::Vector(const LinearContainer& con){ size = con.Size(); Elements = new Data[size]{}; for(ulong i=0; i Vector::Vector(const Vector& vec){ size = vec.size; Elements = new Data[size]{}; for(ulong i=0; i Vector::Vector(Vector&& vec)noexcept{ std::swap(Elements, vec.Elements); std::swap(size, vec.size); } // Destructor template Vector::~Vector(){ Clear(); } // Copy assignment template Vector& Vector::operator=(const Vector& vec){ Vector* tmpvec = new Vector(vec); std::swap(*tmpvec, *this); delete tmpvec; return *this; } // Move assignment template Vector& Vector::operator=(Vector&& vec)noexcept{ std::swap(Elements,vec.Elements); std::swap(size, vec.size); return *this; } template bool Vector::operator==(const Vector& vec) const noexcept{ if(size == vec.size){ for(ulong i=0; i bool Vector::operator!=(const Vector& vec)const noexcept{ return !(*this == vec); } template void Vector::Resize(const ulong newsize){ if(newsize == 0){ Vector::Clear(); //Vector::Clear() instead of Clear() otherwise it'd call the Matrix's implementation. } else if(size != newsize){ ulong limit = (size < newsize) ? size : newsize; Data* TmpElements = new Data[newsize]{}; for(ulong i=0; i void Vector::Clear(){ delete[] Elements; Elements = nullptr; size = 0; } template Data& Vector::Front() const { if(size != 0){ return Elements[0]; } else{ throw std::length_error("Access to an empty vector!"); } } template Data& Vector::Back() const { if(size != 0){ return Elements[size - 1]; } else{ throw std::length_error("Access to an empty vector!"); } } template Data& Vector::operator[](const ulong index) const{ if(index < size){ return Elements[index]; } else{ throw std::out_of_range("Tried to access index " + std::to_string(index) + " but the dimension of the vector is " + std::to_string(size)); } } template void Vector::MapPreOrder(const MapFunctor fun, void* par){ for(ulong i=0; i void Vector::MapPostOrder(const MapFunctor fun, void* par){ ulong index = size; while(index > 0){ fun(Elements[--index], par); } } template void Vector::FoldPreOrder(const FoldFunctor fun, const void* par, void* acc) const{ for(ulong i=0; i void Vector::FoldPostOrder(const FoldFunctor fun, const void* par, void* acc) const{ ulong idx = size; while(idx > 0){ fun(Elements[--idx], par, acc); } } }