Re: [Article Submission] Have Your Efficiency, and Flexibility Too

2011-06-01 Thread Nick Sabalausky
"Timon Gehr" wrote in message news:is5iha$1e2k$1...@digitalmars.com... > > It is not documented in detail but it is there =). > See: http://www.digitalmars.com/d/2.0/declaration.html > "1. typeof(this) will generate the type of what this would be in a > non-static > member function, even if not

Re: [Article Submission] Have Your Efficiency, and Flexibility Too

2011-06-01 Thread Steven Schveighoffer
On Wed, 01 Jun 2011 10:32:10 -0400, Timon Gehr wrote: Steven Schveighoffer wrote: I think there are certain special situations where you can use typeof(this). For example, as the return type for a static method. *looks for doc* Couldn't find any documentation on it... It's somewhat like st

Re: [Article Submission] Have Your Efficiency, and Flexibility Too

2011-06-01 Thread Timon Gehr
Steven Schveighoffer wrote: > I think there are certain special situations where you can use > typeof(this). For example, as the return type for a static method. > > *looks for doc* Couldn't find any documentation on it... > > It's somewhat like static this, which is inflexible in how you write i

Re: [Article Submission] Have Your Efficiency, and Flexibility Too

2011-06-01 Thread Steven Schveighoffer
On Tue, 31 May 2011 19:32:59 -0400, Nick Sabalausky wrote: "Nick Sabalausky" wrote in message news:is3tk5$1j2n$1...@digitalmars.com... "Timon Gehr" wrote in message news:is3rb5$1g32$1...@digitalmars.com... It works for me. Are you sure you did not accidentally break some other part of your

Re: [Article Submission] Have Your Efficiency, and Flexibility Too

2011-06-01 Thread Timon Gehr
Nick Sabalausky wrote: > "bearophile" wrote in message > news:is45u7$21vq$1...@digitalmars.com... >> Nick Sabalausky: >> >>> Error: template instance cannot use local 'np' as parameter to non-global >>> template addGizmosTo(int numPorts,bool isSpinnable) >> >> Are you able to reduce this to a mini

Re: [Article Submission] Have Your Efficiency, and Flexibility Too

2011-05-31 Thread Nick Sabalausky
"bearophile" wrote in message news:is45u7$21vq$1...@digitalmars.com... > Nick Sabalausky: > >> Error: template instance cannot use local 'np' as parameter to non-global >> template addGizmosTo(int numPorts,bool isSpinnable) > > Are you able to reduce this to a minimal test case? > If it is indee

Re: [Article Submission] Have Your Efficiency, and Flexibility Too

2011-05-31 Thread bearophile
Nick Sabalausky: > Error: template instance cannot use local 'np' as parameter to non-global > template addGizmosTo(int numPorts,bool isSpinnable) Are you able to reduce this to a minimal test case? Bye, bearophile

Re: [Article Submission] Have Your Efficiency, and Flexibility Too

2011-05-31 Thread Nick Sabalausky
"Nick Sabalausky" wrote in message news:is22gk$1v03$1...@digitalmars.com... > Getting in just under the wire here. I seem to have misjudged the scope of > my topic, it ended up a bit large... Anyway, here's my entry: > > http://www.semitwist.com/articles/EfficientAndFlexible/SinglePage/ > Thank

Re: [Article Submission] Have Your Efficiency, and Flexibility Too

2011-05-31 Thread Nick Sabalausky
"Nick Sabalausky" wrote in message news:is3tk5$1j2n$1...@digitalmars.com... > "Timon Gehr" wrote in message > news:is3rb5$1g32$1...@digitalmars.com... >> >> It works for me. Are you sure you did not accidentally break some other >> part of >> your __traits(compiles,...) ? >> >> My minimal test

Re: [Article Submission] Have Your Efficiency, and Flexibility Too

2011-05-31 Thread Nick Sabalausky
"Timon Gehr" wrote in message news:is3rb5$1g32$1...@digitalmars.com... > > Nick Sabalausky wrote: >> >> "Timon Gehr" wrote in message >> news:is2lts$2fcn$1...@digitalmars.com... >> > >> > @Article: A very good read, it does not get boring even though it is >> > quite >> > long. I >> > like it.

Re: [Article Submission] Have Your Efficiency, and Flexibility Too

