Boost logo

Geometry :

Subject: [geometry] Are all query iterators const?
From: Hal Clark (hdeanclark_at_[hidden])
Date: 2015-09-02 13:54:26


I'm new to Boost.Geometry and have recently discovered the
rtree::qbegin()/qend() mechanism. It is useful (thanks!) but the
iterators are all marked const. Is it possible to get non-const
iterators without mucking about with const_cast? (I see
rtree::begin()/end() are new between 1.57.0 and 1.58.0 -- hopefully
non-const qbegin()/qend() follow more easily.)

---
My use case is as follows. I'm implementing some point clustering
algorithms. My point primitive has a 'ClusterID' attribute member, and
something like a (fat) user-defined boost::any. Because the point is
not cheap to copy, I'm iterating over nearest neighbours and marking
the ClusterID in-place using something like this:
        //Using Boost version 1.57.0.
        ...
        RTree_t::const_query_iterator it;
        it = rtree.qbegin(boost::geometry::index::satisfies(
            [](const MyPoint &) -> bool { return true; } )
        );
        for( ; it != rtree.qend(); ++it){
            //it->ClusterID = -1; //Compilation error: disregards const.
            const_cast<MyPoint &>(*it).ClusterID = -1;
        }
First: my understanding is that because the spatial coordinates are
not altered the const_cast is valid. Is this correct?
Second: can something like the back_inserter interface be created that
won't copy the matching points? non-const query_iterators would be
nice. I don't understand the rationale for, or distinction between,
query_iterator, spatial_query_iterator, distance_query_iterator, but
presumably they are all non-const candidates.
-hal clark

Geometry list run by mateusz at loskot.net