Boost C++ Libraries: Ticket #11113: Support easy enumeration of all elements with BOOST_FOREACH https://svn.boost.org/trac10/ticket/11113 <pre class="wiki">using namespace boost::geometry; typedef model::d2::point_xy&lt;double&gt; point2_t; index::rtree&lt;point2_t, index::quadratic&lt;16&gt;&gt; tree; BOOST_FOREACH(point2_t const&amp; pt, tree) { std::cout &lt;&lt; wkt(pt) &lt;&lt; std::endl; } </pre><p> Alternatively provide a predicate <code>bgi:all</code> that returns all elements and can be used with the <code>queried</code> adaptor. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/11113 Trac 1.4.3 Barend Gehrels Fri, 20 Mar 2015 12:52:06 GMT owner changed https://svn.boost.org/trac10/ticket/11113#comment:1 https://svn.boost.org/trac10/ticket/11113#comment:1 <ul> <li><strong>owner</strong> changed from <span class="trac-author">Barend Gehrels</span> to <span class="trac-author">awulkiew</span> </li> </ul> Ticket awulkiew Sat, 04 Apr 2015 18:47:21 GMT status changed; keywords, resolution set https://svn.boost.org/trac10/ticket/11113#comment:2 https://svn.boost.org/trac10/ticket/11113#comment:2 <ul> <li><strong>keywords</strong> rtree iterator range for added </li> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> Thanks for the suggestion! </p> <p> Boost.Foreach and Boost.Range is now supported in develop branch and will be in Boost 1.59. I added <code>const_iterator</code>, <code>begin()</code> and <code>end()</code> members to the rtree. The category of iterator is <a class="missing wiki">ForwardIterator</a> so the rtree is now adapted to (const) <a class="missing wiki">ForwardRange</a> concept. It should be possible to adapt it to <a class="missing wiki">BidirectionalRange</a> so if this was needed, just let me know. </p> <p> Unfortunately the thing with <code>queried()</code> adaptor is more complicated. Currently it isn't a lazy-range but a container (wrapped <code>std::vector</code>). If it was used to iterate over all values stored in the rtree all of them would be copied into this container. I probably shouldn't change it to lazy-range now since currently it's a <a class="missing wiki">RandomAccessRange</a> so e.g. it can be sorted, etc. A lazy-range would be <a class="missing wiki">ForwardRange</a>, this could be a breaking change. But if you think it should be done please write a suggestion e.g. on the mailing list so we could discuss. I plan to fix it by implementing the "new" <code>view::query()</code> and <code>cont::query()</code> adaptors (currently a proposal so I'm waiting for the committee to know what names I could use) and deprecating the <code>queried()</code> adaptor. </p> <p> For now (Boost &lt;= 1.58) I propose a workaround. You could create a range representing all of the values stored in the rtree by yourself. You need to pass <code>bgi::satisfies()</code> predicate with a <a class="missing wiki">UnaryFunction</a> always returning <code>true</code> into <code>qbegin()</code>. Well, there may be a problem, until now <code>const_query_iterator</code> was <a class="missing wiki">InputIterator</a>. This might cause problems in some cases, e.g. related to Boost.Range concept checks. Besides the change you proposed I also upgraded <code>const_query_iterator</code> to <a class="missing wiki">ForwardIterator</a>. But, I think that something like this could work: </p> <pre class="wiki">struct always_true { template &lt;typename T&gt; bool operator()(T const&amp;) const { return true; } }; // Return a range containing all Rtree elements template &lt;typename Rtree&gt; std::pair &lt; typename Rtree::const_query_iterator, typename Rtree::const_query_iterator &gt; all(Rtree const&amp; tree) { return std::make_pair(tree.qbegin(bgi::satisfies(always_true())), tree.qend()); } /*...*/ BOOST_FOREACH(point2_t const&amp; pt, all(tree)) { // ... } </pre> Ticket awulkiew Sun, 26 Apr 2015 14:21:46 GMT milestone changed https://svn.boost.org/trac10/ticket/11113#comment:3 https://svn.boost.org/trac10/ticket/11113#comment:3 <ul> <li><strong>milestone</strong> <span class="trac-field-old">To Be Determined</span> → <span class="trac-field-new">Boost 1.59.0</span> </li> </ul> Ticket