简体   繁体   English

在std :: upper_bound中的boost :: transform_iterator编译错误

[英]boost::transform_iterator in std::upper_bound compile error

I have a list of nodes sorted by z-order ( http://en.wikipedia.org/wiki/Z-order_curve ). 我有一个按z顺序排序的节点列表( http://en.wikipedia.org/wiki/Z-order_curve )。 I am trying to find the first node bigger than zPosition. 我试图找到比zPosition大的第一个节点。 The iterTransform object takes an iterator and returns a binary position representation (same type as zPosition). iterTransform对象使用一个迭代器并返回一个二进制位置表示形式(与zPosition相同的类型)。 This type can be compared by pathCmp 可以通过pathCmp进行比较

NodeIterT last = std::upper_bound(
    boost::make_transform_iterator(begin, iterTransform), // return PathType
    boost::make_transform_iterator(end, iterTransform),
    zPosition,
    pathCmp ); // takes two PathType arguments

when compiling this I get 编译时我得到

error C2440: 'initializing' : cannot convert from 'boost::transform_iterator < UnaryFunc,Iterator,Reference,Value > ' to 'std::_Vector_iterator<_Myvec>' 错误C2440:'正在初始化':无法从'boost :: transform_iterator <UnaryFunc,Iterator,Reference,Value>'转换为'std :: _ Vector_iterator <_Myvec>'

Is there any mistake in this minimized example or do I need to provide more code? 这个最小化的示例中是否有任何错误,还是我需要提供更多代码?

std::upper_bound returns a transform_iterator . std::upper_bound返回一个transform_iterator Add .base() to get the iterator type that you wrapped: 添加.base()以获取包装的迭代器类型:

NodeIterT last = std::upper_bound(
boost::make_transform_iterator(begin, iterTransform), // return PathType
boost::make_transform_iterator(end, iterTransform),
zPosition,
pathCmp ).base();

should work assuming begin and end are of NodeIterT type. 假设beginendNodeIterT类型,则应该可以正常工作。

std::upper_bound returns an iterator with the same type as those given as parameters. std::upper_bound返回一个迭代器,其类型与作为参数给出的类型相同。 In your case, the return type is therefore boost::transform_iterator<...> and not std::vector<...>::iterator . 因此,在您的情况下,返回类型为boost::transform_iterator<...>而不是std::vector<...>::iterator

If you want to access the underlying iterator, you can use the base() member function : 如果要访问底层的迭代器,则可以使用base()成员函数

NodeIterT last = std::upper_bound(
    boost::make_transform_iterator(begin, iterTransform), // return PathType
    boost::make_transform_iterator(end, iterTransform),
    zPosition,
    pathCmp ).base(); // note the call to base()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM