Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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, .....)

share|improve this question

1 Answer 1

up vote 5 down vote accepted

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...

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.