2011-03-08

C++0x feature support in GCC 4.5

Here is a description of some nice new features available in C++0x supported by GCC 4.5.

http://www.ibm.com/developerworks/aix/library/au-gcc/index.html?cmp=dw&cpb=dwaix&ct=dwnew&cr=dwnen&ccy=zz&csr=030311

Here are some highlights.

Static assertions:

static_assert(sizeof(int) == 4, "Integer sizes expected to be 4");

New character types

char16_t guaranteed to be able to hold a UTF-16 character
char32_t guaranteed to be able to hold a UTF-32 character

Auto syntax type

auto *num1 = new int(7); // type for num1 it int*
const auto num2 = 3.1415; // type for num2 is double


Initializer lists

// in a variable definition
std::vector doubles = {2.3, 4.511, 1.23, 0.99};

// Initializer list used with new
std::list *d2 = new std::list {1.2, 1.3};

// Initialize a map
std::map = { {“key1”, 1}, {“key2”, 2} };

1 comment:

Warwick Hunter said...

A description of the new features in C++0x that has now been approved unanimously.

http://www.slideshare.net/perone/c0x-introduction-to-some-amazing-features