Note: Some of these features might not be supported by your compiler.
1)Â Keyword ‘auto’ – the type comes from the initialization.
A simple example:
auto rand_rc = new std::set<UINT64>;
The compiler deduces the type of ‘rand_rc‘ as ‘std::set<UINT64>*‘.
Now take a look at this:
void printErrorsInMap( map< int, set<UINT64>* > & errorMap )
{
for (auto iter = errorMap.begin(); iter != errorMap.end(); ++iter)
{
cout << “Errors for RC #” << iter->first << endl;
…
…
}
}
Here, the type of iter is automatically deduced as map< int, set<UINT64>* >::const_iterator.
How convenient is that!!
No need to write the long types and there’s no room for any issue related to type-safety… you see, the compiler makes the best decision.
2)Â nullptr
A type nullptr_t especially-created for the null pointer (of any type).
No longer the need to use that potentially un-safe NULL – which can be an int also.
With the nullptr you CANNOT say:
int invalid_type = nullptr;
3)Â Static Assertion.
An assertion that happens at compile-time.
static_assert(const_expr, string); Continue reading “Simple things I like about C++11” →