Bug in Auto Functions and Template? Or Am I Just Crazy...

2012-06-27 Thread Michael
Hello all, I came across some weird behaviors yesterday and I can't figure out what it's about. (1) auto factorial(int n) { if (n 2) return 1; return n * factorial(n-1); } The compiler complained about forward declaration of factorial. If I change the return type to int,

Re: Bug in Auto Functions and Template? Or Am I Just Crazy...

2012-06-27 Thread Tobias Pankrath
On Wednesday, 27 June 2012 at 09:07:57 UTC, Michael wrote: Hello all, I came across some weird behaviors yesterday and I can't figure out what it's about. (1) auto factorial(int n) { if (n 2) return 1; return n * factorial(n-1); } The compiler complained about forward

Removing from SList (std.container)...

2012-06-27 Thread Minas Mina
How can I do that? Why not list.remove(x); like in STL?

Re: Removing from SList (std.container)...

2012-06-27 Thread Tobias Pankrath
On Wednesday, 27 June 2012 at 09:37:01 UTC, Minas Mina wrote: How can I do that? Why not list.remove(x); like in STL? std.container encodes the complexity of operations in the method names. There is no way to remove a range in constant time in SList, so you only get linearRemove. And you

Re: Removing from SList (std.container)...

2012-06-27 Thread Minas Mina
On Wednesday, 27 June 2012 at 09:52:14 UTC, Tobias Pankrath wrote: On Wednesday, 27 June 2012 at 09:37:01 UTC, Minas Mina wrote: How can I do that? Why not list.remove(x); like in STL? std.container encodes the complexity of operations in the method names. There is no way to remove a range

Re: Removing from SList (std.container)...

2012-06-27 Thread Tobias Pankrath
Can you show me an example or removing a number? I think that is a prime example of why std.container sucks both in documentation and implemantation. We really need to improve here, sadly development seems to be bottlenecked by Andrei working on on allocator proposal. And Andrei is busy at

Re: Bug in Auto Functions and Template? Or Am I Just Crazy...

2012-06-27 Thread Timon Gehr
On 06/27/2012 11:07 AM, Michael wrote: Hello all, I came across some weird behaviors yesterday and I can't figure out what it's about. (1) auto factorial(int n) { if (n 2) return 1; return n * factorial(n-1); } The compiler complained about forward declaration of factorial. If I

Re: Bug in Auto Functions and Template? Or Am I Just Crazy...

2012-06-27 Thread Timon Gehr
On 06/27/2012 01:24 PM, Timon Gehr wrote: On 06/27/2012 11:07 AM, Michael wrote: Hello all, I came across some weird behaviors yesterday and I can't figure out what it's about. (1) auto factorial(int n) { if (n 2) return 1; return n * factorial(n-1); } The compiler complained

Re: Removing from SList (std.container)...

2012-06-27 Thread Minas Mina
Thank you for your reply. Yes, std.container really sucks. Anyway, I made my program using C++ and STL

Re: Removing from SList (std.container)...

2012-06-27 Thread Steven Schveighoffer
On Wed, 27 Jun 2012 05:37:00 -0400, Minas Mina minas_mina1...@hotmail.co.uk wrote: How can I do that? Why not list.remove(x); like in STL? SList is quite unusable. If you are looking for STL-like containers, there is dcollections which has a doubly-linked list, and supports syntax like

Re: Removing from SList (std.container)...

2012-06-27 Thread Jonathan M Davis
On Wednesday, June 27, 2012 08:25:04 Steven Schveighoffer wrote: On Wed, 27 Jun 2012 05:37:00 -0400, Minas Mina minas_mina1...@hotmail.co.uk wrote: How can I do that? Why not list.remove(x); like in STL? SList is quite unusable. If you are looking for STL-like containers, there is

Re: Removing from SList (std.container)...

2012-06-27 Thread Steven Schveighoffer
On Wed, 27 Jun 2012 13:44:34 -0400, Jonathan M Davis jmdavisp...@gmx.com wrote: On Wednesday, June 27, 2012 08:25:04 Steven Schveighoffer wrote: On Wed, 27 Jun 2012 05:37:00 -0400, Minas Mina minas_mina1...@hotmail.co.uk wrote: How can I do that? Why not list.remove(x); like in STL?

Re: Removing from SList (std.container)...

