C++ 获取向量对的range-v3交点

C++ 获取向量对的range-v3交点,c++,c++17,range-v3,C++,C++17,Range V3,我想得到两个向量对的交点。我可以用使用默认比较器的stl来做这件事(?-如果我说错了,请纠正我) 我尝试按照此操作,但无法将其编译,因为模板无法专门化: error C2672: 'operator __surrogate_func': no matching overloaded function found 我需要提供自定义比较器吗?我在编译ranges::sort时也遇到了问题。这是因为std::vector专门用于非平凡类型std::pair?ranges::view::set_int

我想得到两个向量对的交点。我可以用使用默认比较器的stl来做这件事(?-如果我说错了,请纠正我)

我尝试按照此操作,但无法将其编译,因为模板无法专门化:

error C2672: 'operator __surrogate_func': no matching overloaded function found

我需要提供自定义比较器吗?我在编译
ranges::sort
时也遇到了问题。这是因为
std::vector
专门用于非平凡类型
std::pair

ranges::view::set_intersection
将结果作为新范围(在本例中为新视图)返回。请参阅如何使用该功能

例如:

using IntPair = std::pair<int,int>;
using IntPairVector = std::vector<IntPair>;

IntPairVector pathWire1 = {{1,1}, {2,2}, {3,3}};
IntPairVector pathWire2 = { {2,2}, {0,0}};

ranges::sort(pathWire1);
ranges::sort(pathWire2);
auto res = ranges::view::set_intersection(pathWire1, pathWire2);

for(auto&& p : res)
    std::cout << p.first << ' ' << p.second << '\n';

// prints 2 2
使用IntPair=std::pair;
使用IntPairVector=std::vector;
IntPairVector路径1={{1,1},{2,2},{3,3};
IntPairvectorPathWire2={{2,2},{0,0};
范围::排序(路径1);
范围::排序(路径2);
自动恢复=范围::视图::设置交叉点(pathWire1,pathWire2);
用于(自动和p:res)

cout如果您想要即时评估,请不要使用视图:提供的示例适用于wandbox和其他在线编译器。然而,在我的本地版本中,我使用的是ranges-v3 0.9.1,我仍然无法编译它。我使用MSVC版本19.23.28107在Windows下构建。有什么建议吗?请参阅MSVC的这篇博文:。简而言之,使用
vcpkg
安装
range-v3
,因为需要进行一些修改才能使用MSVC进行编译。
error C2672: 'operator __surrogate_func': no matching overloaded function found
using IntPair = std::pair<int,int>;
using IntPairVector = std::vector<IntPair>;

IntPairVector pathWire1 = {{1,1}, {2,2}, {3,3}};
IntPairVector pathWire2 = { {2,2}, {0,0}};

ranges::sort(pathWire1);
ranges::sort(pathWire2);
auto res = ranges::view::set_intersection(pathWire1, pathWire2);

for(auto&& p : res)
    std::cout << p.first << ' ' << p.second << '\n';

// prints 2 2