3

I have tested the following two forms with clang and they are both accepted:

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}
};

On Visual Studio 2013, the latter example fails to compile stating there is no constructor in map that takes 4 arguments.

I'm assuming both are actually valid. What is the difference between the two? Why doesn't the second example work on Visual Studio 2013?

4

1 回答 1

1

正如 TC 在评论中指出的那样,两者都是合法的。第一种风格可能会导致怪异,但如果第二种风格在 VS2013 中对您来说失败,那么这是编译器错误)或部分实现)。

于 2015-01-03T17:52:31.310 回答