2012-06-27 Thread Roman D. Boiko
On Wednesday, 27 June 2012 at 18:26:46 UTC, Steven Schveighoffer wrote: The thing that makes SList useless is the O(n) removal. Nobody will ever use SList when they can write a replacement that has O(1) removal in 10 minutes. Do you mean something like indexed/sorted dictionary? It doesn't

Re: Removing from SList (std.container)...

2012-06-27 Thread Timon Gehr
On 06/27/2012 08:46 PM, Roman D. Boiko wrote: On Wednesday, 27 June 2012 at 18:26:46 UTC, Steven Schveighoffer wrote: The thing that makes SList useless is the O(n) removal. Nobody will ever use SList when they can write a replacement that has O(1) removal in 10 minutes. Do you mean something

Re: Removing from SList (std.container)...

2012-06-27 Thread Steven Schveighoffer
On Wed, 27 Jun 2012 14:46:36 -0400, Roman D. Boiko r...@d-coding.com wrote: On Wednesday, 27 June 2012 at 18:26:46 UTC, Steven Schveighoffer wrote: The thing that makes SList useless is the O(n) removal. Nobody will ever use SList when they can write a replacement that has O(1) removal in

Re: Removing from SList (std.container)...

2012-06-27 Thread Roman D. Boiko
On Wednesday, 27 June 2012 at 19:10:24 UTC, Steven Schveighoffer wrote: On Wed, 27 Jun 2012 14:46:36 -0400, Roman D. Boiko r...@d-coding.com wrote: On Wednesday, 27 June 2012 at 18:26:46 UTC, Steven Schveighoffer wrote: The thing that makes SList useless is the O(n) removal. Nobody will

Re: Removing from SList (std.container)...

