2013-08-25 wcdj
在搭建完C++11的编译环境后(参见:在OS X Lion 10.8.4 x86_64平台搭建C++11开发环境),在gcc-4.8.1下尝试测试一些新的特性及用法。
New Features in C++11
1, long long Type
2, List Initialization
3, nullptr Literal
4, constexpr Variables
5, Type Alias Declarations, using A = B;
6, The auto Type Specifier
7, the decltype Type Specifier
8, Range for Statement
9, Defining a vector of vectors
测试代码
/* 编译环境:X86_64, gcc-4.8.1
* 测试C++11新特性
* 2013-10-01 wcdj
* */
#include <iostream>
#include <cstdlib> // NULL
#include <typeinfo> // typeid
#include <string>
#include <vector>
int size1()
{
return 0;
}
constexpr int size2()
{
return 0;
}
int no_carry_out_by_use_deltype()
{
std::cout << "no carry out by use deltype\n";
return 0;
}
int main()
{
// 【1】long long Type
std::cout << "【1】long long Type" << std::endl;
int ivar = 1;
long lvar = 2;
long long llvar = 3;
std::cout << "sizeof(int)=" << sizeof(ivar) << std::endl;
std::cout << "sizeof(long)=" << sizeof(lvar) << std::endl;
std::cout << "sizeof(long long)=" << sizeof(llvar) << std::endl;
// 【2】list initialization