今天,Apple 更新了 Xcode 的命令行工具,然后将 clang 从 318.0.58 升级到了 318.0.61。
我尝试使用初始化列表,但无法编译下面的代码。
#include <iostream>
#include <random>
#include <initializer_list>
int main()
{
std::mt19937 rng(time(NULL));
std::initializer_list<double> probabilities =
{
0.5, 0.1, 0.1, 0.1, 0.1, 0.1
};
std::discrete_distribution<> cheat_dice (probabilities);
int a[6] = { };
for ( int i = 0 ; i != 1000; ++i )
{
++a[cheat_dice(rng)];
}
for ( int i = 0; i != 6; ++i )
{
std::cout << i + 1 << "=" << a[i] << std::endl;
}
}
然后,我尝试编译。
$ clang++ -stdlib=libc++ foo.cpp
错误日志
foo.cpp:9:10: error: no member named 'initializer_list' in namespace 'std'
std::initializer_list<double> probabilities =
~~~~~^
foo.cpp:9:33: error: expected '(' for function-style cast or type construction
std::initializer_list<double> probabilities =
~~~~~~^
foo.cpp:9:35: error: use of undeclared identifier 'probabilities'
std::initializer_list<double> probabilities =
^
foo.cpp:10:5: error: expected expression
{
^
foo.cpp:14:46: error: use of undeclared identifier 'probabilities'
std::discrete_distribution<> cheat_dice (probabilities);
^
5 errors generated.
另一方面,我可以用 gcc-4.7.1-RC-20120606 编译上面的代码。
$ g++ -std=c++11 foo.cpp
Apple 的 clang 不支持初始化列表吗?叮当版本:
$ clang++ -v
Apple clang version 3.1 (tags/Apple/clang-318.0.61) (based on LLVM 3.1svn)
Target: x86_64-apple-darwin11.4.0
Thread model: posix