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()...

修改后的代码如下所示:

results.emplace_back(
    tls->split_thread_pool.enqueue([&json_rfs_route, i](int) -> std::pair<int64_t, std::vector<service::GeoPoint>> {
        int64_t time_stamp = json_rfs_route[i]["time_stamp"].asInt64();
        std::vector<service::GeoPoint> temp;
        
        if (json_rfs_route[i].isMember("route") && json_rfs_route[i]["route"].isString()) {
            std::string str_route = json_rfs_route[i]["route"].asString();
            std::vector<std::string> points = split(str_route, ';');
            
            for (auto& point : points) {
                if (point.empty()) {
                    continue;
                }
                
                std::vector<std::string> p_str = split(point, ',');
                its::service::GeoPoint geo_p;
                geo_p.longitude = stod(p_str[0]);
                geo_p.latitude = stod(p_str[1]);
                
                temp.emplace_back(geo_p);
            }
        } else if (json_rfs_route[i].isMember("route") && json_rfs_route[i]["route"].isArray()) {
            Json::Value& json_route = json_rfs_route[i]["route"];
            
            for (int j = 0; j < json_route.size(); j++) {
                service::GeoPoint p;
                p.latitude = json_route[j]["lat"].asDouble();
                p.longitude = json_route[j]["lng"].asDouble();
                
                temp.emplace_back(p);
            }
        }
        
        return std::make_pair(time_stamp, temp);
    })
);

这段代码是将一个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

注册

已经有帐号?