Can lambda functions be templated?

UPDATE 2018: C++20 will come with templated and conceptualized lambdas. The feature has already been integrated into the standard draft. UPDATE 2014: C++14 has been released this year and now provides Polymorphic lambdas with the same syntax as in this example. Some major compilers already implement it. At it stands (in C++11), sadly no. Polymorphic … Read more

Why can I not push_back a unique_ptr into a vector?

You need to move the unique_ptr: vec.push_back(std::move(ptr2x)); unique_ptr guarantees that a single unique_ptr container has ownership of the held pointer. This means that you can’t make copies of a unique_ptr (because then two unique_ptrs would have ownership), so you can only move it. Note, however, that your current use of unique_ptr is incorrect. You cannot … Read more

What does “default” mean after a class’ function declaration?

It’s a new C++11 feature. It means that you want to use the compiler-generated version of that function, so you don’t need to specify a body. You can also use = delete to specify that you don’t want the compiler to generate that function automatically. With the introduction of move constructors and move assignment operators, … Read more

“unpacking” a tuple to call a matching function pointer

You need to build a parameter pack of numbers and unpack them template<int …> struct seq { }; template<int N, int …S> struct gens : gens<N-1, N-1, S…> { }; template<int …S> struct gens<0, S…> { typedef seq<S…> type; }; // … void delayed_dispatch() { callFunc(typename gens<sizeof…(Args)>::type()); } template<int …S> void callFunc(seq<S…>) { func(std::get<S>(params) …); … Read more

Is std::unique_ptr required to know the full definition of T?

Adopted from here. Most templates in the C++ standard library require that they be instantiated with complete types. However shared_ptr and unique_ptr are partial exceptions. Some, but not all of their members can be instantiated with incomplete types. The motivation for this is to support idioms such as pimpl using smart pointers, and without risking … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)