【c++11并不遥远】使xcode工程支持c++11特性

来源:互联网 发布:苹果6手机壳淘宝 编辑:程序博客网 时间:2024/05/01 13:57

一、操作步骤:

工程文件 => Build Settings(All) =>  Apple LLVM 6.1 Language - C++

C++ Language Dialect: C++11 [-std=c++11]

C++ Standard Library: libc++ (LLVM C++ standard library with C++11 support)


二、测试代码(可编译通过即可):

void whatValue(int&& val) {    printf("R-Value: %d\n", val);}void whatValue(const int& val) {    printf("L-Value: %d\n", val);}void testRValue(int&& i) {    whatValue(i);    whatValue(std::move(i)); // g++ 不支持 std::move<int>(i); 这种写法}constexpr int getCstExpr() {    return 888;}void testFor11() {    int arrInt[5] = {1, 2, 3, 4, 5};    for (int& item : arrInt) {        item *= 2;    }}void testTypeInference() {    int value[getCstExpr() + 123];    const std::vector<char> vec(1);    auto a = vec[0];    decltype(a)b; // g++ 不支持 decltype(vec[0])b; 这种写法    auto c = 0;    auto d = c;    decltype(c) e;    decltype((c)) f = e;    decltype(0) g;}
参考连接:

cocos2d-x工程中,让xcode4.6能够使用C++11标准库

http://my.oschina.net/u/160089/blog/174692

测试编译器是否支持C++11新特性(1)

http://my.oschina.net/u/186539/blog/58074



0 0
原创粉丝点击