boost r-tree 错误:std::pair 的第一种类型必须是 Indexable。我该如何解决这个问题?

问题描述 投票:0回答:1

我正在使用

boost::geometry::index::rtree
Eigen::Vector
给出的点类型。为此,我声明

namespace boost
{
    namespace geometry
    {
        namespace traits
        {
            template<typename T, std::size_t D> struct tag<Eigen::Vector<T, D>> { using type = point_tag; };
            template<typename T, std::size_t D> struct dimension<Eigen::Vector<T, D>> : boost::mpl::int_<D> {};
            template<typename T, std::size_t D> struct coordinate_type<Eigen::Vector<T, D>> { using type = T; };
            template<typename T, std::size_t D> struct coordinate_system<Eigen::Vector<T, D>> { using type = boost::geometry::cs::cartesian; };

            template<typename T, std::size_t D, std::size_t Index>
            struct access<Eigen::Vector<T, D>, Index>
            {
                static_assert(Index < D, "out of range");

                using Point = Eigen::Vector<T, D>;
                using CoordinateType = typename coordinate_type<Point>::type;
                static inline CoordinateType get(Point const& p) { return p[Index]; }
                static inline void set(Point& p, CoordinateType const& value) { p[Index] = value; }
            };
        } // namespace traits
    } // namespace geometry
} // namespace boost

那我声明

template<class PointType>
using rtree = boost::geometry::index::rtree<PointType, boost::geometry::index::rstar<16>>;

rtree<std::pair<Eigen::Vector<double, 2>, std::size_t>> foo;
。虽然这可以使用 MSVC 完美编译,但我收到了错误消息

error: static assertion failed: 第一种类型的 std::pair 必须是 一个可索引的。 24 | static_assert(boost::geometry::detail::static_assert_check<(CHECK), VA_ARGS>::value, MESSAGE)

当我在 Linux/GCC 下编译它时。这里出了什么问题,我该如何解决?

c++ boost eigen boost-geometry r-tree
1个回答
0
投票

不知何故,GCC 不匹配部分模板专业化,除非您制作

std::size_t D
模板参数
int
.

这可能与缩小限制的内部解释有关,但我觉得这可能是一个错误(在某些版本的 GCC 中?)。 Clang 15 接受它就像您报告 MSVC 所做的那样。

更改也修复了我的 GCC 版本:

Live On Compiler Explorer

#include <Eigen/StdVector>
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/adapted/std_array.hpp>
#include <boost/geometry/geometries/register/point.hpp>
#include <boost/geometry/index/rtree.hpp>
namespace bgi = boost::geometry::index;

namespace boost::geometry::traits {
    template <typename T, int D> struct tag<Eigen::Vector<T, D>> {
        using type = point_tag;
    };
    template <typename T, int D> struct dimension<Eigen::Vector<T, D>> : boost::mpl::int_<D> {};
    template <typename T, int D> struct coordinate_type<Eigen::Vector<T, D>> {
        using type = T;
    };
    template <typename T, int D> struct coordinate_system<Eigen::Vector<T, D>> {
        using type = boost::geometry::cs::cartesian;
    };

    template <typename T, int D, std::size_t Index> struct access<Eigen::Vector<T, D>, Index> {
        static_assert(Index < D, "out of range");

        using Point          = Eigen::Vector<T, D>;
        using CoordinateType = typename coordinate_type<Point>::type;
        static inline CoordinateType get(Point const& p) { return p[Index]; }
        static inline void           set(Point& p, CoordinateType const& value) { p[Index] = value; }
    };
} // namespace boost::geometry::traits

int main() {//
    using Point = Eigen::Vector<double, 2>;
    bgi::rtree<std::pair<Point, std::size_t>, bgi::rstar<16>> foo;
}
© www.soinside.com 2019 - 2024. All rights reserved.