2011-05-31 Thread Timon Gehr
Nick Sabalausky wrote: >"Timon Gehr" wrote in message >news:is2lts$2fcn$1...@digitalmars.com... >> bearophile wrote: >>> ... >>> A shorter way to write it: >>> >>> void addGizmos(int numPorts, bool isSpinnable, int numGizmos) { >>> foreach (np; TypeTuple!(1, 2, 3, 5, 10)) >>> if (numPo

Re: [Article Submission] Have Your Efficiency, and Flexibility Too

2011-05-31 Thread Nick Sabalausky
"Timon Gehr" wrote in message news:is2lts$2fcn$1...@digitalmars.com... > bearophile wrote: >> ... >> A shorter way to write it: >> >> void addGizmos(int numPorts, bool isSpinnable, int numGizmos) { >> foreach (np; TypeTuple!(1, 2, 3, 5, 10)) >> if (numPorts == np) { >> for

Re: [Article Submission] Have Your Efficiency, and Flexibility Too

2011-05-31 Thread Timon Gehr
Nick Sabalausky wrote: > > "Timon Gehr" wrote in message > news:is2lts$2fcn$1...@digitalmars.com... > > > > @Article: A very good read, it does not get boring even though it is quite > > long. I > > like it. > > > > Thanks :) > > > Small nitpick: > > mixin(declareInterface("IGizmo", "Gizmo!(numPo

Re: [Article Submission] Have Your Efficiency, and Flexibility Too

2011-05-31 Thread Nick Sabalausky
"Timon Gehr" wrote in message news:is2lts$2fcn$1...@digitalmars.com... > > @Article: A very good read, it does not get boring even though it is quite > long. I > like it. > Thanks :) > Small nitpick: > mixin(declareInterface("IGizmo", "Gizmo!(numPorts, isSpinnable)")); > > It seems like this s

Re: [Article Submission] Have Your Efficiency, and Flexibility Too

2011-05-31 Thread Timon Gehr
> Timon Gehr: > >> Nice, but isSpinnable is always checked twice with your approach. > > Right. But isn't the compiler able to optimize away this inefficiency? Nope. You don't get a guarantee from the language that your code will be optimized in a certain way. That said, dmd/gdc are _not_ able to

Re: [Article Submission] Have Your Efficiency, and Flexibility Too

2011-05-31 Thread bearophile
Timon Gehr: > Nice, but isSpinnable is always checked twice with your approach. Right. But isn't the compiler able to optimize away this inefficiency? > I would like an explicit "static foreach" better though. See: http://d.puremagic.com/issues/show_bug.cgi?id=4085 Bye, bearophile

Re: [Article Submission] Have Your Efficiency, and Flexibility Too

2011-05-31 Thread Timon Gehr
Ary Manzana wrote: > Why you need a type tuple? Can't you do: > > foreach(np; [1, 2, 3, 5, 10]) That is a runtime foreach, so no. If the argument is a TypeTuple, the compiler evaluates the foreach as a "static foreach", effectively duplicating all code in its body and filling in the constants/type

Re: [Article Submission] Have Your Efficiency, and Flexibility Too

2011-05-31 Thread Ary Manzana
On 5/31/11 6:05 PM, bearophile wrote: Nick Sabalausky: http://www.semitwist.com/articles/EfficientAndFlexible/SinglePage/ Regarding your addGizmos() in ex6_meta_flex3_runtimeToCompileTime1.d: void addGizmos(int numPorts, bool isSpinnable, int numGizmos) { // Dispatch to correct version

Re: [Article Submission] Have Your Efficiency, and Flexibility Too

2011-05-31 Thread Timon Gehr
bearophile wrote: > ... > A shorter way to write it: > > void addGizmos(int numPorts, bool isSpinnable, int numGizmos) { > foreach (np; TypeTuple!(1, 2, 3, 5, 10)) > if (numPorts == np) { > foreach (b; TypeTuple!(true, false)) > if (isSpinnable == b) >

Re: [Article Submission] Have Your Efficiency, and Flexibility Too

2011-05-31 Thread bearophile
Nick Sabalausky: > http://www.semitwist.com/articles/EfficientAndFlexible/SinglePage/ Regarding your addGizmos() in ex6_meta_flex3_runtimeToCompileTime1.d: void addGizmos(int numPorts, bool isSpinnable, int numGizmos) { // Dispatch to correct version of addGizmosTo. // Effectively conve

[Submission] Have Your Efficiency, and Flexibility Too

2011-05-31 Thread Nick Sabalausky
"Jonathan M Davis" wrote in message news:mailman.494.1306830186.14074.digitalmar...@puremagic.com... > Okay. According to a recent post on the Announce group, Walter wants all > articles for the contest to be posted to the D newsgroup with [Submission] > in > the subject line, so I'm reposting t

Re: [Article Submission] Have Your Efficiency, and Flexibility Too

2011-05-31 Thread Nick Sabalausky
"Lars T. Kyllingstad" wrote in message news:is2aah$29pf$1...@digitalmars.com... > On Tue, 31 May 2011 02:36:58 -0400, Nick Sabalausky wrote: > >> Getting in just under the wire here. I seem to have misjudged the scope >> of my topic, it ended up a bit large... Anyway, here's my entry: >> >> http:

Re: [Article Submission] Have Your Efficiency, and Flexibility Too

2011-05-31 Thread Lars T. Kyllingstad
On Tue, 31 May 2011 02:36:58 -0400, Nick Sabalausky wrote: > Getting in just under the wire here. I seem to have misjudged the scope > of my topic, it ended up a bit large... Anyway, here's my entry: > > http://www.semitwist.com/articles/EfficientAndFlexible/SinglePage/ Nice article. :) Some of