Today I was doing some catch-up on c++11 (as we have not moved on yet). One of the reasons to switch as stated by a lot of people seems to be lambda expressions. I am still unsure on how they offer something new.
For instance using c++11:
#include <iostream>
int main()
{
auto func = [] () { std::cout << "Hello world" << std::endl; };
func();
}
seems to be very similar to:
#include <iostream>
#define FUNC( )\
do { std::cout << "Hello world" << std::endl; } while(0)
int main()
{
FUNC();
}
What would lambda expressions offer me that I can’t currently already do?
http://msdn.microsoft.com/en-us/library/vstudio/dd293608.aspx sums up the main points and more on the subject in great detail. Here is the salient excerpt:
There are examples on the site showing more differences and comparisons.
Also…conventional wisdom is never use macros in C++:
http://scienceblogs.com/goodmath/2007/12/17/macros-why-theyre-evil/