1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>Range adaptors</title> 5<link rel="stylesheet" href="../../../../../../../doc/src/boostbook.css" type="text/css"> 6<meta name="generator" content="DocBook XSL Stylesheets V1.79.1"> 7<link rel="home" href="../../../index.html" title="Chapter 1. Geometry"> 8<link rel="up" href="../rtree_examples.html" title="Examples"> 9<link rel="prev" href="using_indexablegetter_function_object___storing_indexes_of_external_container_s_elements.html" title="Using IndexableGetter function object - storing indexes of external container's elements"> 10<link rel="next" href="iterative_query.html" title="Iterative query"> 11</head> 12<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> 13<table cellpadding="2" width="100%"><tr> 14<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../boost.png"></td> 15<td align="center"><a href="../../../../../../../index.html">Home</a></td> 16<td align="center"><a href="../../../../../../../libs/libraries.htm">Libraries</a></td> 17<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td> 18<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td> 19<td align="center"><a href="../../../../../../../more/index.htm">More</a></td> 20</tr></table> 21<hr> 22<div class="spirit-nav"> 23<a accesskey="p" href="using_indexablegetter_function_object___storing_indexes_of_external_container_s_elements.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../rtree_examples.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="iterative_query.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a> 24</div> 25<div class="section"> 26<div class="titlepage"><div><div><h4 class="title"> 27<a name="geometry.spatial_indexes.rtree_examples.range_adaptors"></a><a class="link" href="range_adaptors.html" title="Range adaptors">Range 28 adaptors</a> 29</h4></div></div></div> 30<p> 31</p> 32<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">geometry</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> 33<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">geometry</span><span class="special">/</span><span class="identifier">geometries</span><span class="special">/</span><span class="identifier">point</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> 34<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">geometry</span><span class="special">/</span><span class="identifier">geometries</span><span class="special">/</span><span class="identifier">box</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> 35 36<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">geometry</span><span class="special">/</span><span class="identifier">index</span><span class="special">/</span><span class="identifier">rtree</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> 37 38<span class="comment">// Boost.Range</span> 39<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">range</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> 40<span class="comment">// adaptors</span> 41<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">range</span><span class="special">/</span><span class="identifier">adaptor</span><span class="special">/</span><span class="identifier">indexed</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> 42<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">range</span><span class="special">/</span><span class="identifier">adaptor</span><span class="special">/</span><span class="identifier">transformed</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> 43 44<span class="comment">// a container</span> 45<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">vector</span><span class="special">></span> 46 47<span class="comment">// just for output</span> 48<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">iostream</span><span class="special">></span> 49 50<span class="keyword">namespace</span> <span class="identifier">bg</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">geometry</span><span class="special">;</span> 51<span class="keyword">namespace</span> <span class="identifier">bgi</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">geometry</span><span class="special">::</span><span class="identifier">index</span><span class="special">;</span> 52 53<span class="comment">// Define a function object converting a value_type of indexed Range into std::pair<>.</span> 54<span class="comment">// This is a generic implementation but of course it'd be possible to use some</span> 55<span class="comment">// specific types. One could also take Value as template parameter and access</span> 56<span class="comment">// first_type and second_type members, etc.</span> 57<span class="keyword">template</span> <span class="special"><</span><span class="keyword">typename</span> <span class="identifier">First</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Second</span><span class="special">></span> 58<span class="keyword">struct</span> <span class="identifier">pair_maker</span> 59<span class="special">{</span> 60 <span class="keyword">typedef</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">pair</span><span class="special"><</span><span class="identifier">First</span><span class="special">,</span> <span class="identifier">Second</span><span class="special">></span> <span class="identifier">result_type</span><span class="special">;</span> 61 <span class="keyword">template</span><span class="special"><</span><span class="keyword">typename</span> <span class="identifier">T</span><span class="special">></span> 62 <span class="keyword">inline</span> <span class="identifier">result_type</span> <span class="keyword">operator</span><span class="special">()(</span><span class="identifier">T</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">v</span><span class="special">)</span> <span class="keyword">const</span> 63 <span class="special">{</span> 64 <span class="keyword">return</span> <span class="identifier">result_type</span><span class="special">(</span><span class="identifier">v</span><span class="special">.</span><span class="identifier">value</span><span class="special">(),</span> <span class="identifier">v</span><span class="special">.</span><span class="identifier">index</span><span class="special">());</span> 65 <span class="special">}</span> 66<span class="special">};</span> 67 68<span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span> 69<span class="special">{</span> 70 <span class="keyword">typedef</span> <span class="identifier">bg</span><span class="special">::</span><span class="identifier">model</span><span class="special">::</span><span class="identifier">point</span><span class="special"><</span><span class="keyword">float</span><span class="special">,</span> <span class="number">2</span><span class="special">,</span> <span class="identifier">bg</span><span class="special">::</span><span class="identifier">cs</span><span class="special">::</span><span class="identifier">cartesian</span><span class="special">></span> <span class="identifier">point</span><span class="special">;</span> 71 <span class="keyword">typedef</span> <span class="identifier">bg</span><span class="special">::</span><span class="identifier">model</span><span class="special">::</span><span class="identifier">box</span><span class="special"><</span><span class="identifier">point</span><span class="special">></span> <span class="identifier">box</span><span class="special">;</span> 72 73 <span class="keyword">typedef</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special"><</span><span class="identifier">box</span><span class="special">></span> <span class="identifier">container</span><span class="special">;</span> 74 <span class="keyword">typedef</span> <span class="identifier">container</span><span class="special">::</span><span class="identifier">size_type</span> <span class="identifier">size_type</span><span class="special">;</span> 75 76 <span class="keyword">typedef</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">pair</span><span class="special"><</span><span class="identifier">box</span><span class="special">,</span> <span class="identifier">size_type</span><span class="special">></span> <span class="identifier">value</span><span class="special">;</span> 77 78 <span class="comment">// create a container of boxes</span> 79 <span class="identifier">container</span> <span class="identifier">boxes</span><span class="special">;</span> 80 <span class="keyword">for</span> <span class="special">(</span> <span class="identifier">size_type</span> <span class="identifier">i</span> <span class="special">=</span> <span class="number">0</span> <span class="special">;</span> <span class="identifier">i</span> <span class="special"><</span> <span class="number">10</span> <span class="special">;</span> <span class="special">++</span><span class="identifier">i</span> <span class="special">)</span> 81 <span class="special">{</span> 82 <span class="comment">// add a box into the container</span> 83 <span class="identifier">box</span> <span class="identifier">b</span><span class="special">(</span><span class="identifier">point</span><span class="special">(</span><span class="identifier">i</span> <span class="special">+</span> <span class="number">0.0f</span><span class="special">,</span> <span class="identifier">i</span> <span class="special">+</span> <span class="number">0.0f</span><span class="special">),</span> <span class="identifier">point</span><span class="special">(</span><span class="identifier">i</span> <span class="special">+</span> <span class="number">0.5f</span><span class="special">,</span> <span class="identifier">i</span> <span class="special">+</span> <span class="number">0.5f</span><span class="special">));</span> 84 <span class="identifier">boxes</span><span class="special">.</span><span class="identifier">push_back</span><span class="special">(</span><span class="identifier">b</span><span class="special">);</span> 85 <span class="special">}</span> 86 87 <span class="comment">// create the rtree passing a Range</span> 88 <span class="identifier">bgi</span><span class="special">::</span><span class="identifier">rtree</span><span class="special"><</span> <span class="identifier">value</span><span class="special">,</span> <span class="identifier">bgi</span><span class="special">::</span><span class="identifier">quadratic</span><span class="special"><</span><span class="number">16</span><span class="special">></span> <span class="special">></span> 89 <span class="identifier">rtree</span><span class="special">(</span><span class="identifier">boxes</span> <span class="special">|</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">adaptors</span><span class="special">::</span><span class="identifier">indexed</span><span class="special">()</span> 90 <span class="special">|</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">adaptors</span><span class="special">::</span><span class="identifier">transformed</span><span class="special">(</span><span class="identifier">pair_maker</span><span class="special"><</span><span class="identifier">box</span><span class="special">,</span> <span class="identifier">size_type</span><span class="special">>()));</span> 91 92 <span class="comment">// print the number of values using boxes[0] as indexable</span> 93 <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">rtree</span><span class="special">.</span><span class="identifier">count</span><span class="special">(</span><span class="identifier">boxes</span><span class="special">[</span><span class="number">0</span><span class="special">])</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> 94 95 <span class="keyword">return</span> <span class="number">0</span><span class="special">;</span> 96<span class="special">}</span> 97</pre> 98<p> 99 </p> 100<h5> 101<a name="geometry.spatial_indexes.rtree_examples.range_adaptors.h0"></a> 102 <span class="phrase"><a name="geometry.spatial_indexes.rtree_examples.range_adaptors.expected_results"></a></span><a class="link" href="range_adaptors.html#geometry.spatial_indexes.rtree_examples.range_adaptors.expected_results">Expected 103 results</a> 104 </h5> 105<pre class="programlisting"><span class="number">1</span> 106</pre> 107</div> 108<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 109<td align="left"></td> 110<td align="right"><div class="copyright-footer">Copyright © 2009-2019 Barend Gehrels, Bruno Lalande, Mateusz Loskot, Adam 111 Wulkiewicz, Oracle and/or its affiliates<p> 112 Distributed under the Boost Software License, Version 1.0. (See accompanying 113 file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>) 114 </p> 115</div></td> 116</tr></table> 117<hr> 118<div class="spirit-nav"> 119<a accesskey="p" href="using_indexablegetter_function_object___storing_indexes_of_external_container_s_elements.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../rtree_examples.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="iterative_query.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a> 120</div> 121</body> 122</html> 123