From: Mikko Rasa Date: Sat, 25 Jan 2025 23:21:37 +0000 (+0200) Subject: Use range-based for loops where appropriate X-Git-Url: https://git.tdb.fi/?a=commitdiff_plain;h=a8b8337aeb5b4fde8af525eb5b11bea9b8e7787c;p=libs%2Fmath.git Use range-based for loops where appropriate --- diff --git a/source/geometry/compositeshape.h b/source/geometry/compositeshape.h index 0baa579..012c390 100644 --- a/source/geometry/compositeshape.h +++ b/source/geometry/compositeshape.h @@ -66,8 +66,8 @@ template inline void CompositeShape::init() { max_isect = 0; - for(typename ShapeArray::const_iterator i=shapes.begin(); i!=shapes.end(); ++i) - max_isect += (*i)->get_max_ray_intersections(); + for(Shape *s: shapes) + max_isect += s->get_max_ray_intersections(); } template @@ -75,19 +75,19 @@ inline CompositeShape::CompositeShape(const CompositeShape &ot shapes(other.shapes), max_isect(other.max_isect) { - for(typename ShapeArray::iterator i=shapes.begin(); i!=shapes.end(); ++i) - *i = (*i)->clone(); + for(Shape *&s: shapes) + s = s->clone(); } template inline CompositeShape &CompositeShape::operator=(const CompositeShape &other) { - for(typename ShapeArray::iterator i=shapes.begin(); i!=shapes.end(); ++i) - delete *i; + for(Shape *s: shapes) + delete s; shapes = other.shapes; - for(typename ShapeArray::iterator i=shapes.begin(); i!=shapes.end(); ++i) - *i = (*i)->clone(); + for(Shape *&s: shapes) + s = s->clone(); max_isect = other.max_isect; } @@ -95,8 +95,8 @@ inline CompositeShape &CompositeShape::operator=(const Composi template inline CompositeShape::~CompositeShape() { - for(typename ShapeArray::iterator i=shapes.begin(); i!=shapes.end(); ++i) - delete *i; + for(Shape *s: shapes) + delete s; } template @@ -106,7 +106,7 @@ inline BoundingBox CompositeShape::get_axis_aligned_bounding_box( return this->bisect_axis_aligned_bounding_box(detail); BoundingBox aabb; - for(typename ShapeArray::const_iterator i=shapes.begin(); i!=shapes.end(); ++i) + for(auto i=shapes.begin(); i!=shapes.end(); ++i) { if(i==shapes.begin()) aabb = (*i)->get_axis_aligned_bounding_box(); @@ -120,9 +120,9 @@ template inline bool CompositeShape::contains(const LinAl::Vector &point) const { bool inside = false; - for(typename ShapeArray::const_iterator i=shapes.begin(); i!=shapes.end(); ++i) + for(Shape *s: shapes) { - inside = (*i)->contains(point); + inside = s->contains(point); if(Ops::shortcircuit(inside)) return inside; } @@ -142,7 +142,7 @@ inline unsigned CompositeShape::get_intersections(const Ray &ray, int start_nesting = 0; unsigned n = 0; - for(typename ShapeArray::const_iterator i=shapes.begin(); (nget_intersections(ray, buffer+base, buf_size-base); @@ -198,7 +198,7 @@ template inline Coverage CompositeShape::get_coverage(const BoundingBox &bbox) const { Coverage coverage = NO_COVERAGE; - for(typename ShapeArray::const_iterator i=shapes.begin(); i!=shapes.end(); ++i) + for(auto i=shapes.begin(); i!=shapes.end(); ++i) { Coverage c = (*i)->get_coverage(bbox); if(i==shapes.begin()) diff --git a/source/geometry/loader.h b/source/geometry/loader.h index c5d7e56..6b03bbb 100644 --- a/source/geometry/loader.h +++ b/source/geometry/loader.h @@ -195,8 +195,8 @@ inline DimensionIndependentLoader::DimensionIndependentLoader(bool s): template inline DimensionIndependentLoader::~DimensionIndependentLoader() { - for(typename std::list *>::iterator i=shapes.begin(); i!=shapes.end(); ++i) - delete *i; + for(Shape *s: shapes) + delete s; } template