I’m not so familiar with C++. Can someone please inform me what this lines does (in detail):
auto add_element = [&rows,&cols,&values](size_t row, size_t col, double value)
{
rows.push_back(int(row));
cols.push_back(int(col));
values.push_back(value);
};
Rows, cols, values are obvious vectors.
Is this the same as void add_element(vector & rows, size_t row, …..)
That defines and stores a lambda. Read here on more details or google up on C++11 and lambda.
One of the most exciting features of C++11 is ability to create lambda functions (sometimes referred to as closures). What does this mean? A lambda function is a function that you can write inline in your source code (usually to pass in to another function, similar to the idea of a functor or function pointer). With lambda, creating quick functions has become much easier, and this means that not only can you start using lambda when you’d previously have needed to write a separate named function, but you can start writing more code that relies on the ability to create quick-and-easy functions. In this article, I’ll first explain why lambda is great–with some examples–and then I’ll walk through all of the details of what you can do with lambda…