#ifndef __VECTOR_TPP__ #define __VECTOR_TPP__ /* for auto loop */ template typename Vector::iterator Vector::begin() { return iterator(this); } template typename Vector::iterator Vector::end() { return iterator(this, this->size() - 1); } template typename Vector::const_iterator Vector::begin() const { return iterator(this); } template typename Vector::const_iterator Vector::end() const { return iterator(this, this->size() - 1); } template bool Vector::operator==(const Vector& v) const { if(this->size() != v.size()) return false; //Retourne déjà faux si les deux vecteurs n'ont pas la même dimension for(size_t i(0); i < v.size(); ++i){ if ((*this)[i] != v[i]) return false; //Lors que le programme rencontre deux coordonnées différenentes respectivement pour la même dimension des deux vecteurs //la fonction retourne false } return true; } template bool Vector::operator>=(const Vector& v) const { return sq_module() >= v.sq_module(); } template bool Vector::operator<=(const Vector& v) const { return sq_module() <= v.sq_module(); } template bool Vector::operator>=(double m) const { return sq_module() >= m * m; } template bool Vector::operator<=(double m) const { return sq_module() <= m * m; } template bool Vector::operator>(const Vector& v) const { return sq_module() > v.sq_module(); } template bool Vector::operator<(const Vector& v) const { return sq_module() < v.sq_module(); } template bool Vector::operator>(double m) const { return sq_module() > m * m; } template bool Vector::operator<(double m) const { return sq_module() < m * m; } template bool Vector::operator!=(const Vector& w) const { return !(*this == w); } //Operateurs somme et produit template Vector& Vector::add(const Vector& w) { size_t n = (this->size() <= w.size()) ? this->size() : w.size(); for (size_t i= 0; i < n; ++i) (*this)[i] += w[i]; return *this; } template Vector& Vector::sub(const Vector& w) { size_t n = (this->size() <= w.size()) ? this->size() : w.size(); for (size_t i = 0; i < n; ++i) (*this)[i] -= w[i]; return *this; } template Vector& Vector::mult(double k) { for (size_t i = 0; i < this->size(); ++i) (*this)[i] *= k; return *this; } template Vector& Vector::divide(double k) { for (size_t i = 0; i < this->size(); ++i) (*this)[i] /= k; return *this; } template Vector& Vector::_unit() const { return (*this) /= this->module(); } /* Dot product */ template double Vector::operator*(const Vector& w) const { double x = 0; size_t n = (this->size() <= w.size()) ? this->size() : w.size(); for (size_t i = 0; i < n; ++i) x += (*this)[i] * w[i]; return x; } template Vector& Vector::reverse() { return (*this)*=-1.0; } template double Vector::sq_module() const { return (*this) * (*this); } template double Vector::module() const { return sqrt(this->sq_module()); } /* Implementation of ostream operator overloading */ /* Le prototype je le mets dans un header séparé parce que * il ne fait pas partie de l'implementation d'un vecteur * Une classe l'utilisant n'as pas besoin de l'imprimer */ #ifdef _USE_VECTOR_OSTREAM #include template void Vector::affiche(std::ostream& os) const { os << "("; for (size_t i(0); i < (size() - 1); ++i) { os << (*this)[i] << ", "; } os << (*this)[size()-1] << ")"; } // Flux de sortie permettant d'afficher les coordonnées du vecteur template std::ostream& operator<<(std::ostream& os, const Vector& v) { v.affiche(os); return os; } #endif #endif //__VECTOR_TPP__