boost::phoenix.end 报错::"vector iterators incompatible"

time_is_life 2018-11-15 10:02:42
从书上拿下来的如下的代码:

namespace phx = boost::phoenix;
using phx::arg_names::arg1;
std::vector<std::string> greets{ "Hello", "Hola", "Hujambo",
"Hallo" };
auto finder = phx::find(greets, arg1);
auto it = finder("Hujambo");

assert(phx::end(greets)() != it); //Assert失败, 不太清楚为什么.
std::cout << *it << '\n';
assert(++it != greets.end());
std::cout << *it << '\n';

return 0;


运行到:
assert(phx::end(greets)() != it);
这一句的时候会报Assert失败,错误信息是:"vector iterators incompatible",到底是为什么那?
请指教,谢谢
...全文
307 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
zarelaky 2018-12-05
  • 打赏
  • 举报
回复
如下代码在g++-4.9 -std=c++11 编译没问题,你用的是vc?

#include <iostream>
#include <vector>
#include <boost/phoenix/stl/container.hpp>
#include <boost/phoenix/stl/algorithm.hpp>
#include <boost/phoenix/core/argument.hpp>

int main(int argc, char* argv[]) {

namespace phx = boost::phoenix;
using phx::arg_names::arg1;
std::vector<std::string> greets{ "Hello", "Hola", "Hujambo",
"Hallo" };
auto finder = phx::find(greets, arg1);
auto it = finder("Hujambo");

assert(phx::end(greets)() != it); //Assert失败, 不太清楚为什么.
std::cout << *it << '\n';
assert(++it != greets.end());
std::cout << *it << '\n';

return 0;
}

24,855

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 工具平台和程序库
社区管理员
  • 工具平台和程序库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