From 05a62b2ef616b2b24b75a64a9414e9b4a3837185 Mon Sep 17 00:00:00 2001 From: Dmitri Naumov <github@naumov.de> Date: Thu, 16 Jun 2016 03:13:33 +0000 Subject: [PATCH] Use for-range-loop where possible. --- Applications/FileIO/GMSInterface.cpp | 4 +-- .../ResetPropertiesInPolygonalRegion.cpp | 12 +++---- Applications/Utils/MeshEdit/checkMesh.cpp | 12 +++---- Applications/Utils/MeshEdit/moveMeshNodes.cpp | 4 +-- FileIO/TetGenInterface.cpp | 20 +++++------ GeoLib/AnalyticalGeometry.cpp | 4 +-- GeoLib/GEOObjects.cpp | 20 +++++------ GeoLib/IO/Legacy/OGSIOVer4.cpp | 34 +++++++++---------- GeoLib/Polygon.cpp | 8 ++--- GeoLib/Surface.cpp | 10 +++--- .../Mesh2MeshPropertyInterpolation.cpp | 6 ++-- MeshLib/MeshGenerators/MeshGenerator.cpp | 4 +-- MeshLib/MeshQuality/MeshValidation.cpp | 4 +-- Tests/BaseLib/TestQuicksort.cpp | 8 ++--- Tests/FileIO/TestCsvReader.cpp | 4 +-- Tests/GeoLib/TestPolygon.cpp | 21 ++++++------ Tests/GeoLib/TestPolyline.cpp | 4 +-- Tests/GeoLib/TestSimplePolygonTree.cpp | 4 +-- Tests/MeshLib/TestAddLayerToMesh.cpp | 4 +-- 19 files changed, 92 insertions(+), 95 deletions(-) diff --git a/Applications/FileIO/GMSInterface.cpp b/Applications/FileIO/GMSInterface.cpp index 63164b69c93..d31d6c7353e 100644 --- a/Applications/FileIO/GMSInterface.cpp +++ b/Applications/FileIO/GMSInterface.cpp @@ -140,10 +140,10 @@ void GMSInterface::writeBoreholesToGMS(const std::vector<GeoLib::Point*>* statio out << "name" << "\t" << std::fixed << "X" << "\t" << "Y" << "\t" << "Z" << "\t" << "soilID" << "\n"; - for (std::size_t j = 0; j < stations->size(); j++) + for (auto station_as_point : *stations) { GeoLib::StationBorehole* station = - static_cast<GeoLib::StationBorehole*>((*stations)[j]); + static_cast<GeoLib::StationBorehole*>(station_as_point); std::vector<GeoLib::Point*> profile = station->getProfile(); std::vector<std::string> soilNames = station->getSoilNames(); //std::size_t idx = 0; diff --git a/Applications/Utils/MeshEdit/ResetPropertiesInPolygonalRegion.cpp b/Applications/Utils/MeshEdit/ResetPropertiesInPolygonalRegion.cpp index e0455f37d12..536db8ada0f 100644 --- a/Applications/Utils/MeshEdit/ResetPropertiesInPolygonalRegion.cpp +++ b/Applications/Utils/MeshEdit/ResetPropertiesInPolygonalRegion.cpp @@ -42,8 +42,8 @@ static std::vector<bool> markNodesOutSideOfPolygon( // *** rotate mesh nodes to xy-plane // 1 copy all mesh nodes to GeoLib::Points std::vector<GeoLib::Point*> rotated_nodes; - for (std::size_t j(0); j < nodes.size(); j++) - rotated_nodes.push_back(new GeoLib::Point(*nodes[j], nodes[j]->getID())); + for (auto node : nodes) + rotated_nodes.push_back(new GeoLib::Point(*node, node->getID())); // 2 rotate the Points MathLib::DenseMatrix<double> rot_mat(3,3); GeoLib::computeRotationMatrixToXY(normal, rot_mat); @@ -61,16 +61,16 @@ static std::vector<bool> markNodesOutSideOfPolygon( } } - for (std::size_t j(0); j < rotated_nodes.size(); j++) - delete rotated_nodes[j]; + for (auto & rotated_node : rotated_nodes) + delete rotated_node; std::vector<GeoLib::Point*> & rot_polygon_pnts( const_cast<std::vector<GeoLib::Point*> &>( rot_polygon.getPointsVec() ) ); - for (std::size_t k(0); k < rot_polygon_pnts.size(); k++) - delete rot_polygon_pnts[k]; + for (auto & rot_polygon_pnt : rot_polygon_pnts) + delete rot_polygon_pnt; return outside; } diff --git a/Applications/Utils/MeshEdit/checkMesh.cpp b/Applications/Utils/MeshEdit/checkMesh.cpp index 823bf5025d6..955e97aaaf0 100644 --- a/Applications/Utils/MeshEdit/checkMesh.cpp +++ b/Applications/Utils/MeshEdit/checkMesh.cpp @@ -83,18 +83,18 @@ int main(int argc, char *argv[]) std::vector<std::string> const& vec_names (mesh->getProperties().getPropertyVectorNames()); INFO("There are %d properties in the mesh:", vec_names.size()); - for (std::size_t i=0; i<vec_names.size(); ++i) + for (const auto & vec_name : vec_names) { - auto vec_bounds (MeshLib::MeshInformation::getValueBounds<int>(*mesh, vec_names[i])); + auto vec_bounds (MeshLib::MeshInformation::getValueBounds<int>(*mesh, vec_name)); if (vec_bounds.second != std::numeric_limits<int>::max()) - INFO("\t%s: [%d, %d]", vec_names[i].c_str(), vec_bounds.first, vec_bounds.second) + INFO("\t%s: [%d, %d]", vec_name.c_str(), vec_bounds.first, vec_bounds.second) else { - auto vec_bounds (MeshLib::MeshInformation::getValueBounds<double>(*mesh, vec_names[i])); + auto vec_bounds (MeshLib::MeshInformation::getValueBounds<double>(*mesh, vec_name)); if (vec_bounds.second != std::numeric_limits<double>::max()) - INFO("\t%s: [%g, %g]", vec_names[i].c_str(), vec_bounds.first, vec_bounds.second) + INFO("\t%s: [%g, %g]", vec_name.c_str(), vec_bounds.first, vec_bounds.second) else - INFO("\t%s: Unknown properties", vec_names[i].c_str()) + INFO("\t%s: Unknown properties", vec_name.c_str()) } } diff --git a/Applications/Utils/MeshEdit/moveMeshNodes.cpp b/Applications/Utils/MeshEdit/moveMeshNodes.cpp index 7e26e05f0c8..f2795dc720d 100644 --- a/Applications/Utils/MeshEdit/moveMeshNodes.cpp +++ b/Applications/Utils/MeshEdit/moveMeshNodes.cpp @@ -98,8 +98,8 @@ int main (int argc, char* argv[]) } bool is_keyword(false); - for (std::size_t i=0; i<keywords.size(); i++) - if (current_key.compare(keywords[i])==0) + for (auto & keyword : keywords) + if (current_key.compare(keyword)==0) { is_keyword = true; break; diff --git a/FileIO/TetGenInterface.cpp b/FileIO/TetGenInterface.cpp index f4f3e5ee829..9b39bd936d4 100644 --- a/FileIO/TetGenInterface.cpp +++ b/FileIO/TetGenInterface.cpp @@ -63,8 +63,8 @@ bool TetGenInterface::readTetGenGeometry (std::string const& geo_fname, if (!readNodesFromStream (poly_stream, nodes)) { // remove nodes read until now - for (std::size_t k(0); k<nodes.size(); ++k) - delete nodes[k]; + for (auto & node : nodes) + delete node; return false; } const std::size_t nNodes (nodes.size()); @@ -184,8 +184,8 @@ bool TetGenInterface::parseSmeshFacets(std::ifstream &input, // here the poly-file potentially defines a number of region attributes, these are ignored for now std::size_t nTotalTriangles (0); - for (std::size_t i=0; i<surfaces.size(); ++i) - nTotalTriangles += surfaces[i]->getNumberOfTriangles(); + for (auto & surface : surfaces) + nTotalTriangles += surface->getNumberOfTriangles(); if (nTotalTriangles == nFacets) return true; @@ -211,8 +211,8 @@ MeshLib::Mesh* TetGenInterface::readTetGenMesh (std::string const& nodes_fname, std::vector<MeshLib::Node*> nodes; if (!readNodesFromStream (ins_nodes, nodes)) { // remove nodes read until now - for (std::size_t k(0); k<nodes.size(); k++) { - delete nodes[k]; + for (auto & node : nodes) { + delete node; } return nullptr; } @@ -221,12 +221,12 @@ MeshLib::Mesh* TetGenInterface::readTetGenMesh (std::string const& nodes_fname, std::vector<int> materials; if (!readElementsFromStream (ins_ele, elements, materials, nodes)) { // remove elements read until now - for (std::size_t k(0); k<elements.size(); k++) { - delete elements[k]; + for (auto & element : elements) { + delete element; } // remove nodes - for (std::size_t k(0); k<nodes.size(); k++) { - delete nodes[k]; + for (auto & node : nodes) { + delete node; } return nullptr; } diff --git a/GeoLib/AnalyticalGeometry.cpp b/GeoLib/AnalyticalGeometry.cpp index 13c6e3fdf35..36dab8ea84c 100644 --- a/GeoLib/AnalyticalGeometry.cpp +++ b/GeoLib/AnalyticalGeometry.cpp @@ -285,8 +285,8 @@ void rotatePointsToXZ(std::vector<GeoLib::Point*> &pnts) rotatePoints(rot_mat, pnts); } - for (std::size_t k(0); k<pnts.size(); k++) - (*(pnts[k]))[1] = 0.0; // should be -= d but there are numerical errors + for (auto & pnt : pnts) + (*pnt)[1] = 0.0; // should be -= d but there are numerical errors } std::unique_ptr<GeoLib::Point> triangleLineIntersection( diff --git a/GeoLib/GEOObjects.cpp b/GeoLib/GEOObjects.cpp index 87ee8064478..e64cc9698e8 100644 --- a/GeoLib/GEOObjects.cpp +++ b/GeoLib/GEOObjects.cpp @@ -31,14 +31,14 @@ GEOObjects::GEOObjects() GEOObjects::~GEOObjects() { // delete surfaces - for (std::size_t k(0); k < _sfc_vecs.size(); k++) - delete _sfc_vecs[k]; + for (auto & _sfc_vec : _sfc_vecs) + delete _sfc_vec; // delete polylines - for (std::size_t k(0); k < _ply_vecs.size(); k++) - delete _ply_vecs[k]; + for (auto & _ply_vec : _ply_vecs) + delete _ply_vec; // delete points - for (std::size_t k(0); k < _pnt_vecs.size(); k++) - delete _pnt_vecs[k]; + for (auto & _pnt_vec : _pnt_vecs) + delete _pnt_vec; } void GEOObjects::addPointVec( @@ -239,8 +239,8 @@ bool GEOObjects::appendSurfaceVec(const std::vector<Surface*>& surfaces, // ctor, which needs write access to the surface vector. auto sfc = std::unique_ptr<std::vector<GeoLib::Surface*>>{ new std::vector<GeoLib::Surface*>}; - for (std::size_t i = 0; i < surfaces.size(); i++) - sfc->push_back(surfaces[i]); + for (auto surface : surfaces) + sfc->push_back(surface); addSurfaceVec(std::move(sfc), name); return false; } @@ -299,8 +299,8 @@ bool GEOObjects::isUniquePointVecName(std::string &name) if (count > 1) cpName = cpName + "-" + std::to_string(count); - for (std::size_t i = 0; i < _pnt_vecs.size(); i++) - if ( cpName.compare(_pnt_vecs[i]->getName()) == 0 ) + for (auto & _pnt_vec : _pnt_vecs) + if ( cpName.compare(_pnt_vec->getName()) == 0 ) isUnique = false; } diff --git a/GeoLib/IO/Legacy/OGSIOVer4.cpp b/GeoLib/IO/Legacy/OGSIOVer4.cpp index 2d2d501c82f..19ca52502f8 100644 --- a/GeoLib/IO/Legacy/OGSIOVer4.cpp +++ b/GeoLib/IO/Legacy/OGSIOVer4.cpp @@ -425,8 +425,8 @@ std::string readSurfaces(std::istream &in, sfc_vec.push_back(sfc); } } - for (std::size_t k(0); k < polygon_vec.size(); k++) - delete polygon_vec[k]; + for (auto & k : polygon_vec) + delete k; return tag; } @@ -526,7 +526,7 @@ bool readGLIFileV4(const std::string& fname, std::size_t writeTINSurfaces(std::ofstream &os, GeoLib::SurfaceVec const* sfcs_vec, std::size_t sfc_count, std::string const& path) { const std::vector<GeoLib::Surface*>* sfcs (sfcs_vec->getVector()); - for (std::size_t k(0); k < sfcs->size(); k++) + for (auto sfc : *sfcs) { os << "#SURFACE" << "\n"; std::string sfc_name; @@ -541,7 +541,7 @@ std::size_t writeTINSurfaces(std::ofstream &os, GeoLib::SurfaceVec const* sfcs_v os << "\t\t" << sfc_name << "\n"; // create tin file sfc_name = path + sfc_name; - GeoLib::IO::TINInterface::writeSurfaceAsTIN(*(*sfcs)[k], sfc_name.c_str()); + GeoLib::IO::TINInterface::writeSurfaceAsTIN(*sfc, sfc_name.c_str()); sfc_count++; } return sfc_count; @@ -575,15 +575,15 @@ void writeGLIFileV4 (const std::string& fname, const std::vector<GeoLib::Polyline*>* plys (plys_vec->getVector()); INFO("GeoLib::writeGLIFileV4(): %d polylines to file %s.", plys->size (), fname.c_str()); - for (std::size_t k(0); k < plys->size(); k++) + for (auto ply : *plys) { os << "#POLYLINE" << "\n"; std::string polyline_name; - plys_vec->getNameOfElement((*plys)[k], polyline_name); + plys_vec->getNameOfElement(ply, polyline_name); os << " $NAME " << "\n" << " " << polyline_name << "\n"; os << " $POINTS" << "\n"; - for (std::size_t j(0); j < (*plys)[k]->getNumberOfPoints(); j++) - os << " " << ((*plys)[k])->getPointID(j) << "\n"; + for (std::size_t j(0); j < ply->getNumberOfPoints(); j++) + os << " " << ply->getPointID(j) << "\n"; } } @@ -612,10 +612,10 @@ void writeAllDataToGLIFileV4 (const std::string& fname, const GeoLib::GEOObjects // writing all points os << "#POINTS" << "\n"; - for (std::size_t j(0); j < geo_names.size(); j++) + for (auto & geo_name : geo_names) { os.precision(std::numeric_limits<double>::digits10); - GeoLib::PointVec const* const pnt_vec(geo.getPointVecObj(geo_names[j])); + GeoLib::PointVec const* const pnt_vec(geo.getPointVecObj(geo_name)); std::vector<GeoLib::Point*> const* const pnts (pnt_vec->getVector()); if (pnts) { std::string pnt_name; @@ -638,10 +638,10 @@ void writeAllDataToGLIFileV4 (const std::string& fname, const GeoLib::GEOObjects // writing all stations std::vector<std::string> stn_names; geo.getStationVectorNames (stn_names); - for (std::size_t j(0); j < stn_names.size(); j++) + for (auto & stn_name : stn_names) { os.precision(std::numeric_limits<double>::digits10); - const std::vector<GeoLib::Point*>* pnts (geo.getStationVec(stn_names[j])); + const std::vector<GeoLib::Point*>* pnts (geo.getStationVec(stn_name)); if (pnts) { for (std::size_t k(0); k < pnts->size(); k++) @@ -660,7 +660,7 @@ void writeAllDataToGLIFileV4 (const std::string& fname, const GeoLib::GEOObjects const GeoLib::PolylineVec* plys_vec (geo.getPolylineVecObj (geo_names[j])); if (plys_vec) { const std::vector<GeoLib::Polyline*>* plys (plys_vec->getVector()); - for (std::size_t k(0); k < plys->size(); k++) { + for (auto ply : *plys) { os << "#POLYLINE" << "\n"; std::string ply_name; os << " $NAME\n"; @@ -669,9 +669,9 @@ void writeAllDataToGLIFileV4 (const std::string& fname, const GeoLib::GEOObjects else os << " " << geo_names[j] << "-" << plys_cnt << "\n"; os << " $POINTS" << "\n"; - for (std::size_t l(0); l < (*plys)[k]->getNumberOfPoints(); l++) + for (std::size_t l(0); l < ply->getNumberOfPoints(); l++) os << " " << pnts_id_offset[j] + - ((*plys)[k])->getPointID(l) << "\n"; + ply->getPointID(l) << "\n"; plys_cnt++; } } @@ -679,9 +679,9 @@ void writeAllDataToGLIFileV4 (const std::string& fname, const GeoLib::GEOObjects // writing surfaces as TIN files std::size_t sfcs_cnt (0); - for (std::size_t j(0); j < geo_names.size(); j++) + for (auto & geo_name : geo_names) { - const GeoLib::SurfaceVec* sfcs_vec (geo.getSurfaceVecObj (geo_names[j])); + const GeoLib::SurfaceVec* sfcs_vec (geo.getSurfaceVecObj (geo_name)); if (sfcs_vec) sfcs_cnt += writeTINSurfaces(os, sfcs_vec, sfcs_cnt, path); } diff --git a/GeoLib/Polygon.cpp b/GeoLib/Polygon.cpp index 0dc41b4d7d9..53abbc860d8 100644 --- a/GeoLib/Polygon.cpp +++ b/GeoLib/Polygon.cpp @@ -125,9 +125,9 @@ std::vector<GeoLib::Point> Polygon::getAllIntersectionPoints( { std::vector<GeoLib::Point> intersections; GeoLib::Point s; - for (auto seg_it(begin()); seg_it != end(); ++seg_it) + for (auto&& seg_it : *this) { - if (GeoLib::lineSegmentIntersect(*seg_it, segment, s)) { + if (GeoLib::lineSegmentIntersect(seg_it, segment, s)) { intersections.push_back(s); } } @@ -308,8 +308,8 @@ void Polygon::ensureCWOrientation () // rotate copied points into x-y-plane GeoLib::rotatePointsToXY(tmp_polygon_pnts); - for (std::size_t k(0); k < tmp_polygon_pnts.size(); k++) - (*(tmp_polygon_pnts[k]))[2] = 0.0; // should be -= d but there are numerical errors + for (auto & tmp_polygon_pnt : tmp_polygon_pnts) + (*tmp_polygon_pnt)[2] = 0.0; // should be -= d but there are numerical errors // *** get the left most upper point std::size_t min_x_max_y_idx (0); // for orientation check diff --git a/GeoLib/Surface.cpp b/GeoLib/Surface.cpp index 2d448040d8d..8443f14a2a1 100644 --- a/GeoLib/Surface.cpp +++ b/GeoLib/Surface.cpp @@ -49,8 +49,8 @@ Surface::Surface(Surface const& src) Surface::~Surface() { - for (std::size_t k(0); k < _sfc_triangles.size(); k++) - delete _sfc_triangles[k]; + for (auto & _sfc_triangle : _sfc_triangles) + delete _sfc_triangle; } void Surface::addTriangle(std::size_t pnt_a, @@ -166,11 +166,11 @@ bool Surface::isPntInSfc(MathLib::Point3d const& pnt) const const Triangle* Surface::findTriangle(MathLib::Point3d const& pnt) const { - for (std::size_t k(0); k < _sfc_triangles.size(); k++) + for (auto _sfc_triangle : _sfc_triangles) { - if (_sfc_triangles[k]->containsPoint(pnt)) + if (_sfc_triangle->containsPoint(pnt)) { - return _sfc_triangles[k]; + return _sfc_triangle; } } return nullptr; diff --git a/MeshLib/MeshEditing/Mesh2MeshPropertyInterpolation.cpp b/MeshLib/MeshEditing/Mesh2MeshPropertyInterpolation.cpp index 7d63b2700fd..3512faebcd2 100644 --- a/MeshLib/MeshEditing/Mesh2MeshPropertyInterpolation.cpp +++ b/MeshLib/MeshEditing/Mesh2MeshPropertyInterpolation.cpp @@ -98,8 +98,7 @@ void Mesh2MeshPropertyInterpolation::interpolatePropertiesForMesh(Mesh *dest_mes std::size_t cnt(0); dest_properties[k] = 0.0; - for (std::size_t i(0); i<nodes.size(); ++i) { - std::vector<MeshLib::Node*> const* i_th_vec(nodes[i]); + for (auto i_th_vec : nodes) { const std::size_t n_nodes_in_vec(i_th_vec->size()); for (std::size_t j(0); j<n_nodes_in_vec; j++) { MeshLib::Node const*const j_th_node((*i_th_vec)[j]); @@ -132,8 +131,7 @@ void Mesh2MeshPropertyInterpolation::interpolatePropertiesForMesh(Mesh *dest_mes std::ofstream out_src(source_fname.c_str()); out_src << "#POINTS" << "\n"; std::size_t nodes_cnt(0); - for (std::size_t i(0); i<nodes.size(); ++i) { - std::vector<MeshLib::Node*> const* i_th_vec(nodes[i]); + for (auto i_th_vec : nodes) { const std::size_t n_nodes_in_vec(i_th_vec->size()); for (std::size_t j(0); j<n_nodes_in_vec; j++) { MeshLib::Node const*const j_th_node((*i_th_vec)[j]); diff --git a/MeshLib/MeshGenerators/MeshGenerator.cpp b/MeshLib/MeshGenerators/MeshGenerator.cpp index c9661b3e1ad..4843e1f6bf5 100644 --- a/MeshLib/MeshGenerators/MeshGenerator.cpp +++ b/MeshLib/MeshGenerators/MeshGenerator.cpp @@ -36,9 +36,9 @@ std::vector<MeshLib::Node*> MeshGenerator::generateRegularNodes( for (std::size_t j = 0; j < vec_xyz_coords[1]->size(); j++) { const double y ((*vec_xyz_coords[1])[j]+origin[1]); - for (std::size_t k = 0; k < vec_xyz_coords[0]->size(); k++) + for (double const x : *vec_xyz_coords[0]) { - nodes.push_back (new Node((*vec_xyz_coords[0])[k]+origin[0], y, z)); + nodes.push_back (new Node(x+origin[0], y, z)); } } } diff --git a/MeshLib/MeshQuality/MeshValidation.cpp b/MeshLib/MeshQuality/MeshValidation.cpp index 9dc94d61c30..a329f7ff105 100644 --- a/MeshLib/MeshQuality/MeshValidation.cpp +++ b/MeshLib/MeshQuality/MeshValidation.cpp @@ -43,8 +43,8 @@ MeshValidation::MeshValidation(MeshLib::Mesh &mesh) const std::vector<ElementErrorCode> codes (this->testElementGeometry(mesh)); std::array<std::string, static_cast<std::size_t>(ElementErrorFlag::MaxValue)> output_str (this->ElementErrorCodeOutput(codes)); - for (std::size_t i = 0; i < output_str.size(); ++i) - INFO (output_str[i].c_str()); + for (auto & i : output_str) + INFO (i.c_str()); } std::vector<ElementErrorCode> MeshValidation::testElementGeometry(const MeshLib::Mesh &mesh, double min_volume) diff --git a/Tests/BaseLib/TestQuicksort.cpp b/Tests/BaseLib/TestQuicksort.cpp index 5afa8255b26..bdf2057852d 100644 --- a/Tests/BaseLib/TestQuicksort.cpp +++ b/Tests/BaseLib/TestQuicksort.cpp @@ -127,8 +127,8 @@ TEST_F(BaseLibQuicksort, ReportCorrectPermutationsWithPointer) std::iota(perm.begin(), perm.end(), 0); std::vector<int*> p_xs; - for (std::size_t i=0; i<xs.size(); ++i) - p_xs.push_back(&xs[i]); + for (int & x : xs) + p_xs.push_back(&x); BaseLib::quicksort(p_xs, 0, p_xs.size(), perm); @@ -199,8 +199,8 @@ TEST_F(BaseLibQuicksort, ReportCorrectPermutationsReverseWithPointer) std::iota(perm.begin(), perm.end(), 0); std::vector<int*> p_xs; - for (std::size_t i=0; i<xs.size(); ++i) - p_xs.push_back(&xs[i]); + for (int & x : xs) + p_xs.push_back(&x); BaseLib::quicksort(p_xs, 0, p_xs.size(), perm); diff --git a/Tests/FileIO/TestCsvReader.cpp b/Tests/FileIO/TestCsvReader.cpp index f70fbe96071..be85b8c58f6 100644 --- a/Tests/FileIO/TestCsvReader.cpp +++ b/Tests/FileIO/TestCsvReader.cpp @@ -114,8 +114,8 @@ TEST_F(CsvInterfaceTest, Points2D) _result = GeoLib::IO::CsvInterface::readPoints(_file_name, '\t', points, "x", "y"); ASSERT_EQ(0, _result); ASSERT_EQ(10, points.size()); - for (std::size_t i=0; i<points.size(); ++i) - ASSERT_NEAR(0, (*points[i])[2], std::numeric_limits<double>::epsilon()); + for (auto & point : points) + ASSERT_NEAR(0, (*point)[2], std::numeric_limits<double>::epsilon()); for (auto p : points) delete p; } diff --git a/Tests/GeoLib/TestPolygon.cpp b/Tests/GeoLib/TestPolygon.cpp index ce250a8135c..51281c82ba6 100644 --- a/Tests/GeoLib/TestPolygon.cpp +++ b/Tests/GeoLib/TestPolygon.cpp @@ -67,8 +67,8 @@ public: ~PolygonTest() { delete _polygon; - for (std::size_t k(0); k<_pnts.size(); k++) - delete _pnts[k]; + for (auto & _pnt : _pnts) + delete _pnt; } protected: @@ -78,8 +78,8 @@ protected: TEST_F(PolygonTest, isPntInPolygonCheckCorners) { - for (std::size_t k(0); k<_pnts.size(); k++) - EXPECT_TRUE(_polygon->isPntInPolygon(*_pnts[k])); + for (auto & _pnt : _pnts) + EXPECT_TRUE(_polygon->isPntInPolygon(*_pnt)); } TEST_F(PolygonTest, isPntInPolygonCheckPointsRestOnPolygonEdges) @@ -146,10 +146,9 @@ TEST_F(PolygonTest, containsSegment) } // test all segments of polygon - for (auto segment_it(_polygon->begin()); segment_it != _polygon->end(); - ++segment_it) + for (auto && segment_it : *_polygon) { - EXPECT_TRUE(_polygon->containsSegment(*segment_it)); + EXPECT_TRUE(_polygon->containsSegment(segment_it)); } { // 70 @@ -191,8 +190,8 @@ TEST_F(PolygonTest, isPolylineInPolygon) outer_ply.addPoint(0); outer_ply.addPoint(1); ASSERT_FALSE(_polygon->isPolylineInPolygon(outer_ply)); - for (std::size_t k(0); k<pnts.size(); k++) - delete pnts[k]; + for (auto & pnt : pnts) + delete pnt; pnts.clear(); pnts.push_back(new GeoLib::Point(-1.0,2.0,0.0)); // 3 @@ -201,8 +200,8 @@ TEST_F(PolygonTest, isPolylineInPolygon) inner_ply.addPoint(0); inner_ply.addPoint(1); ASSERT_TRUE(_polygon->isPolylineInPolygon(inner_ply)); - for (std::size_t k(0); k<pnts.size(); k++) - delete pnts[k]; + for (auto & pnt : pnts) + delete pnt; } TEST_F(PolygonTest, CopyConstructor) diff --git a/Tests/GeoLib/TestPolyline.cpp b/Tests/GeoLib/TestPolyline.cpp index 6265c9a17f9..9768c93cfe2 100644 --- a/Tests/GeoLib/TestPolyline.cpp +++ b/Tests/GeoLib/TestPolyline.cpp @@ -109,6 +109,6 @@ TEST(GeoLib, PolylineTest) } ASSERT_EQ(ply.getNumberOfSegments(), segment_cnt); - for (std::size_t k(0); k < ply_pnts.size(); ++k) - delete ply_pnts[k]; + for (auto & ply_pnt : ply_pnts) + delete ply_pnt; } diff --git a/Tests/GeoLib/TestSimplePolygonTree.cpp b/Tests/GeoLib/TestSimplePolygonTree.cpp index 73e2ac157a6..06470a991f1 100644 --- a/Tests/GeoLib/TestSimplePolygonTree.cpp +++ b/Tests/GeoLib/TestSimplePolygonTree.cpp @@ -92,8 +92,8 @@ public: delete _p1; delete _p2; delete _p3; - for (std::size_t k(0); k<_pnts.size(); k++) - delete _pnts[k]; + for (auto & _pnt : _pnts) + delete _pnt; } protected: diff --git a/Tests/MeshLib/TestAddLayerToMesh.cpp b/Tests/MeshLib/TestAddLayerToMesh.cpp index 47749ec987d..f31624f6e57 100644 --- a/Tests/MeshLib/TestAddLayerToMesh.cpp +++ b/Tests/MeshLib/TestAddLayerToMesh.cpp @@ -31,9 +31,9 @@ namespace AddLayerValidation ElementErrorFlag const flags[nErrorFlags] = {ElementErrorFlag::ZeroVolume, ElementErrorFlag::NonCoplanar, ElementErrorFlag::NonConvex, ElementErrorFlag::NodeOrder}; std::vector<ElementErrorCode> const codes (MeshLib::MeshValidation::testElementGeometry(mesh)); - for (std::size_t i=0; i<codes.size(); ++i) + for (auto code : codes) for (std::size_t j=0; j<nErrorFlags-reduce_tests; ++j) - ASSERT_FALSE(codes[i][flags[j]]); + ASSERT_FALSE(code[flags[j]]); } void testZCoords2D(MeshLib::Mesh const& input, MeshLib::Mesh const& output, double height) -- GitLab