Lambda funtions in C++

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Lambda funtions in C++

Postby Julio Jerez » Fri Oct 23, 2015 9:07 pm

In any one using them.
It seem a really good way to write clear multithreaded code, specially when using thread pool.
this is kind of like how openMp words, who make code very readable, using hand codes like Newton used now the code is messy and very hard o follow.
This is also the approach that Microsoft used for AMP used to write GPU code.

My only problem is that adopting Lambda functions will force to abandonee Visual studio 10 and lower, it seem that all compiler now support them. No sure abut Linux.

Of all of the new function that the keep saying about C++ to me Lambda function is the only really new one in more than 15 years.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Lambda funtions in C++

Postby JoeJ » Sat Oct 24, 2015 11:31 am

I'd go for it now if you like to.
I've not tried it myself yet (totally lack in modern C++), but it seems the feature i've always missed and there is no possible replacement (unlike C++ threads vs. pthreads).
User avatar
JoeJ
 
Posts: 1489
Joined: Tue Dec 21, 2010 6:18 pm

Re: Lambda funtions in C++

Postby Stucuk » Sat Oct 24, 2015 2:08 pm

Julio Jerez wrote:My only problem is that adopting Lambda functions will force to abandonee Visual studio 10 and lower, it seem that all compiler now support them. No sure abut Linux.


You would need to provide binaries for the stable versions if you abandon visual studio 10 and lower so that people who don't have versions higher can at least link to the dll's. Otherwise you would prevent some from being able to use future versions of Newton.
User avatar
Stucuk
 
Posts: 801
Joined: Sat Mar 12, 2005 3:54 pm
Location: Scotland

Re: Lambda funtions in C++

Postby godlike » Sat Oct 24, 2015 6:46 pm

Julio Jerez wrote:In any one using them.


I use them only for inline template functions (eg iterate a vector and call a lambda).

I never pass them around. I prefer plain callbacks where I have full visibility of what is happening.

Julio Jerez wrote:No sure abut Linux.


GCC supports them since 4.5 (now it's 5.2) and Clang since 3.1 (now it's 3.7). I think it's pretty safe to assume that Linux compilers support them.
User avatar
godlike
 
Posts: 58
Joined: Sun Mar 16, 2014 3:48 am


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 3 guests

cron