std::map 的这两种列表初始化形式有什么区别
What is the difference between these two forms of list initialization for std::map?
我已经用clang测试了以下两种形式,它们都被接受:
using IntMap = std::map<int, int>;
IntMap map1 {{
{1, 1},
{2, 2},
{3, 3},
{4, 4}
}};
IntMap map2 {
{1, 1},
{2, 2},
{3, 3},
{4, 4}
};
在 Visual Studio 2013 上,后一个示例无法编译,说明 map 中没有接受 4 个参数的构造函数。
我假设两者都是有效的。两者有什么区别?为什么第二个示例在 Visual Studio 2013 上不起作用?
正如T.C.在评论中指出的那样,两者都是合法的。第一种样式可能会导致怪异,但如果第二种样式在VS2013中失败,那么这就是编译器错误)或部分实现)。
相关文章:
- 向量 <int> a {N, 0} 和 int arr a[N] = {0} 的时间复杂度有什么区别
- 在 .h 文件中的类中声明静态变量和在.cpp文件中声明"global"变量有什么区别
- 我是C++编程的新手,这些代码之间有什么区别,我应该使用哪一个
- 返回常量对象引用 (getter) 和仅返回字符串有什么区别?
- Qt:remove() 和 rmdir() 有什么区别
- 这 4 个 lambda 表达式之间有什么区别?
- 将向量作为类>(值)<向量启动和向量<类>[值]有什么区别
- typedef 枚举和枚举类有什么区别?
- &C::c 和 &(C::c) 有什么区别?
- ascii 和 unicode 在处理级别有什么区别吗?
- C 中的常量限定符和 C++ 中的常量限定符有什么区别?
- "ABC" 和 "ABC" ) 在C++中有什么区别?
- 空指针常量 (nullptr)、空指针值和空成员指针值之间有什么区别?
- 引用捕获和在 lambda 中通过引用发送参数有什么区别 (C++)
- 两种访问I2C总线的方法有什么区别?
- 两种模板示例有什么区别?
- 这两种C++语法之间有什么区别?
- lua 5.0.2 模块和 5.3.5 有什么区别?
- C++中"typedef"、"using"、"namespace"和"using namespace"有什么区别?
- std::enable_if 和 std::enable_if_t 有什么区别?