A comparison between C++ and D

maik klein via Digitalmars-d digitalmars-d at puremagic.com
Wed Mar 9 11:33:30 PST 2016


On Wednesday, 9 March 2016 at 18:26:01 UTC, bigsandwich wrote:
> On Wednesday, 9 March 2016 at 01:18:26 UTC, maik klein wrote:
>> [...]
>
> C++ as well as D have anonymous functions. C++: [](auto a, auto 
> b){ return a + b;} , D: (a, b) => a + b or (a, b){return a + 
> b;}. As far as I know capturing other variables requires the GC 
> in D. In C++ you can explicitly capture variables by copy, ref 
> or move. Lambda functions in D can not return references. C++17 
> will also make lambda functions available with constexpr. 
> Lambda functions can also be used at compile time in D.
>
> Is this really true?  Couldn't the closure be stored internally 
> somewhere like std::function<> does in C++?

I think this is actually not true, but I wrote it because of this

http://dpaste.dzfl.pl/dd6b935df5ce

I run into this problem a couple of times.


More information about the Digitalmars-d mailing list