在 Windows 的 IndexableGetter 中使用 boost::geometry::index::indexable [英] Using boost::geometry::index::indexable within an IndexableGetter in Windows

查看:30
本文介绍了在 Windows 的 IndexableGetter 中使用 boost::geometry::index::indexable的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

建立在这个例子之上:

https nofollow://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 可以理解的任何类型.

I have constructed the following MWE to build and query spatial trees based on indices onto non-trivial containers. The example this was based upon assumes that Container::value_type is already a leaf of the tree. I simply adapted the example to work with any indexable type, i.e., any type understood by bgi::indexable<typename Container::value_type>.

包含的 MWE 在 Linux 和 Mac 上运行良好,但无法在 Windows 上编译,我正在努力理解问题可能是什么.这里有一个工作示例 https://godbolt.org/z/vTT5r5MWc,您可以在其中看到如果您切换到 gcc 或 clang,一切正常,但使用 MSVC19,我们会收到下面报告的错误.

The included MWE works just fine on Linux and Mac, but fails to compile on Windows, and I'm struggling in understanding what the problem may be. A working example is here https://godbolt.org/z/vTT5r5MWc, where you can see that if you switch to gcc or clang, everything works, but with MSVC19 we get the errors reported below.

关于如何修改 IndexableGetter/其他任何东西以使其在 MSVC 下工作的任何想法?

Any idea on how to modify the IndexableGetter/anything else to make this work under 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 上遇到的错误是

The error I get on Windows is

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>,std::allocator<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>,std::allocator<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>,std::allocator<std::pair<Point,int>>>>,
            EqualTo=boost::geometry::index::equal_to<std::_Default_allocator_traits<std::allocator<std::pair<Point,int>>>::size_type>
        ]

....

推荐答案

感谢提供一个非常简洁的独立示例.

Thanks for a very neat self-contained example.

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

回想起来有线索:

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

这篇关于在 Windows 的 IndexableGetter 中使用 boost::geometry::index::indexable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