Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:35:34

0001 // Boost.Geometry Index
0002 //
0003 // R-tree implementation
0004 //
0005 // Copyright (c) 2008 Federico J. Fernandez.
0006 // Copyright (c) 2011-2023 Adam Wulkiewicz, Lodz, Poland.
0007 // Copyright (c) 2020 Caian Benedicto, Campinas, Brazil.
0008 //
0009 // This file was modified by Oracle on 2019-2021.
0010 // Modifications copyright (c) 2019-2021 Oracle and/or its affiliates.
0011 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
0012 //
0013 // Use, modification and distribution is subject to the Boost Software License,
0014 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
0015 // http://www.boost.org/LICENSE_1_0.txt)
0016 
0017 #ifndef BOOST_GEOMETRY_INDEX_RTREE_HPP
0018 #define BOOST_GEOMETRY_INDEX_RTREE_HPP
0019 
0020 // STD
0021 #include <algorithm>
0022 #include <type_traits>
0023 
0024 // Boost
0025 #include <boost/container/new_allocator.hpp>
0026 #include <boost/tuple/tuple.hpp>
0027 #include <boost/core/invoke_swap.hpp>
0028 
0029 // Boost.Geometry
0030 #include <boost/geometry/core/static_assert.hpp>
0031 
0032 #include <boost/geometry/algorithms/detail/comparable_distance/interface.hpp>
0033 #include <boost/geometry/algorithms/detail/covered_by/interface.hpp>
0034 #include <boost/geometry/algorithms/detail/disjoint/interface.hpp>
0035 #include <boost/geometry/algorithms/detail/equals/interface.hpp>
0036 #include <boost/geometry/algorithms/detail/intersects/interface.hpp>
0037 #include <boost/geometry/algorithms/detail/overlaps/interface.hpp>
0038 #include <boost/geometry/algorithms/detail/touches/interface.hpp>
0039 #include <boost/geometry/algorithms/detail/within/interface.hpp>
0040 #include <boost/geometry/algorithms/centroid.hpp>
0041 
0042 #include <boost/geometry/geometries/point.hpp>
0043 #include <boost/geometry/geometries/box.hpp>
0044 
0045 // Boost.Geometry.Index
0046 #include <boost/geometry/index/detail/config_begin.hpp>
0047 
0048 #include <boost/geometry/index/detail/assert.hpp>
0049 #include <boost/geometry/index/detail/exception.hpp>
0050 
0051 #include <boost/geometry/index/detail/rtree/options.hpp>
0052 
0053 #include <boost/geometry/index/indexable.hpp>
0054 #include <boost/geometry/index/equal_to.hpp>
0055 
0056 #include <boost/geometry/index/detail/translator.hpp>
0057 
0058 #include <boost/geometry/index/predicates.hpp>
0059 #include <boost/geometry/index/distance_predicates.hpp>
0060 #include <boost/geometry/index/detail/rtree/adaptors.hpp>
0061 
0062 #include <boost/geometry/index/detail/meta.hpp>
0063 #include <boost/geometry/index/detail/utilities.hpp>
0064 #include <boost/geometry/index/detail/rtree/node/node.hpp>
0065 
0066 #include <boost/geometry/index/detail/algorithms/is_valid.hpp>
0067 
0068 #include <boost/geometry/index/detail/rtree/visitors/insert.hpp>
0069 #include <boost/geometry/index/detail/rtree/visitors/iterator.hpp>
0070 #include <boost/geometry/index/detail/rtree/visitors/remove.hpp>
0071 #include <boost/geometry/index/detail/rtree/visitors/copy.hpp>
0072 #include <boost/geometry/index/detail/rtree/visitors/destroy.hpp>
0073 #include <boost/geometry/index/detail/rtree/visitors/spatial_query.hpp>
0074 #include <boost/geometry/index/detail/rtree/visitors/distance_query.hpp>
0075 #include <boost/geometry/index/detail/rtree/visitors/count.hpp>
0076 #include <boost/geometry/index/detail/rtree/visitors/children_box.hpp>
0077 
0078 #include <boost/geometry/index/detail/rtree/linear/linear.hpp>
0079 #include <boost/geometry/index/detail/rtree/quadratic/quadratic.hpp>
0080 #include <boost/geometry/index/detail/rtree/rstar/rstar.hpp>
0081 //#include <boost/geometry/extensions/index/detail/rtree/kmeans/kmeans.hpp>
0082 
0083 #include <boost/geometry/index/detail/rtree/pack_create.hpp>
0084 
0085 #include <boost/geometry/index/inserter.hpp>
0086 
0087 #include <boost/geometry/index/detail/rtree/utilities/view.hpp>
0088 
0089 #include <boost/geometry/index/detail/rtree/iterators.hpp>
0090 #include <boost/geometry/index/detail/rtree/query_iterators.hpp>
0091 
0092 #ifdef BOOST_GEOMETRY_INDEX_DETAIL_EXPERIMENTAL
0093 #ifndef BOOST_GEOMETRY_INDEX_DETAIL_EXPERIMENTAL_SERIALIZATION
0094 #define BOOST_GEOMETRY_INDEX_DETAIL_EXPERIMENTAL_SERIALIZATION
0095 #endif
0096 #ifndef BOOST_GEOMETRY_INDEX_DETAIL_EXPERIMENTAL_ITERATORS
0097 #define BOOST_GEOMETRY_INDEX_DETAIL_EXPERIMENTAL_ITERATORS
0098 #endif
0099 #endif
0100 
0101 #ifdef BOOST_GEOMETRY_INDEX_DETAIL_EXPERIMENTAL_SERIALIZATION
0102 #include <boost/geometry/index/detail/serialization.hpp>
0103 #endif
0104 
0105 #include <boost/geometry/util/range.hpp>
0106 #include <boost/geometry/util/type_traits.hpp>
0107 
0108 // TODO change the name to bounding_tree
0109 
0110 /*!
0111 \defgroup rtree_functions R-tree free functions (boost::geometry::index::)
0112 */
0113 
0114 namespace boost { namespace geometry { namespace index {
0115 
0116 /*!
0117 \brief The R-tree spatial index.
0118 
0119 This is self-balancing spatial index capable to store various types of Values
0120 and balancing algorithms.
0121 
0122 \par Parameters
0123 The user must pass a type defining the Parameters which will
0124 be used in rtree creation process. This type is used e.g. to specify balancing
0125 algorithm with specific parameters like min and max number of elements in node.
0126 
0127 \par
0128 Predefined algorithms with compile-time parameters are:
0129  \li <tt>boost::geometry::index::linear</tt>,
0130  \li <tt>boost::geometry::index::quadratic</tt>,
0131  \li <tt>boost::geometry::index::rstar</tt>.
0132 
0133 \par
0134 Predefined algorithms with run-time parameters are:
0135  \li \c boost::geometry::index::dynamic_linear,
0136  \li \c boost::geometry::index::dynamic_quadratic,
0137  \li \c boost::geometry::index::dynamic_rstar.
0138 
0139 \par IndexableGetter
0140 An object of IndexableGetter type translates from Value to Indexable each time
0141 r-tree requires it. This operation is done for each Value access.
0142 The Indexable should not be calculated each time since it could harm
0143 the performance. The default IndexableGetter can translate all types adapted
0144 to Point, Box or Segment concepts (called Indexables). Furthermore, it can
0145 handle <tt>std::pair<Indexable, T></tt>, <tt>std::tuple<Indexable, ...></tt>
0146 and <tt>boost::tuple<Indexable, ...></tt>. For example, for Value
0147 of type <tt>std::pair<Box, int></tt>, the default IndexableGetter translates
0148 from <tt>std::pair<Box, int> const&</tt> to <tt>Box const&</tt>.
0149 
0150 \par EqualTo
0151 The object of EqualTo type compares Values and returns <tt>true</tt> if they
0152 are equal. It's similar to <tt>std::equal_to<></tt>. The default EqualTo
0153 returns the result of <tt>boost::geometry::equals()</tt> for types adapted to
0154 some Geometry concept defined in Boost.Geometry and the result of
0155 <tt>operator==</tt> for other types. Components of Pairs and Tuples are
0156 compared left-to-right.
0157 
0158 \tparam Value           The type of objects stored in the container.
0159 \tparam Parameters      Compile-time parameters.
0160 \tparam IndexableGetter The function object extracting Indexable from Value.
0161 \tparam EqualTo         The function object comparing objects of type Value.
0162 \tparam Allocator       The allocator used to allocate/deallocate memory,
0163                         construct/destroy nodes and Values.
0164 */
0165 template
0166 <
0167     typename Value,
0168     typename Parameters,
0169     typename IndexableGetter = index::indexable<Value>,
0170     typename EqualTo = index::equal_to<Value>,
0171     typename Allocator = boost::container::new_allocator<Value>
0172 >
0173 class rtree
0174 {
0175 public:
0176     /*! \brief The type of Value stored in the container. */
0177     typedef Value value_type;
0178     /*! \brief R-tree parameters type. */
0179     typedef Parameters parameters_type;
0180     /*! \brief The function object extracting Indexable from Value. */
0181     typedef IndexableGetter indexable_getter;
0182     /*! \brief The function object comparing objects of type Value. */
0183     typedef EqualTo value_equal;
0184     /*! \brief The type of allocator used by the container. */
0185     typedef Allocator allocator_type;
0186 
0187     // TODO: SHOULD THIS TYPE BE REMOVED?
0188     /*! \brief The Indexable type to which Value is translated. */
0189     typedef typename index::detail::indexable_type<
0190         detail::translator<IndexableGetter, EqualTo>
0191     >::type indexable_type;
0192 
0193     /*! \brief The Box type used by the R-tree. */
0194     typedef geometry::model::box<
0195                 geometry::model::point<
0196                     typename coordinate_type<indexable_type>::type,
0197                     dimension<indexable_type>::value,
0198                     typename coordinate_system<indexable_type>::type
0199                 >
0200             >
0201     bounds_type;
0202 
0203 private:
0204 
0205     typedef bounds_type box_type;
0206 
0207     struct members_holder
0208         : public detail::translator<IndexableGetter, EqualTo>
0209         , public Parameters
0210         , public detail::rtree::allocators
0211             <
0212                 Allocator,
0213                 Value,
0214                 Parameters,
0215                 bounds_type,
0216                 typename detail::rtree::options_type<Parameters>::type::node_tag
0217             >
0218     {
0219         typedef Value value_type;
0220         typedef typename rtree::bounds_type bounds_type;
0221         typedef Parameters parameters_type;
0222         //typedef IndexableGetter indexable_getter;
0223         //typedef EqualTo value_equal;
0224         //typedef Allocator allocator_type;
0225 
0226         typedef bounds_type box_type;
0227         typedef detail::translator<IndexableGetter, EqualTo> translator_type;
0228         typedef typename detail::rtree::options_type<Parameters>::type options_type;
0229         typedef typename options_type::node_tag node_tag;
0230         typedef detail::rtree::allocators
0231             <
0232                 Allocator, Value, Parameters, bounds_type, node_tag
0233             > allocators_type;
0234 
0235         typedef typename detail::rtree::node
0236             <
0237                 value_type, parameters_type, bounds_type, allocators_type, node_tag
0238             >::type node;
0239         typedef typename detail::rtree::internal_node
0240             <
0241                 value_type, parameters_type, bounds_type, allocators_type, node_tag
0242             >::type internal_node;
0243         typedef typename detail::rtree::leaf
0244             <
0245                 value_type, parameters_type, bounds_type, allocators_type, node_tag
0246             >::type leaf;
0247 
0248         // TODO: only one visitor type is needed
0249         typedef typename detail::rtree::visitor
0250             <
0251                 value_type, parameters_type, bounds_type, allocators_type, node_tag, false
0252             >::type visitor;
0253         typedef typename detail::rtree::visitor
0254             <
0255                 value_type, parameters_type, bounds_type, allocators_type, node_tag, true
0256             >::type visitor_const;
0257 
0258         typedef typename allocators_type::node_pointer node_pointer;
0259 
0260         typedef ::boost::container::allocator_traits<Allocator> allocator_traits_type;
0261         typedef typename allocators_type::size_type size_type;
0262 
0263     private:
0264         members_holder(members_holder const&);
0265         members_holder & operator=(members_holder const&);
0266 
0267     public:
0268         template <typename IndGet, typename ValEq, typename Alloc>
0269         members_holder(IndGet const& ind_get,
0270                        ValEq const& val_eq,
0271                        Parameters const& parameters,
0272                        Alloc&& alloc)
0273             : translator_type(ind_get, val_eq)
0274             , Parameters(parameters)
0275             , allocators_type(std::forward<Alloc>(alloc))
0276             , values_count(0)
0277             , leafs_level(0)
0278             , root(0)
0279         {}
0280 
0281         template <typename IndGet, typename ValEq>
0282         members_holder(IndGet const& ind_get,
0283                        ValEq const& val_eq,
0284                        Parameters const& parameters)
0285             : translator_type(ind_get, val_eq)
0286             , Parameters(parameters)
0287             , allocators_type()
0288             , values_count(0)
0289             , leafs_level(0)
0290             , root(0)
0291         {}
0292 
0293         translator_type const& translator() const { return *this; }
0294 
0295         IndexableGetter const& indexable_getter() const { return *this; }
0296         IndexableGetter & indexable_getter() { return *this; }
0297         EqualTo const& equal_to() const { return *this; }
0298         EqualTo & equal_to() { return *this; }
0299         Parameters const& parameters() const { return *this; }
0300         Parameters & parameters() { return *this; }
0301         allocators_type const& allocators() const { return *this; }
0302         allocators_type & allocators() { return *this; }
0303 
0304         size_type values_count;
0305         size_type leafs_level;
0306         node_pointer root;
0307     };
0308 
0309     typedef typename members_holder::translator_type translator_type;
0310     typedef typename members_holder::options_type options_type;
0311     typedef typename members_holder::allocators_type allocators_type;
0312     typedef typename members_holder::node node;
0313     typedef typename members_holder::internal_node internal_node;
0314     typedef typename members_holder::leaf leaf;
0315 
0316     typedef typename members_holder::node_pointer node_pointer;
0317     typedef typename members_holder::allocator_traits_type allocator_traits_type;
0318 
0319     friend class detail::rtree::utilities::view<rtree>;
0320 #ifdef BOOST_GEOMETRY_INDEX_DETAIL_EXPERIMENTAL_SERIALIZATION
0321     friend class detail::rtree::private_view<rtree>;
0322     friend class detail::rtree::const_private_view<rtree>;
0323 #endif
0324 
0325 public:
0326 
0327     /*! \brief Type of reference to Value. */
0328     typedef typename allocators_type::reference reference;
0329     /*! \brief Type of reference to const Value. */
0330     typedef typename allocators_type::const_reference const_reference;
0331     /*! \brief Type of pointer to Value. */
0332     typedef typename allocators_type::pointer pointer;
0333     /*! \brief Type of pointer to const Value. */
0334     typedef typename allocators_type::const_pointer const_pointer;
0335     /*! \brief Type of difference type. */
0336     typedef typename allocators_type::difference_type difference_type;
0337     /*! \brief Unsigned integral type used by the container. */
0338     typedef typename allocators_type::size_type size_type;
0339 
0340     /*! \brief Type of const iterator, category ForwardIterator. */
0341     typedef index::detail::rtree::iterators::iterator
0342         <
0343             value_type, options_type, translator_type, box_type, allocators_type
0344         > const_iterator;
0345 
0346     /*! \brief Type of const query iterator, category ForwardIterator. */
0347     typedef index::detail::rtree::iterators::query_iterator
0348         <
0349             value_type, allocators_type
0350         > const_query_iterator;
0351 
0352 public:
0353 
0354     /*!
0355     \brief The constructor.
0356 
0357     \param parameters   The parameters object.
0358     \param getter       The function object extracting Indexable from Value.
0359     \param equal        The function object comparing Values.
0360 
0361     \par Throws
0362     If allocator default constructor throws.
0363     */
0364     inline explicit rtree(parameters_type const& parameters = parameters_type(),
0365                           indexable_getter const& getter = indexable_getter(),
0366                           value_equal const& equal = value_equal())
0367         : m_members(getter, equal, parameters)
0368     {}
0369 
0370     /*!
0371     \brief The constructor.
0372 
0373     \param parameters   The parameters object.
0374     \param getter       The function object extracting Indexable from Value.
0375     \param equal        The function object comparing Values.
0376     \param allocator    The allocator object.
0377 
0378     \par Throws
0379     If allocator copy constructor throws.
0380     */
0381     inline rtree(parameters_type const& parameters,
0382                  indexable_getter const& getter,
0383                  value_equal const& equal,
0384                  allocator_type const& allocator)
0385         : m_members(getter, equal, parameters, allocator)
0386     {}
0387 
0388     /*!
0389     \brief The constructor.
0390 
0391     The tree is created using packing algorithm.
0392 
0393     \param first        The beginning of the range of Values.
0394     \param last         The end of the range of Values.
0395     \param parameters   The parameters object.
0396     \param getter       The function object extracting Indexable from Value.
0397     \param equal        The function object comparing Values.
0398     \param allocator    The allocator object.
0399 
0400     \par Throws
0401     \li If allocator copy constructor throws.
0402     \li If Value copy constructor or copy assignment throws.
0403     \li If allocation throws or returns invalid value.
0404     */
0405     template<typename Iterator>
0406     inline rtree(Iterator first, Iterator last,
0407                  parameters_type const& parameters = parameters_type(),
0408                  indexable_getter const& getter = indexable_getter(),
0409                  value_equal const& equal = value_equal(),
0410                  allocator_type const& allocator = allocator_type())
0411         : m_members(getter, equal, parameters, allocator)
0412     {
0413         pack_construct(first, last, boost::container::new_allocator<void>());
0414     }
0415 
0416     /*!
0417     \brief The constructor.
0418 
0419     The tree is created using packing algorithm.
0420 
0421     \param rng          The range of Values.
0422     \param parameters   The parameters object.
0423     \param getter       The function object extracting Indexable from Value.
0424     \param equal        The function object comparing Values.
0425     \param allocator    The allocator object.
0426 
0427     \par Throws
0428     \li If allocator copy constructor throws.
0429     \li If Value copy constructor or copy assignment throws.
0430     \li If allocation throws or returns invalid value.
0431     */
0432     template<typename Range>
0433     inline explicit rtree(Range const& rng,
0434                           parameters_type const& parameters = parameters_type(),
0435                           indexable_getter const& getter = indexable_getter(),
0436                           value_equal const& equal = value_equal(),
0437                           allocator_type const& allocator = allocator_type())
0438         : m_members(getter, equal, parameters, allocator)
0439     {
0440         pack_construct(::boost::begin(rng), ::boost::end(rng), boost::container::new_allocator<void>());
0441     }
0442 
0443     /*!
0444     \brief The constructor.
0445 
0446     The tree is created using packing algorithm and a temporary packing allocator.
0447 
0448     \param first             The beginning of the range of Values.
0449     \param last              The end of the range of Values.
0450     \param parameters        The parameters object.
0451     \param getter            The function object extracting Indexable from Value.
0452     \param equal             The function object comparing Values.
0453     \param allocator         The allocator object for persistent data in the tree.
0454     \param temp_allocator    The temporary allocator object used when packing.
0455 
0456     \par Throws
0457     \li If allocator copy constructor throws.
0458     \li If Value copy constructor or copy assignment throws.
0459     \li If allocation throws or returns invalid value.
0460     */
0461     template<typename Iterator, typename PackAlloc>
0462     inline rtree(Iterator first, Iterator last,
0463                  parameters_type const& parameters,
0464                  indexable_getter const& getter,
0465                  value_equal const& equal,
0466                  allocator_type const& allocator,
0467                  PackAlloc const& temp_allocator)
0468         : m_members(getter, equal, parameters, allocator)
0469     {
0470         pack_construct(first, last, temp_allocator);
0471     }
0472 
0473     /*!
0474     \brief The constructor.
0475 
0476     The tree is created using packing algorithm and a temporary packing allocator.
0477 
0478     \param rng               The range of Values.
0479     \param parameters        The parameters object.
0480     \param getter            The function object extracting Indexable from Value.
0481     \param equal             The function object comparing Values.
0482     \param allocator         The allocator object for persistent data in the tree.
0483     \param temp_allocator    The temporary allocator object used when packing.
0484 
0485     \par Throws
0486     \li If allocator copy constructor throws.
0487     \li If Value copy constructor or copy assignment throws.
0488     \li If allocation throws or returns invalid value.
0489     */
0490     template<typename Range, typename PackAlloc>
0491     inline explicit rtree(Range const& rng,
0492                           parameters_type const& parameters,
0493                           indexable_getter const& getter,
0494                           value_equal const& equal,
0495                           allocator_type const& allocator,
0496                           PackAlloc const& temp_allocator)
0497         : m_members(getter, equal, parameters, allocator)
0498     {
0499         pack_construct(::boost::begin(rng), ::boost::end(rng), temp_allocator);
0500     }
0501 
0502     /*!
0503     \brief The constructor.
0504 
0505     The tree is created using packing algorithm and a temporary packing allocator.
0506 
0507     \param first        The beginning of the range of Values.
0508     \param last         The end of the range of Values.
0509     \param allocator    The allocator object for persistent data in the tree.
0510 
0511     \par Throws
0512     \li If allocator copy constructor throws.
0513     \li If Value copy constructor or copy assignment throws.
0514     \li If allocation throws or returns invalid value.
0515     */
0516     template<typename Iterator>
0517     inline rtree(Iterator first, Iterator last,
0518                  allocator_type const& allocator)
0519         : m_members(indexable_getter(), value_equal(), parameters_type(), allocator)
0520     {
0521         pack_construct(first, last, boost::container::new_allocator<void>());
0522     }
0523 
0524     /*!
0525     \brief The constructor.
0526 
0527     The tree is created using packing algorithm and a temporary packing allocator.
0528 
0529     \param rng          The range of Values.
0530     \param allocator    The allocator object for persistent data in the tree.
0531 
0532     \par Throws
0533     \li If allocator copy constructor throws.
0534     \li If Value copy constructor or copy assignment throws.
0535     \li If allocation throws or returns invalid value.
0536     */
0537     template<typename Range>
0538     inline explicit rtree(Range const& rng,
0539                           allocator_type const& allocator)
0540         : m_members(indexable_getter(), value_equal(), parameters_type(), allocator)
0541     {
0542         pack_construct(::boost::begin(rng), ::boost::end(rng), boost::container::new_allocator<void>());
0543     }
0544 
0545     /*!
0546     \brief The constructor.
0547 
0548     The tree is created using packing algorithm and a temporary packing allocator.
0549 
0550     \param first             The beginning of the range of Values.
0551     \param last              The end of the range of Values.
0552     \param allocator         The allocator object for persistent data in the tree.
0553     \param temp_allocator    The temporary allocator object used when packing.
0554 
0555     \par Throws
0556     \li If allocator copy constructor throws.
0557     \li If Value copy constructor or copy assignment throws.
0558     \li If allocation throws or returns invalid value.
0559     */
0560     template<typename Iterator, typename PackAlloc>
0561     inline rtree(Iterator first, Iterator last,
0562                  allocator_type const& allocator,
0563                  PackAlloc const& temp_allocator)
0564         : m_members(indexable_getter(), value_equal(), parameters_type(), allocator)
0565     {
0566         pack_construct(first, last, temp_allocator);
0567     }
0568 
0569     /*!
0570     \brief The constructor.
0571 
0572     The tree is created using packing algorithm and a temporary packing allocator.
0573 
0574     \param rng               The range of Values.
0575     \param allocator         The allocator object for persistent data in the tree.
0576     \param temp_allocator    The temporary allocator object used when packing.
0577 
0578     \par Throws
0579     \li If allocator copy constructor throws.
0580     \li If Value copy constructor or copy assignment throws.
0581     \li If allocation throws or returns invalid value.
0582     */
0583     template<typename Range, typename PackAlloc>
0584     inline explicit rtree(Range const& rng,
0585                           allocator_type const& allocator,
0586                           PackAlloc const& temp_allocator)
0587         : m_members(indexable_getter(), value_equal(), parameters_type(), allocator)
0588     {
0589         pack_construct(::boost::begin(rng), ::boost::end(rng), temp_allocator);
0590     }
0591 
0592     /*!
0593     \brief The destructor.
0594 
0595     \par Throws
0596     Nothing.
0597     */
0598     inline ~rtree()
0599     {
0600         this->raw_destroy(*this);
0601     }
0602 
0603     /*!
0604     \brief  The copy constructor.
0605 
0606     It uses parameters, observers and allocator from the source tree.
0607 
0608     \param src          The rtree which content will be copied.
0609 
0610     \par Throws
0611     \li If allocator copy constructor throws.
0612     \li If Value copy constructor throws.
0613     \li If allocation throws or returns invalid value.
0614     */
0615     inline rtree(rtree const& src)
0616         : m_members(src.m_members.indexable_getter(),
0617                     src.m_members.equal_to(),
0618                     src.m_members.parameters(),
0619                     allocator_traits_type::select_on_container_copy_construction(src.get_allocator()))
0620     {
0621         this->raw_copy(src, *this, false);
0622     }
0623 
0624     /*!
0625     \brief The copy constructor.
0626 
0627     It uses parameters and observers from the source tree.
0628 
0629     \param src          The rtree which content will be copied.
0630     \param allocator    The allocator which will be used.
0631 
0632     \par Throws
0633     \li If allocator copy constructor throws.
0634     \li If Value copy constructor throws.
0635     \li If allocation throws or returns invalid value.
0636     */
0637     inline rtree(rtree const& src, allocator_type const& allocator)
0638         : m_members(src.m_members.indexable_getter(),
0639                     src.m_members.equal_to(),
0640                     src.m_members.parameters(), allocator)
0641     {
0642         this->raw_copy(src, *this, false);
0643     }
0644 
0645     /*!
0646     \brief The moving constructor.
0647 
0648     It uses parameters, observers and allocator from the source tree.
0649 
0650     \param src          The rtree which content will be moved.
0651 
0652     \par Throws
0653     Nothing.
0654     */
0655     inline rtree(rtree&& src)
0656         : m_members(src.m_members.indexable_getter(),
0657                     src.m_members.equal_to(),
0658                     src.m_members.parameters(),
0659                     std::move(src.m_members.allocators()))
0660     {
0661         boost::core::invoke_swap(m_members.values_count, src.m_members.values_count);
0662         boost::core::invoke_swap(m_members.leafs_level, src.m_members.leafs_level);
0663         boost::core::invoke_swap(m_members.root, src.m_members.root);
0664     }
0665 
0666     /*!
0667     \brief The moving constructor.
0668 
0669     It uses parameters and observers from the source tree.
0670 
0671     \param src          The rtree which content will be moved.
0672     \param allocator    The allocator.
0673 
0674     \par Throws
0675     \li If allocator copy constructor throws.
0676     \li If Value copy constructor throws (only if allocators aren't equal).
0677     \li If allocation throws or returns invalid value (only if allocators aren't equal).
0678     */
0679     inline rtree(rtree&& src, allocator_type const& allocator)
0680         : m_members(src.m_members.indexable_getter(),
0681                     src.m_members.equal_to(),
0682                     src.m_members.parameters(),
0683                     allocator)
0684     {
0685         if ( src.m_members.allocators() == allocator )
0686         {
0687             boost::core::invoke_swap(m_members.values_count, src.m_members.values_count);
0688             boost::core::invoke_swap(m_members.leafs_level, src.m_members.leafs_level);
0689             boost::core::invoke_swap(m_members.root, src.m_members.root);
0690         }
0691         else
0692         {
0693             this->raw_copy(src, *this, false);
0694         }
0695     }
0696 
0697     /*!
0698     \brief The assignment operator.
0699 
0700     It uses parameters and observers from the source tree.
0701 
0702     \param src          The rtree which content will be copied.
0703 
0704     \par Throws
0705     \li If Value copy constructor throws.
0706     \li If allocation throws.
0707     \li If allocation throws or returns invalid value.
0708     */
0709     inline rtree & operator=(rtree const& src)
0710     {
0711         if ( &src != this )
0712         {
0713             allocators_type & this_allocs = m_members.allocators();
0714             allocators_type const& src_allocs = src.m_members.allocators();
0715 
0716             // NOTE: if propagate is true for std allocators on darwin 4.2.1, glibc++
0717             // (allocators stored as base classes of members_holder)
0718             // copying them changes values_count, in this case it doesn't cause errors since data must be copied
0719 
0720             typedef std::integral_constant<bool,
0721                 allocator_traits_type::propagate_on_container_copy_assignment::value
0722             > propagate;
0723 
0724             if ( propagate::value && !(this_allocs == src_allocs) )
0725                 this->raw_destroy(*this);
0726             detail::assign_cond(this_allocs, src_allocs, propagate());
0727 
0728             // It uses m_allocators
0729             this->raw_copy(src, *this, true);
0730         }
0731 
0732         return *this;
0733     }
0734 
0735     /*!
0736     \brief The moving assignment.
0737 
0738     It uses parameters and observers from the source tree.
0739 
0740     \param src          The rtree which content will be moved.
0741 
0742     \par Throws
0743     Only if allocators aren't equal.
0744     \li If Value copy constructor throws.
0745     \li If allocation throws or returns invalid value.
0746     */
0747     inline rtree & operator=(rtree&& src)
0748     {
0749         if ( &src != this )
0750         {
0751             allocators_type & this_allocs = m_members.allocators();
0752             allocators_type & src_allocs = src.m_members.allocators();
0753 
0754             if ( this_allocs == src_allocs )
0755             {
0756                 this->raw_destroy(*this);
0757 
0758                 m_members.indexable_getter() = src.m_members.indexable_getter();
0759                 m_members.equal_to() = src.m_members.equal_to();
0760                 m_members.parameters() = src.m_members.parameters();
0761 
0762                 boost::core::invoke_swap(m_members.values_count, src.m_members.values_count);
0763                 boost::core::invoke_swap(m_members.leafs_level, src.m_members.leafs_level);
0764                 boost::core::invoke_swap(m_members.root, src.m_members.root);
0765 
0766                 // NOTE: if propagate is true for std allocators on darwin 4.2.1, glibc++
0767                 // (allocators stored as base classes of members_holder)
0768                 // moving them changes values_count
0769 
0770                 typedef std::integral_constant<bool,
0771                     allocator_traits_type::propagate_on_container_move_assignment::value
0772                 > propagate;
0773                 detail::move_cond(this_allocs, src_allocs, propagate());
0774             }
0775             else
0776             {
0777 // TODO - shouldn't here propagate_on_container_copy_assignment be checked like in operator=(const&)?
0778 
0779                 // It uses m_allocators
0780                 this->raw_copy(src, *this, true);
0781             }
0782         }
0783 
0784         return *this;
0785     }
0786 
0787     /*!
0788     \brief Swaps contents of two rtrees.
0789 
0790     Parameters, observers and allocators are swapped as well.
0791 
0792     \param other    The rtree which content will be swapped with this rtree content.
0793 
0794     \par Throws
0795     If allocators swap throws.
0796     */
0797     void swap(rtree & other)
0798     {
0799         boost::core::invoke_swap(m_members.indexable_getter(), other.m_members.indexable_getter());
0800         boost::core::invoke_swap(m_members.equal_to(), other.m_members.equal_to());
0801         boost::core::invoke_swap(m_members.parameters(), other.m_members.parameters());
0802 
0803         // NOTE: if propagate is true for std allocators on darwin 4.2.1, glibc++
0804         // (allocators stored as base classes of members_holder)
0805         // swapping them changes values_count
0806 
0807         typedef std::integral_constant<bool,
0808             allocator_traits_type::propagate_on_container_swap::value
0809         > propagate;
0810         detail::swap_cond(m_members.allocators(), other.m_members.allocators(), propagate());
0811 
0812         boost::core::invoke_swap(m_members.values_count, other.m_members.values_count);
0813         boost::core::invoke_swap(m_members.leafs_level, other.m_members.leafs_level);
0814         boost::core::invoke_swap(m_members.root, other.m_members.root);
0815     }
0816 
0817     /*!
0818     \brief Insert a value to the index.
0819 
0820     \param value    The value which will be stored in the container.
0821 
0822     \par Throws
0823     \li If Value copy constructor or copy assignment throws.
0824     \li If allocation throws or returns invalid value.
0825 
0826     \warning
0827     This operation only guarantees that there will be no memory leaks.
0828     After an exception is thrown the R-tree may be left in an inconsistent state,
0829     elements must not be inserted or removed. Other operations are allowed however
0830     some of them may return invalid data.
0831     */
0832     inline void insert(value_type const& value)
0833     {
0834         if ( !m_members.root )
0835             this->raw_create();
0836 
0837         this->raw_insert(value);
0838     }
0839 
0840     /*!
0841     \brief Insert a range of values to the index.
0842 
0843     \param first    The beginning of the range of values.
0844     \param last     The end of the range of values.
0845 
0846     \par Throws
0847     \li If Value copy constructor or copy assignment throws.
0848     \li If allocation throws or returns invalid value.
0849 
0850     \warning
0851     This operation only guarantees that there will be no memory leaks.
0852     After an exception is thrown the R-tree may be left in an inconsistent state,
0853     elements must not be inserted or removed. Other operations are allowed however
0854     some of them may return invalid data.
0855     */
0856     template <typename Iterator>
0857     inline void insert(Iterator first, Iterator last)
0858     {
0859         if ( !m_members.root )
0860             this->raw_create();
0861 
0862         for ( ; first != last ; ++first )
0863             this->raw_insert(*first);
0864     }
0865 
0866     /*!
0867     \brief Insert a value created using convertible object or a range of values to the index.
0868 
0869     \param conv_or_rng      An object of type convertible to value_type or a range of values.
0870 
0871     \par Throws
0872     \li If Value copy constructor or copy assignment throws.
0873     \li If allocation throws or returns invalid value.
0874 
0875     \warning
0876     This operation only guarantees that there will be no memory leaks.
0877     After an exception is thrown the R-tree may be left in an inconsistent state,
0878     elements must not be inserted or removed. Other operations are allowed however
0879     some of them may return invalid data.
0880     */
0881     template <typename ConvertibleOrRange>
0882     inline void insert(ConvertibleOrRange const& conv_or_rng)
0883     {
0884         if ( !m_members.root )
0885             this->raw_create();
0886 
0887         typedef std::is_convertible<ConvertibleOrRange, value_type> is_conv_t;
0888         typedef range::detail::is_range<ConvertibleOrRange> is_range_t;
0889         BOOST_GEOMETRY_STATIC_ASSERT((is_conv_t::value || is_range_t::value),
0890             "The argument has to be convertible to Value type or be a Range.",
0891             ConvertibleOrRange);
0892 
0893         this->insert_dispatch(conv_or_rng, is_conv_t());
0894     }
0895 
0896     /*!
0897     \brief Remove a value from the container.
0898 
0899     In contrast to the \c std::set or <tt>std::map erase()</tt> method
0900     this method removes only one value from the container.
0901 
0902     \param value    The value which will be removed from the container.
0903 
0904     \return         1 if the value was removed, 0 otherwise.
0905 
0906     \par Throws
0907     \li If Value copy constructor or copy assignment throws.
0908     \li If allocation throws or returns invalid value.
0909 
0910     \warning
0911     This operation only guarantees that there will be no memory leaks.
0912     After an exception is thrown the R-tree may be left in an inconsistent state,
0913     elements must not be inserted or removed. Other operations are allowed however
0914     some of them may return invalid data.
0915     */
0916     inline size_type remove(value_type const& value)
0917     {
0918         if ( !m_members.root )
0919             return 0;
0920 
0921         return this->raw_remove(value);
0922     }
0923 
0924     /*!
0925     \brief Remove a range of values from the container.
0926 
0927     In contrast to the \c std::set or <tt>std::map erase()</tt> method
0928     it doesn't take iterators pointing to values stored in this container. It removes values equal
0929     to these passed as a range. Furthermore this method removes only one value for each one passed
0930     in the range, not all equal values.
0931 
0932     \param first    The beginning of the range of values.
0933     \param last     The end of the range of values.
0934 
0935     \return         The number of removed values.
0936 
0937     \par Throws
0938     \li If Value copy constructor or copy assignment throws.
0939     \li If allocation throws or returns invalid value.
0940 
0941     \warning
0942     This operation only guarantees that there will be no memory leaks.
0943     After an exception is thrown the R-tree may be left in an inconsistent state,
0944     elements must not be inserted or removed. Other operations are allowed however
0945     some of them may return invalid data.
0946     */
0947     template <typename Iterator>
0948     inline size_type remove(Iterator first, Iterator last)
0949     {
0950         size_type result = 0;
0951 
0952         if ( !m_members.root )
0953             return result;
0954 
0955         for ( ; first != last ; ++first )
0956             result += this->raw_remove(*first);
0957         return result;
0958     }
0959 
0960     /*!
0961     \brief Remove value corresponding to an object convertible to it or a range of values from the container.
0962 
0963     In contrast to the \c std::set or <tt>std::map erase()</tt> method
0964     it removes values equal to these passed as a range. Furthermore, this method removes only
0965     one value for each one passed in the range, not all equal values.
0966 
0967     \param conv_or_rng      The object of type convertible to value_type or a range of values.
0968 
0969     \return         The number of removed values.
0970 
0971     \par Throws
0972     \li If Value copy constructor or copy assignment throws.
0973     \li If allocation throws or returns invalid value.
0974 
0975     \warning
0976     This operation only guarantees that there will be no memory leaks.
0977     After an exception is thrown the R-tree may be left in an inconsistent state,
0978     elements must not be inserted or removed. Other operations are allowed however
0979     some of them may return invalid data.
0980     */
0981     template <typename ConvertibleOrRange>
0982     inline size_type remove(ConvertibleOrRange const& conv_or_rng)
0983     {
0984         if ( !m_members.root )
0985             return 0;
0986 
0987         typedef std::is_convertible<ConvertibleOrRange, value_type> is_conv_t;
0988         typedef range::detail::is_range<ConvertibleOrRange> is_range_t;
0989         BOOST_GEOMETRY_STATIC_ASSERT((is_conv_t::value || is_range_t::value),
0990             "The argument has to be convertible to Value type or be a Range.",
0991             ConvertibleOrRange);
0992 
0993         return this->remove_dispatch(conv_or_rng, is_conv_t());
0994     }
0995 
0996     /*!
0997     \brief Finds values meeting passed predicates e.g. nearest to some Point and/or intersecting some Box.
0998 
0999     This query function performs spatial and k-nearest neighbor searches. It allows to pass a set of predicates.
1000     Values will be returned only if all predicates are met.
1001 
1002     <b>Spatial predicates</b>
1003 
1004     Spatial predicates may be generated by one of the functions listed below:
1005     \li \c boost::geometry::index::contains(),
1006     \li \c boost::geometry::index::covered_by(),
1007     \li \c boost::geometry::index::covers(),
1008     \li \c boost::geometry::index::disjoint(),
1009     \li \c boost::geometry::index::intersects(),
1010     \li \c boost::geometry::index::overlaps(),
1011     \li \c boost::geometry::index::within(),
1012 
1013     It is possible to negate spatial predicates:
1014     \li <tt>! boost::geometry::index::contains()</tt>,
1015     \li <tt>! boost::geometry::index::covered_by()</tt>,
1016     \li <tt>! boost::geometry::index::covers()</tt>,
1017     \li <tt>! boost::geometry::index::disjoint()</tt>,
1018     \li <tt>! boost::geometry::index::intersects()</tt>,
1019     \li <tt>! boost::geometry::index::overlaps()</tt>,
1020     \li <tt>! boost::geometry::index::within()</tt>
1021 
1022     <b>Satisfies predicate</b>
1023 
1024     This is a special kind of predicate which allows to pass a user-defined function or function object which checks
1025     if Value should be returned by the query. It's generated by:
1026     \li \c boost::geometry::index::satisfies().
1027 
1028     <b>Nearest predicate</b>
1029 
1030     If the nearest predicate is passed a k-nearest neighbor search will be performed. This query will result
1031     in returning k values to the output iterator. Only one nearest predicate may be passed to the query.
1032     It may be generated by:
1033     \li \c boost::geometry::index::nearest().
1034 
1035     <b>Connecting predicates</b>
1036 
1037     Predicates may be passed together connected with \c operator&&().
1038 
1039     \par Example
1040     \verbatim
1041     // return elements intersecting box
1042     tree.query(bgi::intersects(box), std::back_inserter(result));
1043     // return elements intersecting poly but not within box
1044     tree.query(bgi::intersects(poly) && !bgi::within(box), std::back_inserter(result));
1045     // return elements overlapping box and meeting my_fun unary predicate
1046     tree.query(bgi::overlaps(box) && bgi::satisfies(my_fun), std::back_inserter(result));
1047     // return 5 elements nearest to pt and elements are intersecting box
1048     tree.query(bgi::nearest(pt, 5) && bgi::intersects(box), std::back_inserter(result));
1049 
1050     // For each found value do_something (it is a type of function object)
1051     tree.query(bgi::intersects(box),
1052                boost::make_function_output_iterator(do_something()));
1053 
1054     // For each value stored in the rtree do_something
1055     // always_true is a type of function object always returning true
1056     tree.query(bgi::satisfies(always_true()),
1057                boost::make_function_output_iterator(do_something()));
1058 
1059     // C++11 (lambda expression)
1060     tree.query(bgi::intersects(box),
1061                boost::make_function_output_iterator([](value_type const& val){
1062                    // do something
1063                }));
1064 
1065     // C++14 (generic lambda expression)
1066     tree.query(bgi::intersects(box),
1067                boost::make_function_output_iterator([](auto const& val){
1068                    // do something
1069                }));
1070     \endverbatim
1071 
1072     \par Throws
1073     If Value copy constructor or copy assignment throws.
1074     If predicates copy throws.
1075 
1076     \warning
1077     Only one \c nearest() predicate may be passed to the query. Passing more of them results in compile-time error.
1078 
1079     \param predicates   Predicates.
1080     \param out_it       The output iterator, e.g. generated by std::back_inserter().
1081 
1082     \return             The number of values found.
1083     */
1084     template <typename Predicates, typename OutIter>
1085     size_type query(Predicates const& predicates, OutIter out_it) const
1086     {
1087         return m_members.root
1088              ? query_dispatch(predicates, out_it)
1089              : 0;
1090     }
1091 
1092     /*!
1093     \brief Returns a query iterator pointing at the begin of the query range.
1094 
1095     This method returns an iterator which may be used to perform iterative queries.
1096     For the information about predicates which may be passed to this method see query().
1097 
1098     \par Example
1099     \verbatim
1100     for ( Rtree::const_query_iterator it = tree.qbegin(bgi::nearest(pt, 10000)) ;
1101           it != tree.qend() ; ++it )
1102     {
1103         // do something with value
1104         if ( has_enough_nearest_values() )
1105             break;
1106     }
1107 
1108     // C++11 (auto)
1109     for ( auto it = tree.qbegin(bgi::nearest(pt, 3)) ; it != tree.qend() ; ++it )
1110     {
1111         // do something with value
1112     }
1113 
1114     // C++14 (generic lambda expression)
1115     std::for_each(tree.qbegin(bgi::nearest(pt, 3)), tree.qend(), [](auto const& val){
1116         // do something with value
1117     });
1118     \endverbatim
1119 
1120     \par Iterator category
1121     ForwardIterator
1122 
1123     \par Throws
1124     If predicates copy throws.
1125     If allocation throws.
1126 
1127     \warning
1128     The modification of the rtree may invalidate the iterators.
1129 
1130     \param predicates   Predicates.
1131 
1132     \return             The iterator pointing at the begin of the query range.
1133     */
1134     template <typename Predicates>
1135     const_query_iterator qbegin(Predicates const& predicates) const
1136     {
1137         return const_query_iterator(qbegin_(predicates));
1138     }
1139 
1140     /*!
1141     \brief Returns a query iterator pointing at the end of the query range.
1142 
1143     This method returns an iterator which may be used to check if the query has ended.
1144 
1145     \par Example
1146     \verbatim
1147     for ( Rtree::const_query_iterator it = tree.qbegin(bgi::nearest(pt, 10000)) ;
1148           it != tree.qend() ; ++it )
1149     {
1150         // do something with value
1151         if ( has_enough_nearest_values() )
1152             break;
1153     }
1154 
1155     // C++11 (auto)
1156     for ( auto it = tree.qbegin(bgi::nearest(pt, 3)) ; it != tree.qend() ; ++it )
1157     {
1158         // do something with value
1159     }
1160 
1161     // C++14 (generic lambda expression)
1162     std::for_each(tree.qbegin(bgi::nearest(pt, 3)), tree.qend(), [](auto const& val){
1163         // do something with value
1164     });
1165     \endverbatim
1166 
1167     \par Iterator category
1168     ForwardIterator
1169 
1170     \par Throws
1171     Nothing
1172 
1173     \warning
1174     The modification of the rtree may invalidate the iterators.
1175 
1176     \return             The iterator pointing at the end of the query range.
1177     */
1178     const_query_iterator qend() const
1179     {
1180         return const_query_iterator();
1181     }
1182 
1183 private:
1184     template <typename Predicates>
1185     using query_iterator_t = std::conditional_t
1186         <
1187             detail::predicates_count_distance<Predicates>::value == 0,
1188             detail::rtree::iterators::spatial_query_iterator<members_holder, Predicates>,
1189             detail::rtree::iterators::distance_query_iterator<members_holder, Predicates>
1190         >;
1191 
1192 #ifdef BOOST_GEOMETRY_INDEX_DETAIL_EXPERIMENTAL_ITERATORS
1193 public:
1194 #else
1195 private:
1196 #endif
1197     /*!
1198     \brief Returns a query iterator pointing at the begin of the query range.
1199 
1200     This method returns an iterator which may be used to perform iterative queries.
1201     For the information about predicates which may be passed to this method see query().
1202 
1203     The type of the returned iterator depends on the type of passed Predicates but the iterator of this type
1204     may be assigned to the variable of const_query_iterator type. If you'd like to use the type of the iterator
1205     returned by this method you may get the type e.g. by using C++11 decltype or Boost.Typeof library.
1206     This iterator may be compared with iterators returned by both versions of qend() method.
1207 
1208     \par Example
1209     \verbatim
1210     // Store the result in the container using std::copy() - it requires both iterators of the same type
1211     std::copy(tree.qbegin_(bgi::intersects(box)), tree.qend_(bgi::intersects(box)), std::back_inserter(result));
1212 
1213     // Store the result in the container using std::copy() and type-erased iterators
1214     Rtree::const_query_iterator first = tree.qbegin_(bgi::intersects(box));
1215     Rtree::const_query_iterator last = tree.qend_();
1216     std::copy(first, last, std::back_inserter(result));
1217 
1218     // Boost.Typeof
1219     typedef BOOST_TYPEOF(tree.qbegin(bgi::nearest(pt, 10000))) Iter;
1220     for ( Iter it = tree.qbegin_(bgi::nearest(pt, 10000)) ; it != tree.qend_() ; ++it )
1221     {
1222         // do something with value
1223         if ( has_enough_nearest_values() )
1224             break;
1225     }
1226 
1227     // C++11 (auto)
1228     for ( auto it = tree.qbegin_(bgi::nearest(pt, 10000)) ; it != tree.qend_() ; ++it )
1229     {
1230         // do something with value
1231         if ( has_enough_nearest_values() )
1232             break;
1233     }
1234     \endverbatim
1235 
1236     \par Iterator category
1237     ForwardIterator
1238 
1239     \par Throws
1240     If predicates copy throws.
1241     If allocation throws.
1242 
1243     \warning
1244     The modification of the rtree may invalidate the iterators.
1245 
1246     \param predicates   Predicates.
1247 
1248     \return             The iterator pointing at the begin of the query range.
1249     */
1250     template <typename Predicates>
1251     query_iterator_t<Predicates> qbegin_(Predicates const& predicates) const
1252     {
1253         BOOST_GEOMETRY_STATIC_ASSERT((detail::predicates_count_distance<Predicates>::value <= 1),
1254             "Only one distance predicate can be passed.",
1255             Predicates);
1256 
1257         return m_members.root
1258              ? query_iterator_t<Predicates>(m_members, predicates)
1259              : query_iterator_t<Predicates>(predicates);
1260     }
1261 
1262     /*!
1263     \brief Returns the query iterator pointing at the end of the query range.
1264 
1265     This method returns the iterator which may be used to perform iterative queries. For the information
1266     about the predicates which may be passed to this method see query().
1267 
1268     The type of the returned iterator depends on the type of passed Predicates but the iterator of this type
1269     may be assigned to the variable of const_query_iterator type. If you'd like to use the type of the iterator
1270     returned by this method you may get the type e.g. by using C++11 decltype or Boost.Typeof library.
1271 
1272     The type of the iterator returned by this method is the same as the one returned by qbegin() to which
1273     the same predicates were passed.
1274 
1275     \par Example
1276     \verbatim
1277     // Store the result in the container using std::copy() - it requires both iterators of the same type
1278     std::copy(tree.qbegin_(bgi::intersects(box)), tree.qend_(bgi::intersects(box)), std::back_inserter(result));
1279     \endverbatim
1280 
1281     \par Iterator category
1282     ForwardIterator
1283 
1284     \par Throws
1285     If predicates copy throws.
1286 
1287     \warning
1288     The modification of the rtree may invalidate the iterators.
1289 
1290     \param predicates   Predicates.
1291 
1292     \return             The iterator pointing at the end of the query range.
1293     */
1294     template <typename Predicates>
1295     query_iterator_t<Predicates> qend_(Predicates const& predicates) const
1296     {
1297         BOOST_GEOMETRY_STATIC_ASSERT((detail::predicates_count_distance<Predicates>::value <= 1),
1298             "Only one distance predicate can be passed.",
1299             Predicates);
1300 
1301         return query_iterator_t<Predicates>(m_members.parameters(), m_members.translator(), predicates);
1302     }
1303 
1304     /*!
1305     \brief Returns the query iterator pointing at the end of the query range.
1306 
1307     This method returns the iterator which may be compared with the iterator returned by qbegin() in order to
1308     check if the query has ended.
1309 
1310     The type of the returned iterator is different than the type returned by qbegin() but the iterator of this type
1311     may be assigned to the variable of const_query_iterator type. If you'd like to use the type of the iterator returned by this
1312     method, which most certainly will be faster than the type-erased iterator, you may get the type
1313     e.g. by using C++11 decltype or Boost.Typeof library.
1314 
1315     The type of the iterator returned by this method is different than the type returned by qbegin().
1316 
1317     \par Example
1318     \verbatim
1319     // Store the result in the container using std::copy() and type-erased iterators
1320     Rtree::const_query_iterator first = tree.qbegin_(bgi::intersects(box));
1321     Rtree::const_query_iterator last = tree.qend_();
1322     std::copy(first, last, std::back_inserter(result));
1323 
1324     // Boost.Typeof
1325     typedef BOOST_TYPEOF(tree.qbegin(bgi::nearest(pt, 10000))) Iter;
1326     for ( Iter it = tree.qbegin_(bgi::nearest(pt, 10000)) ; it != tree.qend_() ; ++it )
1327     {
1328         // do something with value
1329         if ( has_enough_nearest_values() )
1330             break;
1331     }
1332 
1333     // C++11 (auto)
1334     for ( auto it = tree.qbegin_(bgi::nearest(pt, 10000)) ; it != tree.qend_() ; ++it )
1335     {
1336         // do something with value
1337         if ( has_enough_nearest_values() )
1338             break;
1339     }
1340     \endverbatim
1341 
1342     \par Iterator category
1343     ForwardIterator
1344 
1345     \par Throws
1346     Nothing
1347 
1348     \warning
1349     The modification of the rtree may invalidate the iterators.
1350 
1351     \return             The iterator pointing at the end of the query range.
1352     */
1353     detail::rtree::iterators::end_query_iterator<value_type, allocators_type>
1354     qend_() const
1355     {
1356         return detail::rtree::iterators::end_query_iterator<value_type, allocators_type>();
1357     }
1358 
1359 public:
1360 
1361     /*!
1362     \brief Returns the iterator pointing at the begin of the rtree values range.
1363 
1364     This method returns the iterator which may be used to iterate over all values
1365     stored in the rtree.
1366 
1367     \par Example
1368     \verbatim
1369     // Copy all values into the vector
1370     std::copy(tree.begin(), tree.end(), std::back_inserter(vec));
1371 
1372     for ( Rtree::const_iterator it = tree.begin() ; it != tree.end() ; ++it )
1373     {
1374         // do something with value
1375     }
1376 
1377     // C++11 (auto)
1378     for ( auto it = tree.begin() ; it != tree.end() ; ++it )
1379     {
1380         // do something with value
1381     }
1382 
1383     // C++14 (generic lambda expression)
1384     std::for_each(tree.begin(), tree.end(), [](auto const& val){
1385         // do something with value
1386     })
1387     \endverbatim
1388 
1389     \par Iterator category
1390     ForwardIterator
1391 
1392     \par Throws
1393     If allocation throws.
1394 
1395     \warning
1396     The modification of the rtree may invalidate the iterators.
1397 
1398     \return             The iterator pointing at the begin of the range.
1399     */
1400     const_iterator begin() const
1401     {
1402         return m_members.root
1403              ? const_iterator(m_members.root)
1404              : const_iterator();
1405     }
1406 
1407     /*!
1408     \brief Returns the iterator pointing at the end of the rtree values range.
1409 
1410     This method returns the iterator which may be compared with the iterator returned by begin()
1411     in order to check if the iteration has ended.
1412 
1413     \par Example
1414     \verbatim
1415     for ( Rtree::const_iterator it = tree.begin() ; it != tree.end() ; ++it )
1416     {
1417         // do something with value
1418     }
1419 
1420     // C++11 (lambda expression)
1421     std::for_each(tree.begin(), tree.end(), [](value_type const& val){
1422         // do something with value
1423     })
1424     \endverbatim
1425 
1426     \par Iterator category
1427     ForwardIterator
1428 
1429     \par Throws
1430     Nothing.
1431 
1432     \warning
1433     The modification of the rtree may invalidate the iterators.
1434 
1435     \return             The iterator pointing at the end of the range.
1436     */
1437     const_iterator end() const
1438     {
1439         return const_iterator();
1440     }
1441 
1442     /*!
1443     \brief Returns the number of stored values.
1444 
1445     \return         The number of stored values.
1446 
1447     \par Throws
1448     Nothing.
1449     */
1450     inline size_type size() const
1451     {
1452         return m_members.values_count;
1453     }
1454 
1455     /*!
1456     \brief Query if the container is empty.
1457 
1458     \return         true if the container is empty.
1459 
1460     \par Throws
1461     Nothing.
1462     */
1463     inline bool empty() const
1464     {
1465         return 0 == m_members.values_count;
1466     }
1467 
1468     /*!
1469     \brief Removes all values stored in the container.
1470 
1471     \par Throws
1472     Nothing.
1473     */
1474     inline void clear()
1475     {
1476         this->raw_destroy(*this);
1477     }
1478 
1479     /*!
1480     \brief Returns the box able to contain all values stored in the container.
1481 
1482     Returns the box able to contain all values stored in the container.
1483     If the container is empty the result of \c geometry::assign_inverse() is returned.
1484 
1485     \return     The box able to contain all values stored in the container or an invalid box if
1486                 there are no values in the container.
1487 
1488     \par Throws
1489     Nothing.
1490     */
1491     inline bounds_type bounds() const
1492     {
1493         bounds_type result;
1494         // in order to suppress the uninitialized variable warnings
1495         geometry::assign_inverse(result);
1496 
1497         if ( m_members.root )
1498         {
1499             detail::rtree::visitors::children_box
1500                 <
1501                     members_holder
1502                 > box_v(result, m_members.parameters(), m_members.translator());
1503             detail::rtree::apply_visitor(box_v, *m_members.root);
1504         }
1505 
1506         return result;
1507     }
1508 
1509     /*!
1510     \brief Count Values or Indexables stored in the container.
1511 
1512     For indexable_type it returns the number of values which indexables equals the parameter.
1513     For value_type it returns the number of values which equals the parameter.
1514 
1515     \param vori The value or indexable which will be counted.
1516 
1517     \return     The number of values found.
1518 
1519     \par Throws
1520     Nothing.
1521     */
1522     template <typename ValueOrIndexable>
1523     size_type count(ValueOrIndexable const& vori) const
1524     {
1525         if ( !m_members.root )
1526             return 0;
1527 
1528         // the input should be convertible to Value or Indexable type
1529         typedef typename index::detail::convertible_type
1530             <
1531                 ValueOrIndexable,
1532                 value_type,
1533                 indexable_type
1534             >::type value_or_indexable;
1535 
1536         static const bool is_void = std::is_void<value_or_indexable>::value;
1537         BOOST_GEOMETRY_STATIC_ASSERT((! is_void),
1538             "The argument has to be convertible to Value or Indexable type.",
1539             ValueOrIndexable);
1540 
1541         // NOTE: If an object of convertible but not the same type is passed
1542         // into the function, here a temporary will be created.
1543         return this->template raw_count<value_or_indexable>(vori);
1544     }
1545 
1546     /*!
1547     \brief Returns parameters.
1548 
1549     \return     The parameters object.
1550 
1551     \par Throws
1552     Nothing.
1553     */
1554     inline parameters_type parameters() const
1555     {
1556         return m_members.parameters();
1557     }
1558 
1559     /*!
1560     \brief Returns function retrieving Indexable from Value.
1561 
1562     \return     The indexable_getter object.
1563 
1564     \par Throws
1565     Nothing.
1566     */
1567     indexable_getter indexable_get() const
1568     {
1569         return m_members.indexable_getter();
1570     }
1571 
1572     /*!
1573     \brief Returns function comparing Values
1574 
1575     \return     The value_equal function.
1576 
1577     \par Throws
1578     Nothing.
1579     */
1580     value_equal value_eq() const
1581     {
1582         return m_members.equal_to();
1583     }
1584 
1585     /*!
1586     \brief Returns allocator used by the rtree.
1587 
1588     \return     The allocator.
1589 
1590     \par Throws
1591     If allocator copy constructor throws.
1592     */
1593     allocator_type get_allocator() const
1594     {
1595         return m_members.allocators().allocator();
1596     }
1597 
1598 private:
1599 
1600     /*!
1601     \brief Returns the translator object.
1602 
1603     \return     The translator object.
1604 
1605     \par Throws
1606     Nothing.
1607     */
1608     inline translator_type translator() const
1609     {
1610         return m_members.translator();
1611     }
1612 
1613     /*!
1614     \brief Apply a visitor to the nodes structure in order to perform some operator.
1615 
1616     This function is not a part of the 'official' interface. However it makes
1617     possible e.g. to pass a visitor drawing the tree structure.
1618 
1619     \param visitor  The visitor object.
1620 
1621     \par Throws
1622     If Visitor::operator() throws.
1623     */
1624     template <typename Visitor>
1625     inline void apply_visitor(Visitor & visitor) const
1626     {
1627         if ( m_members.root )
1628             detail::rtree::apply_visitor(visitor, *m_members.root);
1629     }
1630 
1631     /*!
1632     \brief Returns the depth of the R-tree.
1633 
1634     This function is not a part of the 'official' interface.
1635 
1636     \return     The depth of the R-tree.
1637 
1638     \par Throws
1639     Nothing.
1640     */
1641     inline size_type depth() const
1642     {
1643         return m_members.leafs_level;
1644     }
1645 
1646 private:
1647 
1648     /*!
1649     \pre Root node must exist - m_root != 0.
1650 
1651     \brief Insert a value to the index.
1652 
1653     \param value    The value which will be stored in the container.
1654 
1655     \par Exception-safety
1656     basic
1657     */
1658     inline void raw_insert(value_type const& value)
1659     {
1660         BOOST_GEOMETRY_INDEX_ASSERT(m_members.root, "The root must exist");
1661         // CONSIDER: alternative - ignore invalid indexable or throw an exception
1662         BOOST_GEOMETRY_INDEX_ASSERT(detail::is_valid(m_members.translator()(value)), "Indexable is invalid");
1663 
1664         detail::rtree::visitors::insert<value_type, members_holder>
1665             insert_v(m_members.root, m_members.leafs_level, value,
1666                      m_members.parameters(), m_members.translator(), m_members.allocators());
1667 
1668         detail::rtree::apply_visitor(insert_v, *m_members.root);
1669 
1670 // TODO
1671 // Think about this: If exception is thrown, may the root be removed?
1672 // Or it is just cleared?
1673 
1674 // TODO
1675 // If exception is thrown, m_values_count may be invalid
1676         ++m_members.values_count;
1677     }
1678 
1679     /*!
1680     \brief Remove the value from the container.
1681 
1682     \param value    The value which will be removed from the container.
1683 
1684     \par Exception-safety
1685     basic
1686     */
1687     inline size_type raw_remove(value_type const& value)
1688     {
1689         // TODO: awulkiew - assert for correct value (indexable) ?
1690         BOOST_GEOMETRY_INDEX_ASSERT(m_members.root, "The root must exist");
1691 
1692         detail::rtree::visitors::remove<members_holder>
1693             remove_v(m_members.root, m_members.leafs_level, value,
1694                      m_members.parameters(), m_members.translator(), m_members.allocators());
1695 
1696         detail::rtree::apply_visitor(remove_v, *m_members.root);
1697 
1698         // If exception is thrown, m_values_count may be invalid
1699 
1700         if ( remove_v.is_value_removed() )
1701         {
1702             BOOST_GEOMETRY_INDEX_ASSERT(0 < m_members.values_count, "unexpected state");
1703 
1704             --m_members.values_count;
1705 
1706             return 1;
1707         }
1708 
1709         return 0;
1710     }
1711 
1712     /*!
1713     \brief Create an empty R-tree i.e. new empty root node and clear other attributes.
1714 
1715     \par Exception-safety
1716     strong
1717     */
1718     inline void raw_create()
1719     {
1720         BOOST_GEOMETRY_INDEX_ASSERT(0 == m_members.root, "the tree is already created");
1721 
1722         m_members.root = detail::rtree::create_node<allocators_type, leaf>::apply(m_members.allocators()); // MAY THROW (N: alloc)
1723         m_members.values_count = 0;
1724         m_members.leafs_level = 0;
1725     }
1726 
1727     /*!
1728     \brief Destroy the R-tree i.e. all nodes and clear attributes.
1729 
1730     \param t    The container which is going to be destroyed.
1731 
1732     \par Exception-safety
1733     nothrow
1734     */
1735     inline void raw_destroy(rtree & t)
1736     {
1737         if ( t.m_members.root )
1738         {
1739             detail::rtree::visitors::destroy<members_holder>
1740                 ::apply(t.m_members.root, t.m_members.allocators());
1741 
1742             t.m_members.root = 0;
1743         }
1744         t.m_members.values_count = 0;
1745         t.m_members.leafs_level = 0;
1746     }
1747 
1748     /*!
1749     \brief Copy the R-tree i.e. whole nodes structure, values and other attributes.
1750     It uses destination's allocators to create the new structure.
1751 
1752     \param src                  The source R-tree.
1753     \param dst                  The destination R-tree.
1754     \param copy_tr_and_params   If true, translator and parameters will also be copied.
1755 
1756     \par Exception-safety
1757     strong
1758     */
1759     inline void raw_copy(rtree const& src, rtree & dst, bool copy_tr_and_params) const
1760     {
1761         detail::rtree::visitors::copy<members_holder> copy_v(dst.m_members.allocators());
1762 
1763         if ( src.m_members.root )
1764             detail::rtree::apply_visitor(copy_v, *src.m_members.root);                      // MAY THROW (V, E: alloc, copy, N: alloc)
1765 
1766         if ( copy_tr_and_params )
1767         {
1768             dst.m_members.indexable_getter() = src.m_members.indexable_getter();
1769             dst.m_members.equal_to() = src.m_members.equal_to();
1770             dst.m_members.parameters() = src.m_members.parameters();
1771         }
1772 
1773         // TODO use subtree_destroyer
1774         if ( dst.m_members.root )
1775         {
1776             detail::rtree::visitors::destroy<members_holder>
1777                 ::apply(dst.m_members.root, dst.m_members.allocators());
1778 
1779             dst.m_members.root = 0;
1780         }
1781 
1782         dst.m_members.root = copy_v.result;
1783         dst.m_members.values_count = src.m_members.values_count;
1784         dst.m_members.leafs_level = src.m_members.leafs_level;
1785     }
1786 
1787     /*!
1788     \brief Insert a value corresponding to convertible object into the index.
1789 
1790     \param val_conv    The object convertible to value.
1791 
1792     \par Exception-safety
1793     basic
1794     */
1795     template <typename ValueConvertible>
1796     inline void insert_dispatch(ValueConvertible const& val_conv,
1797                                 std::true_type /*is_convertible*/)
1798     {
1799         this->raw_insert(val_conv);
1800     }
1801 
1802     /*!
1803     \brief Insert a range of values into the index.
1804 
1805     \param rng    The range of values.
1806 
1807     \par Exception-safety
1808     basic
1809     */
1810     template <typename Range>
1811     inline void insert_dispatch(Range const& rng,
1812                                 std::false_type /*is_convertible*/)
1813     {
1814         typedef typename boost::range_const_iterator<Range>::type It;
1815         for ( It it = boost::const_begin(rng); it != boost::const_end(rng) ; ++it )
1816             this->raw_insert(*it);
1817     }
1818 
1819     /*!
1820     \brief Remove a value corresponding to convertible object from the index.
1821 
1822     \param val_conv    The object convertible to value.
1823 
1824     \par Exception-safety
1825     basic
1826     */
1827     template <typename ValueConvertible>
1828     inline size_type remove_dispatch(ValueConvertible const& val_conv,
1829                                      std::true_type /*is_convertible*/)
1830     {
1831         return this->raw_remove(val_conv);
1832     }
1833 
1834     /*!
1835     \brief Remove a range of values from the index.
1836 
1837     \param rng    The range of values which will be removed from the container.
1838 
1839     \par Exception-safety
1840     basic
1841     */
1842     template <typename Range>
1843     inline size_type remove_dispatch(Range const& rng,
1844                                      std::false_type /*is_convertible*/)
1845     {
1846         size_type result = 0;
1847         typedef typename boost::range_const_iterator<Range>::type It;
1848         for ( It it = boost::const_begin(rng); it != boost::const_end(rng) ; ++it )
1849             result += this->raw_remove(*it);
1850         return result;
1851     }
1852 
1853     /*!
1854     \brief Return values meeting predicates.
1855 
1856     \par Exception-safety
1857     strong
1858     */
1859     template
1860     <
1861         typename Predicates, typename OutIter,
1862         std::enable_if_t<(detail::predicates_count_distance<Predicates>::value == 0), int> = 0
1863     >
1864     size_type query_dispatch(Predicates const& predicates, OutIter out_it) const
1865     {
1866         detail::rtree::visitors::spatial_query<members_holder, Predicates, OutIter>
1867             query(m_members, predicates, out_it);
1868         return query.apply(m_members);
1869     }
1870 
1871     /*!
1872     \brief Perform nearest neighbour search.
1873 
1874     \par Exception-safety
1875     strong
1876     */
1877     template
1878     <
1879         typename Predicates, typename OutIter,
1880         std::enable_if_t<(detail::predicates_count_distance<Predicates>::value > 0), int> = 0
1881     >
1882     size_type query_dispatch(Predicates const& predicates, OutIter out_it) const
1883     {
1884         BOOST_GEOMETRY_STATIC_ASSERT((detail::predicates_count_distance<Predicates>::value == 1),
1885                                      "Only one distance predicate can be passed.",
1886                                      Predicates);
1887 
1888         detail::rtree::visitors::distance_query<members_holder, Predicates>
1889             distance_v(m_members, predicates);
1890 
1891         return distance_v.apply(m_members, out_it);
1892     }
1893 
1894     /*!
1895     \brief Count elements corresponding to value or indexable.
1896 
1897     \par Exception-safety
1898     strong
1899     */
1900     template <typename ValueOrIndexable>
1901     size_type raw_count(ValueOrIndexable const& vori) const
1902     {
1903         BOOST_GEOMETRY_INDEX_ASSERT(m_members.root, "The root must exist");
1904 
1905         detail::rtree::visitors::count
1906             <
1907                 ValueOrIndexable,
1908                 members_holder
1909             > count_v(vori, m_members.parameters(), m_members.translator());
1910 
1911         detail::rtree::apply_visitor(count_v, *m_members.root);
1912 
1913         return count_v.found_count;
1914     }
1915 
1916     /*!
1917     \brief The constructor TODO.
1918 
1919     The tree is created using packing algorithm.
1920 
1921     \param first             The beginning of the range of Values.
1922     \param last              The end of the range of Values.
1923     \param temp_allocator    The temporary allocator object to be used by the packing algorithm.
1924 
1925     \par Throws
1926     \li If allocator copy constructor throws.
1927     \li If Value copy constructor or copy assignment throws.
1928     \li If allocation throws or returns invalid value.
1929     */
1930     template<typename Iterator, typename PackAlloc>
1931     inline void pack_construct(Iterator first, Iterator last, PackAlloc const& temp_allocator)
1932     {
1933         typedef detail::rtree::pack<members_holder> pack;
1934         size_type vc = 0, ll = 0;
1935         m_members.root = pack::apply(first, last, vc, ll,
1936                                      m_members.parameters(), m_members.translator(),
1937                                      m_members.allocators(), temp_allocator);
1938         m_members.values_count = vc;
1939         m_members.leafs_level = ll;
1940     }
1941 
1942     members_holder m_members;
1943 };
1944 
1945 /*!
1946 \brief Insert a value to the index.
1947 
1948 It calls <tt>rtree::insert(value_type const&)</tt>.
1949 
1950 \ingroup rtree_functions
1951 
1952 \param tree The spatial index.
1953 \param v    The value which will be stored in the index.
1954 */
1955 template <typename Value, typename Parameters, typename IndexableGetter, typename EqualTo, typename Allocator>
1956 inline void insert(rtree<Value, Parameters, IndexableGetter, EqualTo, Allocator> & tree,
1957                    Value const& v)
1958 {
1959     tree.insert(v);
1960 }
1961 
1962 /*!
1963 \brief Insert a range of values to the index.
1964 
1965 It calls <tt>rtree::insert(Iterator, Iterator)</tt>.
1966 
1967 \ingroup rtree_functions
1968 
1969 \param tree     The spatial index.
1970 \param first    The beginning of the range of values.
1971 \param last     The end of the range of values.
1972 */
1973 template<typename Value, typename Parameters, typename IndexableGetter, typename EqualTo, typename Allocator,
1974          typename Iterator>
1975 inline void insert(rtree<Value, Parameters, IndexableGetter, EqualTo, Allocator> & tree,
1976                    Iterator first, Iterator last)
1977 {
1978     tree.insert(first, last);
1979 }
1980 
1981 /*!
1982 \brief Insert a value created using convertible object or a range of values to the index.
1983 
1984 It calls <tt>rtree::insert(ConvertibleOrRange const&)</tt>.
1985 
1986 \ingroup rtree_functions
1987 
1988 \param tree             The spatial index.
1989 \param conv_or_rng      The object of type convertible to value_type or a range of values.
1990 */
1991 template<typename Value, typename Parameters, typename IndexableGetter, typename EqualTo, typename Allocator,
1992          typename ConvertibleOrRange>
1993 inline void insert(rtree<Value, Parameters, IndexableGetter, EqualTo, Allocator> & tree,
1994                    ConvertibleOrRange const& conv_or_rng)
1995 {
1996     tree.insert(conv_or_rng);
1997 }
1998 
1999 /*!
2000 \brief Remove a value from the container.
2001 
2002 Remove a value from the container. In contrast to the \c std::set or <tt>std::map erase()</tt> method
2003 this function removes only one value from the container.
2004 
2005 It calls <tt>rtree::remove(value_type const&)</tt>.
2006 
2007 \ingroup rtree_functions
2008 
2009 \param tree The spatial index.
2010 \param v    The value which will be removed from the index.
2011 
2012 \return     1 if value was removed, 0 otherwise.
2013 */
2014 template <typename Value, typename Parameters, typename IndexableGetter, typename EqualTo, typename Allocator>
2015 inline typename rtree<Value, Parameters, IndexableGetter, EqualTo, Allocator>::size_type
2016 remove(rtree<Value, Parameters, IndexableGetter, EqualTo, Allocator> & tree,
2017        Value const& v)
2018 {
2019     return tree.remove(v);
2020 }
2021 
2022 /*!
2023 \brief Remove a range of values from the container.
2024 
2025 Remove a range of values from the container. In contrast to the \c std::set or <tt>std::map erase()</tt> method
2026 it doesn't take iterators pointing to values stored in this container. It removes values equal
2027 to these passed as a range. Furthermore this function removes only one value for each one passed
2028 in the range, not all equal values.
2029 
2030 It calls <tt>rtree::remove(Iterator, Iterator)</tt>.
2031 
2032 \ingroup rtree_functions
2033 
2034 \param tree     The spatial index.
2035 \param first    The beginning of the range of values.
2036 \param last     The end of the range of values.
2037 
2038 \return         The number of removed values.
2039 */
2040 template<typename Value, typename Parameters, typename IndexableGetter, typename EqualTo, typename Allocator,
2041          typename Iterator>
2042 inline typename rtree<Value, Parameters, IndexableGetter, EqualTo, Allocator>::size_type
2043 remove(rtree<Value, Parameters, IndexableGetter, EqualTo, Allocator> & tree,
2044        Iterator first, Iterator last)
2045 {
2046     return tree.remove(first, last);
2047 }
2048 
2049 /*!
2050 \brief Remove a value corresponding to an object convertible to it or a range of values from the container.
2051 
2052 Remove a value corresponding to an object convertible to it or a range of values from the container.
2053 In contrast to the \c std::set or <tt>std::map erase()</tt> method
2054 it removes values equal to these passed as a range. Furthermore this method removes only
2055 one value for each one passed in the range, not all equal values.
2056 
2057 It calls <tt>rtree::remove(ConvertibleOrRange const&)</tt>.
2058 
2059 \ingroup rtree_functions
2060 
2061 \param tree                 The spatial index.
2062 \param conv_or_rng      The object of type convertible to value_type or the range of values.
2063 
2064 \return         The number of removed values.
2065 */
2066 template<typename Value, typename Parameters, typename IndexableGetter, typename EqualTo, typename Allocator,
2067          typename ConvertibleOrRange>
2068 inline typename rtree<Value, Parameters, IndexableGetter, EqualTo, Allocator>::size_type
2069 remove(rtree<Value, Parameters, IndexableGetter, EqualTo, Allocator> & tree,
2070        ConvertibleOrRange const& conv_or_rng)
2071 {
2072     return tree.remove(conv_or_rng);
2073 }
2074 
2075 /*!
2076 \brief Finds values meeting passed predicates e.g. nearest to some Point and/or intersecting some Box.
2077 
2078 This query function performs spatial and k-nearest neighbor searches. It allows to pass a set of predicates.
2079 Values will be returned only if all predicates are met.
2080 
2081 <b>Spatial predicates</b>
2082 
2083 Spatial predicates may be generated by one of the functions listed below:
2084 \li \c boost::geometry::index::contains(),
2085 \li \c boost::geometry::index::covered_by(),
2086 \li \c boost::geometry::index::covers(),
2087 \li \c boost::geometry::index::disjoint(),
2088 \li \c boost::geometry::index::intersects(),
2089 \li \c boost::geometry::index::overlaps(),
2090 \li \c boost::geometry::index::within(),
2091 
2092 It is possible to negate spatial predicates:
2093 \li <tt>! boost::geometry::index::contains()</tt>,
2094 \li <tt>! boost::geometry::index::covered_by()</tt>,
2095 \li <tt>! boost::geometry::index::covers()</tt>,
2096 \li <tt>! boost::geometry::index::disjoint()</tt>,
2097 \li <tt>! boost::geometry::index::intersects()</tt>,
2098 \li <tt>! boost::geometry::index::overlaps()</tt>,
2099 \li <tt>! boost::geometry::index::within()</tt>
2100 
2101 <b>Satisfies predicate</b>
2102 
2103 This is a special kind of predicate which allows to pass a user-defined function or function object which checks
2104 if Value should be returned by the query. It's generated by:
2105 \li \c boost::geometry::index::satisfies().
2106 
2107 <b>Nearest predicate</b>
2108 
2109 If the nearest predicate is passed a k-nearest neighbor search will be performed. This query will result
2110 in returning k values to the output iterator. Only one nearest predicate may be passed to the query.
2111 It may be generated by:
2112 \li \c boost::geometry::index::nearest().
2113 
2114 <b>Connecting predicates</b>
2115 
2116 Predicates may be passed together connected with \c operator&&().
2117 
2118 \par Example
2119 \verbatim
2120 // return elements intersecting box
2121 bgi::query(tree, bgi::intersects(box), std::back_inserter(result));
2122 // return elements intersecting poly but not within box
2123 bgi::query(tree, bgi::intersects(poly) && !bgi::within(box), std::back_inserter(result));
2124 // return elements overlapping box and meeting my_fun value predicate
2125 bgi::query(tree, bgi::overlaps(box) && bgi::satisfies(my_fun), std::back_inserter(result));
2126 // return 5 elements nearest to pt and elements are intersecting box
2127 bgi::query(tree, bgi::nearest(pt, 5) && bgi::intersects(box), std::back_inserter(result));
2128 
2129 // For each found value do_something (it is a type of function object)
2130 tree.query(bgi::intersects(box),
2131            boost::make_function_output_iterator(do_something()));
2132 \endverbatim
2133 
2134 \par Throws
2135 If Value copy constructor or copy assignment throws.
2136 
2137 \warning
2138 Only one \c nearest() predicate may be passed to the query. Passing more of them results in compile-time error.
2139 
2140 \ingroup rtree_functions
2141 
2142 \param tree         The rtree.
2143 \param predicates   Predicates.
2144 \param out_it       The output iterator, e.g. generated by std::back_inserter().
2145 
2146 \return             The number of values found.
2147 */
2148 template <typename Value, typename Parameters, typename IndexableGetter, typename EqualTo, typename Allocator,
2149           typename Predicates, typename OutIter> inline
2150 typename rtree<Value, Parameters, IndexableGetter, EqualTo, Allocator>::size_type
2151 query(rtree<Value, Parameters, IndexableGetter, EqualTo, Allocator> const& tree,
2152       Predicates const& predicates,
2153       OutIter out_it)
2154 {
2155     return tree.query(predicates, out_it);
2156 }
2157 
2158 /*!
2159 \brief Returns the query iterator pointing at the begin of the query range.
2160 
2161 This method returns the iterator which may be used to perform iterative queries. For the information
2162 about the predicates which may be passed to this method see query().
2163 
2164 \par Example
2165 \verbatim
2166 std::for_each(bgi::qbegin(tree, bgi::nearest(pt, 3)), bgi::qend(tree), do_something());
2167 \endverbatim
2168 
2169 \par Iterator category
2170 ForwardIterator
2171 
2172 \par Throws
2173 If predicates copy throws.
2174 If allocation throws.
2175 
2176 \warning
2177 The modification of the rtree may invalidate the iterators.
2178 
2179 \ingroup rtree_functions
2180 
2181 \param tree         The rtree.
2182 \param predicates   Predicates.
2183 
2184 \return             The iterator pointing at the begin of the query range.
2185 */
2186 template <typename Value, typename Parameters, typename IndexableGetter, typename EqualTo, typename Allocator,
2187           typename Predicates> inline
2188 typename rtree<Value, Parameters, IndexableGetter, EqualTo, Allocator>::const_query_iterator
2189 qbegin(rtree<Value, Parameters, IndexableGetter, EqualTo, Allocator> const& tree,
2190        Predicates const& predicates)
2191 {
2192     return tree.qbegin(predicates);
2193 }
2194 
2195 /*!
2196 \brief Returns the query iterator pointing at the end of the query range.
2197 
2198 This method returns the iterator which may be used to check if the query has ended.
2199 
2200 \par Example
2201 \verbatim
2202 std::for_each(bgi::qbegin(tree, bgi::nearest(pt, 3)), bgi::qend(tree), do_something());
2203 \endverbatim
2204 
2205 \par Iterator category
2206 ForwardIterator
2207 
2208 \par Throws
2209 Nothing
2210 
2211 \warning
2212 The modification of the rtree may invalidate the iterators.
2213 
2214 \ingroup rtree_functions
2215 
2216 \return             The iterator pointing at the end of the query range.
2217 */
2218 template <typename Value, typename Parameters, typename IndexableGetter, typename EqualTo, typename Allocator> inline
2219 typename rtree<Value, Parameters, IndexableGetter, EqualTo, Allocator>::const_query_iterator
2220 qend(rtree<Value, Parameters, IndexableGetter, EqualTo, Allocator> const& tree)
2221 {
2222     return tree.qend();
2223 }
2224 
2225 /*!
2226 \brief Returns the iterator pointing at the begin of the rtree values range.
2227 
2228 This method returns the iterator which may be used to iterate over all values
2229 stored in the rtree.
2230 
2231 \par Example
2232 \verbatim
2233 std::for_each(bgi::begin(tree), bgi::end(tree), do_something());
2234 // the same as
2235 std::for_each(boost::begin(tree), boost::end(tree), do_something());
2236 \endverbatim
2237 
2238 \par Iterator category
2239 ForwardIterator
2240 
2241 \par Throws
2242 If allocation throws.
2243 
2244 \warning
2245 The modification of the rtree may invalidate the iterators.
2246 
2247 \ingroup rtree_functions
2248 
2249 \return             The iterator pointing at the begin of the range.
2250 */
2251 template <typename Value, typename Parameters, typename IndexableGetter, typename EqualTo, typename Allocator> inline
2252 typename rtree<Value, Parameters, IndexableGetter, EqualTo, Allocator>::const_iterator
2253 begin(rtree<Value, Parameters, IndexableGetter, EqualTo, Allocator> const& tree)
2254 {
2255     return tree.begin();
2256 }
2257 
2258 /*!
2259 \brief Returns the iterator pointing at the end of the rtree values range.
2260 
2261 This method returns the iterator which may be compared with the iterator returned by begin()
2262 in order to check if the iteration has ended.
2263 
2264 \par Example
2265 \verbatim
2266 std::for_each(bgi::begin(tree), bgi::end(tree), do_something());
2267 // the same as
2268 std::for_each(boost::begin(tree), boost::end(tree), do_something());
2269 \endverbatim
2270 
2271 \par Iterator category
2272 ForwardIterator
2273 
2274 \par Throws
2275 Nothing.
2276 
2277 \warning
2278 The modification of the rtree may invalidate the iterators.
2279 
2280 \ingroup rtree_functions
2281 
2282 \return             The iterator pointing at the end of the range.
2283 */
2284 template <typename Value, typename Parameters, typename IndexableGetter, typename EqualTo, typename Allocator> inline
2285 typename rtree<Value, Parameters, IndexableGetter, EqualTo, Allocator>::const_iterator
2286 end(rtree<Value, Parameters, IndexableGetter, EqualTo, Allocator> const& tree)
2287 {
2288     return tree.end();
2289 }
2290 
2291 /*!
2292 \brief Remove all values from the index.
2293 
2294 It calls \c rtree::clear().
2295 
2296 \ingroup rtree_functions
2297 
2298 \param tree     The spatial index.
2299 */
2300 template <typename Value, typename Parameters, typename IndexableGetter, typename EqualTo, typename Allocator>
2301 inline void clear(rtree<Value, Parameters, IndexableGetter, EqualTo, Allocator> & tree)
2302 {
2303     return tree.clear();
2304 }
2305 
2306 /*!
2307 \brief Get the number of values stored in the index.
2308 
2309 It calls \c rtree::size().
2310 
2311 \ingroup rtree_functions
2312 
2313 \param tree     The spatial index.
2314 
2315 \return         The number of values stored in the index.
2316 */
2317 template <typename Value, typename Parameters, typename IndexableGetter, typename EqualTo, typename Allocator>
2318 inline size_t size(rtree<Value, Parameters, IndexableGetter, EqualTo, Allocator> const& tree)
2319 {
2320     return tree.size();
2321 }
2322 
2323 /*!
2324 \brief Query if there are no values stored in the index.
2325 
2326 It calls \c rtree::empty().
2327 
2328 \ingroup rtree_functions
2329 
2330 \param tree     The spatial index.
2331 
2332 \return         true if there are no values in the index.
2333 */
2334 template <typename Value, typename Parameters, typename IndexableGetter, typename EqualTo, typename Allocator>
2335 inline bool empty(rtree<Value, Parameters, IndexableGetter, EqualTo, Allocator> const& tree)
2336 {
2337     return tree.bounds();
2338 }
2339 
2340 /*!
2341 \brief Get the box containing all stored values or an invalid box if the index has no values.
2342 
2343 It calls \c rtree::envelope().
2344 
2345 \ingroup rtree_functions
2346 
2347 \param tree     The spatial index.
2348 
2349 \return         The box containing all stored values or an invalid box.
2350 */
2351 template <typename Value, typename Parameters, typename IndexableGetter, typename EqualTo, typename Allocator>
2352 inline typename rtree<Value, Parameters, IndexableGetter, EqualTo, Allocator>::bounds_type
2353 bounds(rtree<Value, Parameters, IndexableGetter, EqualTo, Allocator> const& tree)
2354 {
2355     return tree.bounds();
2356 }
2357 
2358 /*!
2359 \brief Exchanges the contents of the container with those of other.
2360 
2361 It calls \c rtree::swap().
2362 
2363 \ingroup rtree_functions
2364 
2365 \param l     The first rtree.
2366 \param r     The second rtree.
2367 */
2368 template <typename Value, typename Parameters, typename IndexableGetter, typename EqualTo, typename Allocator>
2369 inline void swap(rtree<Value, Parameters, IndexableGetter, EqualTo, Allocator> & l,
2370                  rtree<Value, Parameters, IndexableGetter, EqualTo, Allocator> & r)
2371 {
2372     return l.swap(r);
2373 }
2374 
2375 }}} // namespace boost::geometry::index
2376 
2377 // Boost.Range adaptation
2378 namespace boost {
2379 
2380 template <typename Value, typename Parameters, typename IndexableGetter, typename EqualTo, typename Allocator>
2381 struct range_mutable_iterator
2382     <
2383         boost::geometry::index::rtree<Value, Parameters, IndexableGetter, EqualTo, Allocator>
2384     >
2385 {
2386     typedef typename boost::geometry::index::rtree
2387         <
2388             Value, Parameters, IndexableGetter, EqualTo, Allocator
2389         >::const_iterator type;
2390 };
2391 
2392 } // namespace boost
2393 
2394 #include <boost/geometry/index/detail/config_end.hpp>
2395 
2396 #endif // BOOST_GEOMETRY_INDEX_RTREE_HPP