小编Ale*_*xBG的帖子

std::map, std::unordered_map - 初始化列表中的缩小转换

它是错误还是标准允许?

#include <iostream>
#include <map>
#include <unordered_map>

int main() {
    std::unordered_map<int,int> mm {{44,44}, {33.3, 54}, {222.2,222.2}};
    for(auto& [f,s] :mm) {
        std::cout<<f<<" - "<<s<<std::endl;
    }

    std::map<int,int> m {{44,44}, {33.3, 54}, {222.2,222.2}};
    for(auto& [f,s] :m) {
       std::cout<<f<<" - "<<s<<std::endl;
    }
}
Run Code Online (Sandbox Code Playgroud)

wandbox.org 上使用 clang10 和 gcc10对其进行测试。std::set和没有这样的问题std::unordered_set

c++ stdmap c++17

7
推荐指数
1
解决办法
104
查看次数

标签 统计

c++ ×1

c++17 ×1

stdmap ×1