Using std::array with initialization lists

std::array is funny. It is defined basically like this: template<typename T, int size> struct std::array { T a[size]; }; It is a struct which contains an array. It does not have a constructor that takes an initializer list. But std::array is an aggregate by the rules of C++11, and therefore it can be created by … Read more

Why does passing object reference arguments to thread function fails to compile?

Threads copy their arguments (think about it, that’s The Right Thing). If you want a reference explicitly, you have to wrap it with std::ref (or std::cref for constant references): std::thread t(foo, std::ref(std::cout)); (The reference wrapper is a wrapper with value semantics around a reference. That is, you can copy the wrapper, and all copies will … Read more