Re: On Concurrency

2014-04-21 Thread via Digitalmars-d-learn
On Friday, 18 April 2014 at 17:20:06 UTC, Nordlöw wrote: Could someone please give some references to thorough explainings on these latest concurrency mechanisms Coroutines is nothing more than explicit stack switching. Goroutines/fiber etc are abstractions that may be implemented using

Re: Function to print a diamond shape

2014-04-21 Thread monarch_dodra via Digitalmars-d-learn
On Monday, 21 April 2014 at 00:11:14 UTC, Jay Norwood wrote: So this printDiamonde2b example had the fastest time of the solutions, and had similar times on all three builds. The ldc2 compiler build is performing best in most examples on ubuntu. void printDiamonde2b(in uint N) { uint N2 =

Regarding foreach loop index ranges

2014-04-21 Thread bearophile via Digitalmars-d-learn
In this case I am not sure about bug reports, so I ask here. In this program the first loop doesn't compile, giving a nice error: test.d(3,5): Error: index type 'ubyte' cannot cover index range 0..300 If you comment out the first loop, the second compiles and runs, but it seems to go in

Re: Regarding foreach loop index ranges

2014-04-21 Thread bearophile via Digitalmars-d-learn
For the second loop one possible alternative behavour is to refuse a ubyte index and accept only a size_t index if it loops on a dynamic array. Another alternative is: the i variable can go from 0 to 255, then go up to the modulus of the remaining indexes, and then stop. In this program the

Re: toString() through interface

2014-04-21 Thread Steven Schveighoffer via Digitalmars-d-learn
On Sat, 19 Apr 2014 20:45:50 -0400, Adam D. Ruppe destructiona...@gmail.com wrote: On Sunday, 20 April 2014 at 00:35:30 UTC, David Held wrote: Since all implementations of an interface must derive from Object That's not true. They can also come from IUnknown or a C++ interface. This is

Re: toString() through interface

2014-04-21 Thread Steven Schveighoffer via Digitalmars-d-learn
On Sat, 19 Apr 2014 20:51:49 -0400, David Held d...@wyntrmute.com wrote: On 4/19/2014 5:35 PM, David Held wrote: interface Foo { } class Bar : Foo { override string toString() pure const { return Bar; } } void main() { Foo foo = new Bar; foo.toString(); } To make things more

Re: Regarding foreach loop index ranges

2014-04-21 Thread Steven Schveighoffer via Digitalmars-d-learn
On Mon, 21 Apr 2014 07:49:03 -0400, bearophile bearophileh...@lycos.com wrote: In this case I am not sure about bug reports, so I ask here. In this program the first loop doesn't compile, giving a nice error: test.d(3,5): Error: index type 'ubyte' cannot cover index range 0..300 If you

Re: Regarding foreach loop index ranges

2014-04-21 Thread bearophile via Digitalmars-d-learn
https://issues.dlang.org/show_bug.cgi?id=12611 Bye, bearophile

Re: string - string literal

2014-04-21 Thread Timothee Cour via Digitalmars-d-learn
does that work? string escapeD(string a){ import std.array:replace; return `r`~a.replace(``,` \ r`)~``; } On Sun, Apr 20, 2014 at 11:14 AM, monarch_dodra via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: On Sunday, 20 April 2014 at 17:55:25 UTC, Ellery Newcomer wrote: is

Best way to check for an element in an array?

2014-04-21 Thread Taylor Hillegeist via Digitalmars-d-learn
So I find myself Doing this kind of thing very frequently. I have a Array of Somethings and i want to see if something specific is inside the array. I wrote a template for it. but is this the best way to do this kind of thing. I feel like it doesn't help with readability. Is there a better

Re: Best way to check for an element in an array?

2014-04-21 Thread Timothee Cour via Digitalmars-d-learn
you can use stuff.canFind(2) but sometimes it'd be more convenient to have the other way around (UFCS chains etc); how about: bool isIn(T,T2...)(T needle, T2 haystack) if(__traits(compiles,T.init==T2[0].init)){ foreach(e;haystack){ if(needle==e) return true; } return false; }

Re: Best way to check for an element in an array?

2014-04-21 Thread Taylor Hillegeist via Digitalmars-d-learn
On Tuesday, 22 April 2014 at 03:57:33 UTC, Timothee Cour via Digitalmars-d-learn wrote: you can use stuff.canFind(2) but sometimes it'd be more convenient to have the other way around (UFCS chains etc); how about: bool isIn(T,T2...)(T needle, T2 haystack)

Re: Function to print a diamond shape

2014-04-21 Thread Jay Norwood via Digitalmars-d-learn
On Monday, 21 April 2014 at 08:26:49 UTC, monarch_dodra wrote: The two key points here, first, is to avoid using appender. Second, instead of having two buffer: and **\n, and two do two slice copies, to only have 1 buffer *, and to do 1 slice copy, and a single '\n' write. At

Re: Best way to check for an element in an array?

2014-04-21 Thread Ali Çehreli via Digitalmars-d-learn
On 04/21/2014 09:22 PM, Taylor Hillegeist wrote: Question though? why doesn't canFind() work on statically allocated arrays? That's an issue all of face from time to time. (Happened to me again last week. :) ) The reason is, algorithms like canFind work with input ranges and fixed-length