使用 boost::property_tree 自动失败?

问题描述

在使用 boost::property_tree 解析 json 时,我遇到了一个错误并找到了一个修复程序,但我不明白为什么这个修复程序有效,或者首先是什么错误。看起来 auto 在这里失败了 - 因此标题 - 但我也可能完全错误..?

我在 cygwin 中使用 C++17 和 gcc 10.2.0

使用以下代码我得到 error: expected primary-expression before 'int'

// const boost::property_tree:ptree elems = ...    // a json array
const auto max_elem = *std::max_element(elems.begin(),elems.end(),[](const auto& lhs,const auto& rhs) {
    return (lhs.second.get<int>("size") < rhs.second.get<int>("size");
  }
);

但是如果命名 lambda 的参数类型,它会编译:

// const boost::property_tree:ptree elems = ...    // a json array
using Element = boost::property_tree::ptree::value_type;
const Element max_elem = *std::max_element(elems.begin(),[](const Element& lhs,const Element& rhs) {
    return (lhs.second.get<int>("size") < rhs.second.get<int>("size");
  }
);

错误消息似乎没有告诉我任何事情,所以如果我在不知道为什么它不起作用的情况下再次遇到这个错误,这看起来很糟糕。据我所知,这应该是与 C++14 相同的代码......为什么不是?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)