c++ boost r-tree错误:std::pair的第一个类型必须是Indexable,我该怎么解决这个问题?

wmomyfyw  于 2023-05-08  发布在  其他
关注(0)|答案(1)|浏览(164)

我使用boost::geometry::index::rtreeEigen::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编译,我收到的错误
错误:静态Assert失败:std::pair的第一个类型必须是Indexable。24| static_assert(boost::geometry::detail::static_assert_check<(CHECK),VA_ARGS>::value,MESSAGE)
在Linux/GCC下编译时。这里出了什么问题,我该如何解决?

toe95027

toe950271#

不知何故,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;
}

相关问题