C++11 ships with a set of out-of-the-box smart pointers that help us to manage the memory easily.
One of those smart pointers is the unique_ptr.
C++11 introduces support for asynchronous calls in a very easy way.
An asynchronous call is a method invocation that will be executed in a separate thread (or core or processor); so, the caller of the method does not wait for the result of the execution and continue doing what is next; in this way, the compiler/processor/operating system can optimise the execution of the program and execute several routines at the same time (given the now common multicore systems we all have at home and in our pockets!). The standard library provides the mechanisms to perform those asynchronous calls and store the results until the caller will actually need them.
The standard library that ships with the new C++11 contains a set of classes to use threads. Before this, we needed to use the OS specific thread facilities each OS provides making our programs hard to port to other platforms.
Anyway, as today (November 16th, 2012), I tried threads using g++ 4.7 in Linux, Windows (through mingw), Mac and NetBSD and I just had success in Linux, Windows and Mac do not implement the thread features and NetBSD misses some details on the implementation (the this_thread::sleep_for() method, for example). Microsoft Visual Studio 2012 ships with good thread support.
To define a thread, we need to use the template class std::thread and we need to pass it a function pointer, a lambda expression or a functor. Look at this example:
Look at this piece of code:
#include <iostream>
#include <functional>
using namespace std;
using namespace std::placeholders;
void add(int a, int b, int& r)
{
r = a + b;
}
int main()
{
int result = 0;
auto f = bind(add, _1, 20, result);
f(80);
cout << result << endl;
return 0;
}
std::enable_if is another feature taken from the Boost C++ library that now ships with every C++11 compliant compiler.
As its name says, the template struct enable_if, enables a function only if a condition (passed as a type trait) is true; otherwise, the function is undefined. In this way, you can declare several “overloads” of a method and enable or disable them depending on some requirements you need. The nice part of this is that the disabled functions will not be part of your binary code because the compiler simply will ignore them.
Say you have this piece of code:
template <typename T>
void show(typename T::iterator x, typename T::iterator y)
{
for (; x != y; ++x) cout << *x << endl;
}
int main()
{
show<int>(16, 18);
}
A bunch of colleagues and friends were very busy developing this very nice tool that lets you get nice reports from Mercurial. Taken from the project web page:
StatHg generates statistical report graphs from the Mercurial activity log. The generated report is independent of the application and can be freely transferred or even published using a web server.
