Skip to content

use auto instead of iterator types, and related #1129

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions include/boost/geometry/algorithms/append.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,15 @@ struct to_polygon_point
signed_size_type ring_index, signed_size_type = 0)
{
using ring_type = typename ring_type<Polygon>::type;
using exterior_ring_type = typename ring_return_type<Polygon>::type;
using interior_ring_range_type = typename interior_return_type<Polygon>::type;

if (ring_index == -1)
{
exterior_ring_type ext_ring = exterior_ring(polygon);
auto&& ext_ring = exterior_ring(polygon);
to_range_point::apply<ring_type, Point>(ext_ring, point);
}
else if (ring_index < signed_size_type(num_interior_rings(polygon)))
{
interior_ring_range_type int_rings = interior_rings(polygon);
auto&& int_rings = interior_rings(polygon);
to_range_point::apply<ring_type, Point>(range::at(int_rings, ring_index), point);
}
}
Expand Down
16 changes: 5 additions & 11 deletions include/boost/geometry/algorithms/centroid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
#include <boost/geometry/algorithms/assign.hpp>
#include <boost/geometry/algorithms/convert.hpp>
#include <boost/geometry/algorithms/detail/centroid/translating_transformer.hpp>
#include <boost/geometry/algorithms/detail/interior_iterator.hpp>
#include <boost/geometry/algorithms/detail/point_on_border.hpp>
#include <boost/geometry/algorithms/detail/visit.hpp>
#include <boost/geometry/algorithms/is_empty.hpp>
Expand Down Expand Up @@ -255,11 +254,9 @@ struct centroid_polygon_state
{
centroid_range_state::apply(exterior_ring(poly), transformer, strategy, state);

typename interior_return_type<Polygon const>::type
rings = interior_rings(poly);

for (typename detail::interior_iterator<Polygon const>::type
it = boost::begin(rings); it != boost::end(rings); ++it)
auto const& rings = interior_rings(poly);
auto const end = boost::end(rings);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reason of copying here and not just using it as boost::end(rings) inside for loop as you are doing below?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's done elsewhere as well, for rings.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this is the reason but the effect is that end will not be calculated at the end of each iteration.

for (auto it = boost::begin(rings); it != end; ++it)
{
centroid_range_state::apply(*it, transformer, strategy, state);
}
Expand Down Expand Up @@ -352,15 +349,12 @@ struct centroid_multi
Point
>::type state;

for (typename boost::range_iterator<Multi const>::type
it = boost::begin(multi);
it != boost::end(multi);
++it)
for (auto it = boost::begin(multi); it != boost::end(multi); ++it)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NOTE: we cannot do a range based for loop here
(as @awulkiew pointed out once).

In some places I changed it to a range based for loop, but these places are internal (for example turns).

{
Policy::apply(*it, transformer, strategy, state);
}

if ( strategy.result(state, centroid) )
if (strategy.result(state, centroid))
{
// translate the result back
transformer.apply_reverse(centroid);
Expand Down
24 changes: 8 additions & 16 deletions include/boost/geometry/algorithms/convert.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
#include <boost/geometry/algorithms/detail/assign_indexed_point.hpp>
#include <boost/geometry/algorithms/detail/convert_point_to_point.hpp>
#include <boost/geometry/algorithms/detail/convert_indexed_to_indexed.hpp>
#include <boost/geometry/algorithms/detail/interior_iterator.hpp>
#include <boost/geometry/algorithms/not_implemented.hpp>

#include <boost/geometry/arithmetic/arithmetic.hpp>
Expand Down Expand Up @@ -128,7 +127,7 @@ struct segment_to_range
{
traits::resize<Range>::apply(range, 2);

typename boost::range_iterator<Range>::type it = boost::begin(range);
auto it = boost::begin(range);

assign_point_from_index<0>(segment, *it);
++it;
Expand Down Expand Up @@ -186,8 +185,7 @@ struct range_to_range
// but ok, sice below it == end()

size_type i = 0;
for (typename boost::range_iterator<view_type const>::type it
= boost::begin(view);
for (auto it = boost::begin(view);
it != boost::end(view) && i < n;
++it, ++i)
{
Expand Down Expand Up @@ -227,15 +225,11 @@ struct polygon_to_polygon
>::type
>::apply(interior_rings(destination), num_interior_rings(source));

typename interior_return_type<Polygon1 const>::type
rings_source = interior_rings(source);
typename interior_return_type<Polygon2>::type
rings_dest = interior_rings(destination);
auto const& rings_source = interior_rings(source);
auto&& rings_dest = interior_rings(destination);

typename detail::interior_iterator<Polygon1 const>::type
it_source = boost::begin(rings_source);
typename detail::interior_iterator<Polygon2>::type
it_dest = boost::begin(rings_dest);
auto it_source = boost::begin(rings_source);
auto it_dest = boost::begin(rings_dest);

for ( ; it_source != boost::end(rings_source); ++it_source, ++it_dest)
{
Expand Down Expand Up @@ -263,10 +257,8 @@ struct multi_to_multi: private Policy
{
traits::resize<Multi2>::apply(multi2, boost::size(multi1));

typename boost::range_iterator<Multi1 const>::type it1
= boost::begin(multi1);
typename boost::range_iterator<Multi2>::type it2
= boost::begin(multi2);
auto it1 = boost::begin(multi1);
auto it2 = boost::begin(multi2);

for (; it1 != boost::end(multi1); ++it1, ++it2)
{
Expand Down
1 change: 0 additions & 1 deletion include/boost/geometry/algorithms/correct.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

#include <boost/geometry/algorithms/area.hpp>
#include <boost/geometry/algorithms/correct_closure.hpp>
#include <boost/geometry/algorithms/detail/interior_iterator.hpp>
#include <boost/geometry/algorithms/detail/multi_modify.hpp>
#include <boost/geometry/algorithms/detail/visit.hpp>

Expand Down
1 change: 0 additions & 1 deletion include/boost/geometry/algorithms/correct_closure.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

#include <cstddef>

#include <boost/geometry/algorithms/detail/interior_iterator.hpp>
#include <boost/geometry/algorithms/detail/multi_modify.hpp>
#include <boost/geometry/algorithms/disjoint.hpp>

Expand Down
12 changes: 5 additions & 7 deletions include/boost/geometry/algorithms/densify.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,10 @@ struct densify_range
static inline void apply(FwdRng const& rng, MutRng & rng_out,
T const& len, Strategies const& strategies)
{
typedef typename boost::range_iterator<FwdRng const>::type iterator_t;
typedef typename boost::range_value<FwdRng>::type point_t;

iterator_t it = boost::begin(rng);
iterator_t end = boost::end(rng);
auto it = boost::begin(rng);
auto const end = boost::end(rng);

if (it == end) // empty(rng)
{
Expand All @@ -92,7 +91,7 @@ struct densify_range
auto strategy = strategies.densify(rng);
push_back_policy<MutRng> policy(rng_out);

iterator_t prev = it;
auto prev = it;
for ( ++it ; it != end ; prev = it++)
{
point_t const& p0 = *prev;
Expand Down Expand Up @@ -123,9 +122,8 @@ struct densify_ring
if (boost::size(ring) <= 1)
return;

typedef typename point_type<Geometry>::type point_t;
point_t const& p0 = range::back(ring);
point_t const& p1 = range::front(ring);
auto const& p0 = range::back(ring);
auto const& p1 = range::front(ring);

auto strategy = strategies.densify(ring);
push_back_policy<GeometryOut> policy(ring_out);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,10 +354,7 @@ struct buffer_multi
RobustPolicy const& robust_policy,
Strategies const& strategies)
{
for (typename boost::range_iterator<Multi const>::type
it = boost::begin(multi);
it != boost::end(multi);
++it)
for (auto it = boost::begin(multi); it != boost::end(multi); ++it)
{
Policy::apply(*it, collection,
distance_strategy, segment_strategy,
Expand Down
Loading