Perfect forwarding and forwarding references allow developers to write generic template functions that retain the lvalueness/rvalueness of passed arguments, in order to avoid unnecessary copies or support reference semantics without having to implement multiple overloads. (This article by Eli Bendersky explains them in depth. I will assume you're familiar with these concepts for the rest of the article.)

In this article, I'll show how to correctly capture perfectly-forwarded objects into lambdas:

• We'll take a look at an example that shows how using std::forward in lambda captures can produce unexpected results.

When writing generic code, it is sometimes useful to check whether or not a particular SFINAE-friendly expression is valid (e.g. to branch at compile-time). Let's assume that we have the following class declarations...

struct Cat
{
void meow() const { cout << "meow\n"; }
};

struct Dog
{
void bark() const { cout << "bark\n"; }
};

...and that we would like to write a template function make_noise(x) that calls x.meow() and/or x.bark() if they are well-formed expressions:

template <typename T>
void make_noise(const T& x)
{
// Pseudocode:
/*
if(x.meow() is well-formed)
{
execute x.meow();
}
else if(x.bark() is well-formed)
{
execute x.bark();
}
else
{
compile-time error
}
*/
}

"An Empirical Study on the Impact of C++ Lambdas and Programmer Experience", a recent research paper presented at ICSE' 16, sparked a lot of controversy (e.g on reddit and Hacker News) after claiming that the use of C++11 lambda functions is harmful to beginners and unhelpful to professionals.

After carefully reading the paper, which is available on Andreas Stefik, Ph.D.'s website for free, I genuinely think that it is misinformative and that the drawn conclusions are inaccurate due to the flawed approach taken for the experiments and due to the small sample size.

In this article, I will support my claims by quoting the original paper and explaining why the authors' work/conclusions are subpar. All blockquotes in this post are citations of doi>10.1145/2884781.2884849.

In my previous article, "visiting variants using lambdas - part 1", I wrote about a simple technique (using boost::hana) that allows variant visitation using lambdas.

The technique consisted in passing several lambdas to boost::hana::overload in order to create a "local" visitor, without having to define a class/struct.

While discussing upcoming C++17 features with other attendees at CppCon 2016, I was surprised to hear complaints about the fact that std::variant visitation requires an external callable object.

Even though std::visit requires an overloaded callable object as its first argument, it is possible to build such an object locally in the call site: this can easily be achieved by implementing something similar to std::overload, proposed in P0051R2.

The aforementioned task however becomes trivial when using boost::hana.

The video of my CppCon 2016 talk, Implementing static control flow in C++14, is now available on YouTube. Enjoy!

I've recently released a script on my GitHub page that simplifies C++ compiler error messages: camomilla.

What does it do?

camomilla uses simple text transformations to make gcc and clang errors smaller and easier to read. During the development of ecst, a compile-time Entity-Component-System C++14 library developed for my BCS thesis, I encountered a lot of huge undeciphrable errors that sometimes completely filled my terminal buffer. Here's an example:

CppCon 2016 ended yesterday - I had the pleasure of attending and presenting at this amazing conference again this year.

I'm really grateful to Jon Kalb, Bryce Lelbach, the conference staff, the speakers, my company and everyone else involved for making this possible.

In the same vein as my C++Now 2016 trip report, I wanted to share my thoughts regarding the talks I liked the most and regarding my sessions.