From 2d6f4de0192aa8b221b02c17d5c358a7abb18c1c Mon Sep 17 00:00:00 2001 From: Dmitri Naumov <dmitri.naumov@ufz.de> Date: Thu, 5 Sep 2013 15:02:20 +0200 Subject: [PATCH] Use std::copy instead for for-loops, std::array iface for c-array access. --- MathLib/TemplatePoint.h | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/MathLib/TemplatePoint.h b/MathLib/TemplatePoint.h index 52c3782c7b7..e9d6a373099 100644 --- a/MathLib/TemplatePoint.h +++ b/MathLib/TemplatePoint.h @@ -71,7 +71,10 @@ public: } /** returns an array containing the coordinates of the point */ - const T* getCoords () const { return &_x[0]; } + const T* getCoords () const + { + return _x.data(); + } /** write point coordinates into stream (used from operator<<) * \param os a standard output stream @@ -84,8 +87,7 @@ public: /** read point coordinates into stream (used from operator>>) */ virtual void read (std::istream &is) { - for (std::size_t k(0); k<DIM; k++) - is >> _x[k]; + std::copy(std::istream_iterator<T>(is), std::istream_iterator<T>(), _x.begin()); } protected: @@ -104,8 +106,7 @@ TemplatePoint<T,DIM>::TemplatePoint(std::array<T,DIM> const& x) : template <typename T, std::size_t DIM> TemplatePoint<T, DIM>::TemplatePoint (T const* x) { - for (std::size_t k(0); k < DIM; k++) - _x[k] = x[k]; + std::copy_n(x, DIM, _x.begin()); } /** overload the output operator for class Point */ -- GitLab