#ifndef __DVECTOR_TPP__ #define __DVECTOR_TPP__ template DVector::DVector(size_t dim) : components(dim) { } template DVector::DVector(const std::vector& init) : components(init) { } template DVector::DVector(const std::initializer_list &init) : components(init.begin(), init.end()) { } template const size_t DVector::size() const { return components.size(); } template T& DVector::operator[](size_t i) { return components[i]; } template const T& DVector::operator[](size_t i) const { return components[i]; } template DVector& DVector::operator<<(const T &value) { components.push_back(value); } template DVector& DVector::operator+=(const Vector &w) { return static_cast&>(this->add(w)); } template DVector& DVector::operator-=(const Vector &w) { return static_cast&>(this->sub(w)); } template DVector& DVector::operator*=(double k) { return static_cast&>(this->mult(k)); } template DVector& DVector::operator/=(double k) { return static_cast&>(this->divide(k)); } template DVector& DVector::operator~() { return static_cast&>(this->reverse()); } template DVector& DVector::unit() { return static_cast&>(this->_unit()); } template const DVector operator-(DVector v) { return ~v; } template const DVector operator+(DVector v, const Vector& w) { return v += w; } template const DVector operator-(DVector v, const Vector& w) { return v -= w; } template const DVector operator*(DVector v, double k) { return v *= k; } template const DVector operator/(DVector v, double k) { return v /= k; } template const DVector operator*(double k, DVector v) { return v *= k; } template const DVector operator/(double k, DVector v) { return v /= k; } inline const DVector operator^(const DVector& v, const Vector& w) { DVector u; size_t n = (v.size() <= w.size()) ? v.size() : w.size(); if (n > 2) { u << v[1] * w[2] - v[2] * w[1]; u << v[2] * w[0] - v[0] * w[2]; u << v[0] * w[1] - v[1] * w[0]; } else if (n == 2) u << v[0] * w[1] - v[1] * w[0]; else if (n == 1) u << v[0] * w[0]; return u; } #endif