Hi Hussein,

Hussein Almashouq wrote:
Hi to all I'm using the rtree*  to load  1M > data points . Then  I use the rtree query to different intersection query  like 

found +=rtree.query(bgi::intersects(qbox), std::back_inserter(result));

currently I'm interested in getting the count of results rather than inserting into the result vector 

I have to two question 

1. is possible to skip std::back_inserter step and do a query that finds the count only.
2. How can improve the performance of the  std::back_inserter methods as my results are N^2 where N > 1M usually . ( check this post https://pkisensee.wordpress.com/2011/06/02/efficient-stl-insertion-tip-of-the-month/)

To count the elements meeting the predicate or do something else for each element without the creation of the result container you can use:

1. boost::function_output_iterator
// using C++11 lambda expression, in C++98 you can pass a function object
size_t counter = 0;
rtree.query(bgi::intersects(box),
            boost::make_function_output_iterator(
                [&](Value const&) {
                    counter++;
                }));
2. query iterator

size_t count = std::distance(tree.qbegin(intersects(box)), tree.qend());

Regards,
Adam