How to make a recursive lambda

Think about the difference between the auto version and the fully specified type version. The auto keyword infers its type from whatever it’s initialized with, but what you’re initializing it with needs to know what its type is (in this case, the lambda closure needs to know the types it’s capturing). Something of a chicken-and-egg … Read more

What is the “rvalue reference for *this” proposal?

First, “ref-qualifiers for *this” is a just a “marketing statement”. The type of *this never changes, see the bottom of this post. It’s way easier to understand it with this wording though. Next, the following code chooses the function to be called based on the ref-qualifier of the “implicit object parameter” of the function†: // … Read more

Why does assigning std::ref not change the value of the referenced object?

A small modification to f2 provides the clue: template<class T> void f2(T arg) { arg.get() = xx; } This now does what you expect. This has happened because std::ref returns a std::reference_wrapper<> object. The assignment operator of which rebinds the wrapper. (see http://en.cppreference.com/w/cpp/utility/functional/reference_wrapper/operator%3D) It does not make an assignment to the wrapped reference. In the … Read more

Why is there no default move-assignment/move-constructor in early drafts of the C++11 standard?

The implicit generation of move constructors and assignment operators has been contentious and there have been major revisions in recent drafts of the C++ Standard, so currently available compilers will likely behave differently with respect to implicit generation. For more about the history of the issue, see the 2010 WG21 papers list and search for … Read more

How do you loop over a parameter pack using a pack expansion?

One of the places where a pack expansion can occur is inside a braced-init-list. You can take advantage of this by putting the expansion inside the initializer list of a dummy array: template<typename… Args> static void foo2(Args &&… args) { int dummy[] = { 0, ( (void) bar(std::forward<Args>(args)), 0) … }; } To explain the … Read more

What is the purpose of std::function and how do I use it?

std::function is a type erasure object. That means it erases the details of how some operations happen, and provides a uniform run time interface to them. For std::function, the primary1 operations are copy/move, destruction, and ‘invocation’ with operator() — the ‘function like call operator’. In less abstruse English, it means that std::function can contain almost … Read more

How does std::forward work, especially when passing lvalue/rvalue references? [duplicate]

I think the explanation of std::forward as static_cast<T&&> is confusing. Our intuition for a cast is that it converts a type to some other type — in this case it would be a conversion to an rvalue reference. It’s not! So we are explaining one mysterious thing using another mysterious thing. This particular cast is … Read more

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