用元组遍历地图

时间:2019-03-09 01:21:22

标签: c++ dictionary tuples

我正在尝试遍历具有元组的地图。以下失败

std::map<int, std::tuple<int,       double, double, double>> database;

for (auto d : database){  
        if (std::get<3>(d) > temp){
            json tmp;
            tmp = { 
            { "result", "ok" },
            { "id", id },
            { "timestamp", std::get<0>(d) },
            { "x", std::get<1>(d) },
            { "y", std::get<2>(d) },
            { "temperature", std::get<3>(d) } 
            };
            result+=tmp;
        }
        id++;
}

错误消息很大,这是第一部分

temperature_server.cc:83:30: error: no matching function for call to 'get(std::pair<const int, std::tuple<int, double, double, double> >&)'
         if (std::get<3>(d) > temp){

1 个答案:

答案 0 :(得分:1)

更改为:

for (const auto& p : database){
    const auto& d = p.second; // std::tuple<int, double, double, double>
    // ...
相关问题