Rotate image (square matrix) by 90 deg
Tue, 06 May 2025
In my opinion, the single biggest addition to C++11 is the Lambda function and expressions (for more features in C++ click here...).
Look at the case when you are calling std::sort function, you have to specify the comparator function and then pass that function as an argument to std::sort. In such situations, you may want to specify the function at the point of calling std::sort inline. Because that function (Comparator Function) has not other use but to be called to this API.
This function may not even have a name , we don't really care..
In C++11, you can specify anonymous functions, called lambda function (or expression). It is of the form:
[capture_list] (parameter_list)->return_type { function_body }
For Example:
[](int x, int y){ return x+y; }
capture_list : This list specify the variables of enclosing function which are passed either by-reference or by-value. In the above example the list is empty. But it can have values to be passed to the function.
std::vector<int> v;
int squareSum = 0;
std::for_each(v.begin(), v.end(), [&](int x) { squareSum += x * x; } );
Tue, 06 May 2025
Tue, 06 May 2025
Tue, 06 May 2025
Leave a comment