【问题标题】:Boost 1.65.1 geometry distance strategy compile error with Visual Studio 2017Boost 1.65.1 几何距离策略使用 Visual Studio 2017 编译错误
【发布时间】:2018-02-19 18:31:22
【问题描述】:

尝试使用新版本的 boost 1.65.1 编译我的项目时,我收到以下错误:

C:\Users\twozn\Dev\soundtoolkit\stk\libraries\boost/geometry/strategies/distance.hpp(101): error C2664: 'int boost::mpl::assertion_failed<false>(boost::mpl::assert<false>::type)': cannot convert argument 1 from 'boost::mpl::failed ************(__cdecl boost::geometry::strategy::distance::services::default_strategy<boost::geometry::point_tag,boost::geometry::segment_tag,boost::geometry::model::point<float,2,boost::geometry::cs::cartesian>,boost::geometry::model::point<float,2,boost::geometry::cs::cartesian>,boost::geometry::cartesian_tag,boost::geometry::cartesian_tag,void>::NOT_IMPLEMENTED_FOR_THIS_POINT_TYPE_COMBINATION::* ***********)(boost::mpl::assert_::types<Point1,Point2,CsTag1,CsTag2>)' to 'boost::mpl::assert<false>::type'
1>        with
1>        [
1>            Point1=boost::geometry::model::point<float,2,boost::geometry::cs::cartesian>,
1>            Point2=boost::geometry::model::point<float,2,boost::geometry::cs::cartesian>,
1>            CsTag1=boost::geometry::cartesian_tag,
1>            CsTag2=boost::geometry::cartesian_tag
1>        ]

由线路触发

std::vector<Value> results;
rtree.query(boost::geometry::index::nearest(Point(p.x, p.y), 1), std::back_inserter(results));

上面的rtree定义为

using Point = boost::geometry::model::point<float, 2,boost::geometry::cs::cartesian>;
using Segment = boost::geometry::model::segment<Point>;
using Value = std::pair<Segment, size_t>;
boost::geometry::index::rtree<Value, boost::geometry::index::rstar<16>> rtree;

触发的断言是(boost/geometry/strategies/distance.hpp):

template
<
    typename GeometryTag1,
    typename GeometryTag2,
    typename Point1,
    typename Point2 = Point1,
    typename CsTag1 = typename cs_tag<Point1>::type,
    typename CsTag2 = typename cs_tag<Point2>::type,
    typename UnderlyingStrategy = void
>
struct default_strategy
{
    BOOST_MPL_ASSERT_MSG
        (
            false, NOT_IMPLEMENTED_FOR_THIS_POINT_TYPE_COMBINATION
            , (types<Point1, Point2, CsTag1, CsTag2>)
        );
};

这已编译并与 Boost 1.64.0 一起正常工作。编译器是 Visual Studio 2017 Update 1。这里有什么问题?

【问题讨论】:

  • 你能发布静态断言的相关位吗?它试图告诉你一些事情,但你把它剪掉了。 (还有results的类型?)
  • @sehe 我用(希望)相关位编辑了这个问题。

标签: c++ visual-studio boost boost-geometry


【解决方案1】:

由于无法访问 MSVC,我可以 /guess/ 您需要包含更多标头。可能它们被间接包含在 Boost 1.64.0 中。

看看能不能编译出以下自包含的例子:

Live On Coliru

#include <boost/geometry/geometry.hpp>
#include <boost/geometry/core/coordinate_system.hpp>
#include <boost/geometry/geometries/segment.hpp>
#include <boost/geometry/index/predicates.hpp>

using Point   = boost::geometry::model::point<float, 2,boost::geometry::cs::cartesian>;
using Segment = boost::geometry::model::segment<Point>;
using Value   = std::pair<Segment, size_t>;

int main() {
    boost::geometry::index::rtree<Value, boost::geometry::index::rstar<16>> rtree;

    std::vector<Value> results;
    rtree.query(boost::geometry::index::nearest(Point(1, 2), 1), std::back_inserter(results));
}

【讨论】:

  • 感谢@sehe,包括&lt;boost/geometry/index/predicates.hpp&gt; 已修复
  • 看起来所需的包含可能再次更改。在 Boost 1.67 中包含 &lt;boost/geometry/index/predicates.hpp&gt; 对我不起作用,但采取懒惰的方式并包含 &lt;boost/geometry/geometry.hpp&gt; 效果很好
  • Boost 1.68:我遇到了同样的问题,我发现&lt;boost/geometry/strategies/strategies.hpp&gt;&lt;boost/geometry/algorithms/comparable_distance.hpp&gt; 这两个标题都需要。有了这些,可以跳过长时间编译的&lt;boost/geometry.hpp&gt;
猜你喜欢
  • 2018-12-08
  • 2017-08-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-04-12
  • 2018-05-26
  • 2019-04-01
  • 2017-12-23
相关资源
最近更新 更多