A comparison between C++ and D
bigsandwich via Digitalmars-d
digitalmars-d at puremagic.com
Wed Mar 9 10:26:01 PST 2016
On Wednesday, 9 March 2016 at 01:18:26 UTC, maik klein wrote:
> Direct link: https://maikklein.github.io/post/CppAndD/
> Reddit link:
> https://www.reddit.com/r/programming/comments/49lna6/a_comparison_between_c_and_d/
>
> If you spot any mistakes, please let me know.
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++?
More information about the Digitalmars-d
mailing list