在 Windows 的 IndexableGetter 中使用 boost::geometry::index::indexable

问题描述

建立在这个例子之上:

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,我们会收到以下报告的错误。

关于如何修改 IndexableGetter/其他任何东西以使其在 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,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,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/include\boost/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>>>>
        ]
C:/data/libraries/installed/x64-windows/include\boost/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>>>>
        ]
C:/data/libraries/installed/x64-windows/include\boost/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/include\boost/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>>>::size_type>
        ]

....

解决方法

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

它确实用 /std::latest 编译:

回想起来有线索:

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

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...