在Windows中的IndexeableGetter中使用boost::geometry::index::indexab

Using boost::geometry::index::indexable within an IndexableGetter in Windows

本文关键字:boost geometry index indexab Windows 中的 IndexeableGetter      更新时间:2024-05-10

在此示例之上构建:

https://www.boost.org/doc/libs/1_75_0/libs/geometry/doc/html/geometry/spatial_indexes/rtree_examples/using_indexablegetter_function_object___storing_indexes_of_external_container_s_elements.html

我构建了以下MWE,以基于非平凡容器上的索引来构建和查询空间树。基于此的示例假设Container::value_type已经是树的一个叶子。我只是简单地调整了这个例子,使其适用于任何可索引类型,即bgi::indexable<typename Container::value_type>所理解的任何类型。

附带的MWE在Linux和Mac上运行良好,但在Windows上无法编译,我很难理解问题所在https://godbolt.org/z/vTT5r5MWc,你可以看到,如果你切换到gcc或clang,一切都会正常,但使用MSVC19,我们会收到下面报告的错误。

关于如何修改IndexeableGetter/其他任何东西以使其在MSVC下工作,有什么想法吗?

#include <boost/geometry/index/rtree.hpp>
#include <boost/geometry/strategies/strategies.hpp>
#include <boost/range/irange.hpp>
#include <iostream>

namespace bg  = boost::geometry;
namespace bgi = boost::geometry::index;
template <typename LeafType,
typename IndexType       = bgi::linear<16>,
typename IndexableGetter = bgi::indexable<LeafType>>
using RTree = bgi::rtree<LeafType, IndexType, IndexableGetter>;
using Point = bg::model::point<double, 2, bg::cs::cartesian>;
template <typename Container>
class IndexableGetterFromIndices
{
public:
using IndexableGetter =
typename bgi::indexable<typename Container::value_type>;
using result_type = typename IndexableGetter::result_type;
using size_t = typename Container::size_type;
explicit IndexableGetterFromIndices(Container const &c)
: container(c)
{}
result_type
operator()(size_t i) const
{
return getter(container[i]);
}
private:
const Container &container;
IndexableGetter getter;
};

template <typename IndexType = boost::geometry::index::linear<16>,
typename ContainerType>
RTree<typename ContainerType::size_type,
IndexType,
IndexableGetterFromIndices<ContainerType>>
pack_rtree_of_indices(const ContainerType &container)
{
boost::integer_range<typename ContainerType::size_type> indices(
0, container.size());
return RTree<typename ContainerType::size_type,
IndexType,
IndexableGetterFromIndices<ContainerType>>(
indices.begin(),
indices.end(),
IndexType(),
IndexableGetterFromIndices<ContainerType>(container));
}

int
main()
{
std::vector<std::pair<Point, int>> points;
// create some points
for (unsigned i = 0; i < 10; ++i)
points.push_back(std::make_pair(Point(i + 0.0, i + 0.0), i * 10));
const auto tree = pack_rtree_of_indices(points);
for (const auto result :
tree | bgi::adaptors::queried(bgi::nearest(Point(3.0, 4.0), 1)))
{
std::cout << "Nearest point: " << bg::wkt<Point>(points[result].first)
<< ", index = " << points[result].second << std::endl;
}
}

我在Windows上得到的错误是

example.cpp
C:/data/libraries/installed/x64-windows/includeboost/geometry/index/rtree.hpp(1762): error C2664: 'boost::geometry::index::detail::translator<IndexableGetter,EqualTo>::translator(const boost::geometry::index::indexable<std::pair<Point,int>> &,const EqualTo &)': cannot convert argument 1 from 'const IndGet' to 'const boost::geometry::index::indexable<std::pair<Point,int>> &'
with
[
IndexableGetter=IndexableGetterFromIndices<std::vector<std::pair<Point,int>,std::allocator<std::pair<Point,int>>>>,
EqualTo=boost::geometry::index::equal_to<std::_Default_allocator_traits<std::allocator<std::pair<Point,int>>>::size_type>
]
and
[
IndGet=IndexableGetterFromIndices<std::vector<std::pair<Point,int>,std::allocator<std::pair<Point,int>>>>
]
C:/data/libraries/installed/x64-windows/includeboost/geometry/index/rtree.hpp(1768): note: Reason: cannot convert from 'const IndGet' to 'const boost::geometry::index::indexable<std::pair<Point,int>>'
with
[
IndGet=IndexableGetterFromIndices<std::vector<std::pair<Point,int>,std::allocator<std::pair<Point,int>>>>
]
C:/data/libraries/installed/x64-windows/includeboost/geometry/index/rtree.hpp(1762): note: No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
C:/data/libraries/installed/x64-windows/includeboost/geometry/index/detail/translator.hpp(51): note: see declaration of 'boost::geometry::index::detail::translator<IndexableGetter,EqualTo>::translator'
with
[
IndexableGetter=IndexableGetterFromIndices<std::vector<std::pair<Point,int>,std::allocator<std::pair<Point,int>>>>,
EqualTo=boost::geometry::index::equal_to<std::_Default_allocator_traits<std::allocator<std::pair<Point,int>>>::size_type>
]
....

感谢您提供了一个非常简洁的自包含示例。

它确实使用/std::latest:进行编译

  • x86 msvc v19.latest,实时编译器资源管理器(
  • x64 msvc v19.latest,实时编译器资源管理器(

回想起来,有一条线索:

cl : Command line warning D9002 : ignoring unknown option '-std=c++2a'