A comparison between C++ and D
bigsandwich via Digitalmars-d
digitalmars-d at puremagic.com
Wed Mar 9 14:54:13 PST 2016
On Wednesday, 9 March 2016 at 22:05:28 UTC, Ola Fosheim Grøstad
wrote:
> On Wednesday, 9 March 2016 at 20:41:35 UTC, bigsandwich wrote:
>> Right, I used to this sort of thing in C++ prior to C++11. I
>> think not having an RAII wrapper for lambdas similar to
>> std::function<> is an oversight for D, especially for people
>> averse to GC. That little bit of syntactic sugar makes a huge
>> difference.
>
> std::function<> is a lot more than syntactic sugar, it is a
> runtime-heavy construct. From
> http://en.cppreference.com/w/cpp/utility/functional/function :
>
> «Class template std::function is a general-purpose polymorphic
> function wrapper. Instances of std::function can store, copy,
> and invoke any Callable target -- functions, lambda
> expressions, bind expressions, or other function objects, as
> well as pointers to member functions and pointers to data
> members.»
>
> I don't think you want this...
Yes, I do. std::function<> uses type erasure to store a
"function". If its small enough, its stored internally,
otherwise it goes on the heap. It uses RAII to manage the
lifetime of the lambda. D is using the GC for managing the
lifetime. D doesn't have a way of doing this without the GC.
More information about the Digitalmars-d
mailing list