2012-06-27 Thread Roman D. Boiko
On Wednesday, 27 June 2012 at 19:55:02 UTC, Roman D. Boiko wrote: Look up SList docs, even with a reference to a *specific element*, you cannot do O(1) removal. Ha-ha, didn't know SList doesn't support that. I somehow confused removal after a referenced element (which should be easy to

Re: Removing from SList (std.container)...

2012-06-27 Thread Roman D. Boiko
On Wednesday, 27 June 2012 at 19:06:46 UTC, Timon Gehr wrote: On 06/27/2012 08:46 PM, Roman D. Boiko wrote: On Wednesday, 27 June 2012 at 18:26:46 UTC, Steven Schveighoffer wrote: The thing that makes SList useless is the O(n) removal. Nobody will ever use SList when they can write a

Re: Removing from SList (std.container)...

2012-06-27 Thread Roman D. Boiko
On Wednesday, 27 June 2012 at 20:00:18 UTC, Roman D. Boiko wrote: Nice. But forces to use iterators everywhere. (I'm not against iterators, they are almost necessary in certain use cases, like this one.)

Re: Removing from SList (std.container)...

2012-06-27 Thread Steven Schveighoffer
On Wed, 27 Jun 2012 15:57:42 -0400, Roman D. Boiko r...@d-coding.com wrote: On Wednesday, 27 June 2012 at 19:55:02 UTC, Roman D. Boiko wrote: Look up SList docs, even with a reference to a *specific element*, you cannot do O(1) removal. Ha-ha, didn't know SList doesn't support that. I

Re: Removing from SList (std.container)...

2012-06-27 Thread Roman D. Boiko
On Wednesday, 27 June 2012 at 20:14:53 UTC, Steven Schveighoffer wrote: Removal of that element is perfectly possible, you just need to maintain a reference to its predecessor. Which SList's range does not keep track of. It all depends on tradeoffs of what you want for performance, vs.

Re: Removing from SList (std.container)...

2012-06-27 Thread Tobias Pankrath
On Wednesday, 27 June 2012 at 20:29:02 UTC, Roman D. Boiko wrote: On Wednesday, 27 June 2012 at 20:14:53 UTC, Steven Schveighoffer wrote: Removal of that element is perfectly possible, you just need to maintain a reference to its predecessor. Which SList's range does not keep track of. It

Re: Removing from SList (std.container)...

2012-06-27 Thread Roman D. Boiko
On Wednesday, 27 June 2012 at 21:22:31 UTC, Tobias Pankrath wrote: E.g., to point to an element in the middle of some range we would need to create another range and pass it to a function along with the original range. I would hesitate to call them ranges unless that is explicitly a goal for

Re: Removing from SList (std.container)...

2012-06-27 Thread Jonathan M Davis
On Wednesday, June 27, 2012 22:29:01 Roman D. Boiko wrote: On Wednesday, 27 June 2012 at 20:14:53 UTC, Steven Schveighoffer wrote: Removal of that element is perfectly possible, you just need to maintain a reference to its predecessor. Which SList's range does not keep track of. It all

Re: Removing from SList (std.container)...

2012-06-27 Thread Roman D. Boiko
On Wednesday, 27 June 2012 at 21:38:28 UTC, Jonathan M Davis wrote: On Wednesday, June 27, 2012 22:29:01 Roman D. Boiko wrote: On Wednesday, 27 June 2012 at 20:14:53 UTC, Steven Schveighoffer wrote: Removal of that element is perfectly possible, you just need to maintain a reference to

Re: Removing from SList (std.container)...

2012-06-27 Thread Minas Mina
Doesn't Andrei plan to do something about this module?

Concurrency in D

2012-06-27 Thread Minas Mina
I have been playing latetly with std.concurrency and core.thread. I like both, but they are entirely different approaches to concurrency. std.concurrency: Uses message passing. Does not allow passing of mutable types. core.thread: Essentially the same as the approach taken by Java. 1) Is

Re: Concurrency in D

2012-06-27 Thread Adam Burton
Minas Mina wrote: I have been playing latetly with std.concurrency and core.thread. I like both, but they are entirely different approaches to concurrency. std.concurrency: Uses message passing. Does not allow passing of mutable types. core.thread: Essentially the same as the approach

Re: Concurrency in D

2012-06-27 Thread Justin Whear
On Thu, 28 Jun 2012 00:34:50 +0200, Minas Mina wrote: I have been playing latetly with std.concurrency and core.thread. I like both, but they are entirely different approaches to concurrency. std.concurrency: Uses message passing. Does not allow passing of mutable types. core.thread:

Re: Concurrency in D

2012-06-27 Thread Nathan M. Swan
On Wednesday, 27 June 2012 at 22:34:51 UTC, Minas Mina wrote: I have been playing latetly with std.concurrency and core.thread. I like both, but they are entirely different approaches to concurrency. Aren't they great? ;) std.concurrency: Uses message passing. Does not allow passing of

Re: Concurrency in D

2012-06-27 Thread Ali Çehreli
On 06/27/2012 04:05 PM, Adam Burton wrote: For example I would like to have a thread calculate the sum of the first half of an array while another thread would calculate the other half, and I could add the two results at the end. For this task there is another concurrency module called

Re: Concurrency in D

2012-06-27 Thread Minas Mina
You all helped, thank you :) I will read the concurrency part tomorrow!

Re: Removing from SList (std.container)...

2012-06-27 Thread Jonathan M Davis
On Thursday, June 28, 2012 00:23:03 Minas Mina wrote: Doesn't Andrei plan to do something about this module? He came up with the basic design, and he's working on the custom allocator design. Once that's been sorted out, std.container will be made to use it, and more containers will be added

Re: Stack overflow / recursive expansion with alias this

2012-06-27 Thread Kenji Hara
On Tuesday, 24 April 2012 at 20:09:32 UTC, Namespace wrote: On Tuesday, 24 April 2012 at 19:34:26 UTC, Timon Gehr wrote: On 04/24/2012 07:09 PM, Namespace wrote: ... And therefore i get the same error, as if i wrote return NotNull!(Foo)(this); instead of return assumeNotNull(this);, in the

Re: implicit conversion to alias this

2012-06-27 Thread BLM768
On Monday, 25 June 2012 at 20:06:21 UTC, Tobias Pankrath wrote: - struct A { bool a; alias a this; } struct B { int b; alias b this; } A a = false; // works B b = 12; // works struct C { A aa; B ab; } C c = { false, 12 }; // does not work, because the implicit conversion does

Re: implicit conversion to alias this

2012-06-27 Thread Tobias Pankrath
On Thursday, 28 June 2012 at 04:43:07 UTC, BLM768 wrote: On Monday, 25 June 2012 at 20:06:21 UTC, Tobias Pankrath wrote: - struct A { bool a; alias a this; } struct B { int b; alias b this; } A a = false; // works B b = 12; // works struct C { A aa; B ab; } C c = { false, 12 };