Re: A comparison between C++ and D

2016-03-10 Thread Steven Schveighoffer via Digitalmars-d
On 3/8/16 10:04 PM, Jack Stouffer wrote: 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

Re: A comparison between C++ and D

2016-03-10 Thread Ola Fosheim Grøstad via Digitalmars-d
On Wednesday, 9 March 2016 at 22:54:13 UTC, bigsandwich wrote: 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. Yes, I believe that is said to be the common implementation, but people also claim

Re: A comparison between C++ and D

2016-03-09 Thread Adam D. Ruppe via Digitalmars-d
On Thursday, 10 March 2016 at 00:31:00 UTC, John Colvin wrote: what magic is this? I had no idea that taking the address of opCall would give me a delegate. opCall is a red herring: taking the address of *any* non-static member function in a class or struct object will give you a delegate.

Re: A comparison between C++ and D

2016-03-09 Thread John Colvin via Digitalmars-d
On Wednesday, 9 March 2016 at 20:14:13 UTC, Adam D. Ruppe wrote: --- import std.stdio; @nogc int delegate(int) dg; int helper() @nogc { int a = 50; struct MyFunctor { int a; @nogc this(int a) { this.a = a; } // the function

Re: A comparison between C++ and D

2016-03-09 Thread Atila Neves via Digitalmars-d
On Wednesday, 9 March 2016 at 22:54:13 UTC, bigsandwich wrote: On Wednesday, 9 March 2016 at 22:05:28 UTC, Ola Fosheim Grøstad wrote: [...] 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

Re: A comparison between C++ and D

2016-03-09 Thread bigsandwich via Digitalmars-d
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,

Re: A comparison between C++ and D

2016-03-09 Thread Ola Fosheim Grøstad via Digitalmars-d
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

Re: A comparison between C++ and D

2016-03-09 Thread bigsandwich via Digitalmars-d
On Wednesday, 9 March 2016 at 20:14:13 UTC, Adam D. Ruppe wrote: On Wednesday, 9 March 2016 at 18:26:01 UTC, bigsandwich wrote: [...] You can easily do it yourself with a struct. That's all the c++ lambda is anyway, a bit of syntax sugar over a struct. [...] Right, I used to this sort

Re: A comparison between C++ and D

2016-03-09 Thread Adam D. Ruppe via Digitalmars-d
On Wednesday, 9 March 2016 at 18:26:01 UTC, bigsandwich wrote: As far as I know capturing other variables requires the GC in D. You can easily do it yourself with a struct. That's all the c++ lambda is anyway, a bit of syntax sugar over a struct. Then you pass the struct itself if you want

Re: A comparison between C++ and D

2016-03-09 Thread Ola Fosheim Grøstad via Digitalmars-d
On Wednesday, 9 March 2016 at 18:26:01 UTC, bigsandwich wrote: Is this really true? Couldn't the closure be stored internally somewhere like std::function<> does in C++? Lambdas in C++ creates a regular class with a call-operator, the class is instantiated and the fields filled with the

Re: A comparison between C++ and D

2016-03-09 Thread maik klein via Digitalmars-d
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

Re: A comparison between C++ and D

2016-03-09 Thread Namespace via Digitalmars-d
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. I'm missing the wildcard

Re: A comparison between C++ and D

2016-03-09 Thread bigsandwich via Digitalmars-d
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

Re: A comparison between C++ and D

2016-03-09 Thread Andrei Alexandrescu via Digitalmars-d
On 03/08/2016 08:18 PM, 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. Nice work, thanks! -- Andrei

Re: A comparison between C++ and D

2016-03-08 Thread Adam D. Ruppe via Digitalmars-d
On Wednesday, 9 March 2016 at 04:37:47 UTC, maik klein wrote: Does this mean I could do any cast at compile time? No, compile time has other restrictions. http://dlang.org/spec/function.html#interpretation "Any pointer may be cast to void * and from void * back to its original type. Casting

Re: A comparison between C++ and D

2016-03-08 Thread maik klein via Digitalmars-d
On Wednesday, 9 March 2016 at 04:15:39 UTC, Walter Bright wrote: On 3/8/2016 6:14 PM, Chris Wright wrote: D does not let you downcast without a runtime check. You can by casting to void* first, then the downcast. Thanks I'll update the post later. Does this mean I could do any cast at

Re: A comparison between C++ and D

2016-03-08 Thread Walter Bright via Digitalmars-d
On 3/8/2016 6:14 PM, Chris Wright wrote: D does not let you downcast without a runtime check. You can by casting to void* first, then the downcast.

Re: A comparison between C++ and D

2016-03-08 Thread maik klein via Digitalmars-d
On Wednesday, 9 March 2016 at 03:04:31 UTC, Jack Stouffer wrote: 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

Re: A comparison between C++ and D

2016-03-08 Thread Jack Stouffer via Digitalmars-d
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. D moves objects with a bitwise

Re: A comparison between C++ and D

2016-03-08 Thread maik klein via Digitalmars-d
On Wednesday, 9 March 2016 at 02:14:34 UTC, Chris Wright wrote: On Wed, 09 Mar 2016 01:18:26 +, maik klein wrote: [...] [...] Rather, declaring a variable should never throw an exception. Declaring a variable shouldn't create any nontrivial work. It's trivial to create a type in D

Re: A comparison between C++ and D

2016-03-08 Thread Chris Wright via Digitalmars-d
On Wed, 09 Mar 2016 01:18:26 +, maik klein wrote: > If you spot any mistakes, please let me know. > structs in D don’t have a default constructor because every type > needs exception free default construction Rather, declaring a variable should never throw an exception. Declaring a variable

A comparison between C++ and D

2016-03-08 Thread maik klein via Digitalmars-d
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.