ZBLOG

results.emplace_back( tls->split_thread_pool.enqueue( [&json_rfs_route,i](i)->pair{ int64_t time_stamp = json_rfs_route[i]["time_stamp"].asInt64()...

修改后的代码如下所示:

  1. results.emplace_back(
  2. tls->split_thread_pool.enqueue([&json_rfs_route, i](int) -> std::pair<int64_t, std::vector<service::GeoPoint>> {
  3. int64_t time_stamp = json_rfs_route[i]["time_stamp"].asInt64();
  4. std::vector<service::GeoPoint> temp;
  5. if (json_rfs_route[i].isMember("route") && json_rfs_route[i]["route"].isString()) {
  6. std::string str_route = json_rfs_route[i]["route"].asString();
  7. std::vector<std::string> points = split(str_route, ';');
  8. for (auto& point : points) {
  9. if (point.empty()) {
  10. continue;
  11. }
  12. std::vector<std::string> p_str = split(point, ',');
  13. its::service::GeoPoint geo_p;
  14. geo_p.longitude = stod(p_str[0]);
  15. geo_p.latitude = stod(p_str[1]);
  16. temp.emplace_back(geo_p);
  17. }
  18. } else if (json_rfs_route[i].isMember("route") && json_rfs_route[i]["route"].isArray()) {
  19. Json::Value& json_route = json_rfs_route[i]["route"];
  20. for (int j = 0; j < json_route.size(); j++) {
  21. service::GeoPoint p;
  22. p.latitude = json_route[j]["lat"].asDouble();
  23. p.longitude = json_route[j]["lng"].asDouble();
  24. temp.emplace_back(p);
  25. }
  26. }
  27. return std::make_pair(time_stamp, temp);
  28. })
  29. );

这段代码是将一个lambda表达式作为参数传递给 enqueue() 函数,并使用 emplace_back() 将返回的结果添加到 results 容器中。在lambda函数体内部,进行了一些JSON数据处理和向 temp 向量中添加元素的操作。注意修改了 lambda 函数参数列表中的类型,以及将 make_pair() 函数改为了 std::make_pair()

请根据您的需求对代码做出适当调整和修改。


内容由零声教学AI助手提供,问题来源于学员提问

本站部分文章来源于网络,版权归原作者所有,如有侵权请联系站长删除。
转载请注明出处:https://golang.0voice.com/?id=15638

分享:
扫描分享到社交APP
上一篇
下一篇
发表列表
游客 游客
此处应有掌声~
评论列表

还没有评论,快来说点什么吧~

联系我们

在线咨询: 点击这里给我发消息

微信号:3007537140

上班时间: 10:30-22:30

关注我们
x

注册

已经有帐号?