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

2011-06-01 Thread Timon Gehr
Nick Sabalausky wrote: bearophile bearophileh...@lycos.com 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

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 a@a.a wrote: Nick Sabalausky a@a.a wrote in message news:is3tk5$1j2n$1...@digitalmars.com... Timon Gehr timon.g...@gmx.ch wrote in message news:is3rb5$1g32$1...@digitalmars.com... It works for me. Are you sure you did not accidentally break

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 it.

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 timon.g...@gmx.ch 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...

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

2011-06-01 Thread Nick Sabalausky
Timon Gehr timon.g...@gmx.ch 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,

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

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

2011-05-31 Thread Nick Sabalausky
Lars T. Kyllingstad public@kyllingen.NOSPAMnet 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

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

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 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

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/types in

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
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 do

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

2011-05-31 Thread Nick Sabalausky
Timon Gehr timon.g...@gmx.ch 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

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

2011-05-31 Thread Timon Gehr
Nick Sabalausky wrote: Timon Gehr timon.g...@gmx.ch 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,

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

2011-05-31 Thread Nick Sabalausky
Timon Gehr timon.g...@gmx.ch 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) {

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

2011-05-31 Thread Timon Gehr
Nick Sabalausky wrote: Timon Gehr timon.g...@gmx.ch 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 ==

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

2011-05-31 Thread Nick Sabalausky
Timon Gehr timon.g...@gmx.ch wrote in message news:is3rb5$1g32$1...@digitalmars.com... Nick Sabalausky wrote: Timon Gehr timon.g...@gmx.ch 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

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

2011-05-31 Thread Nick Sabalausky
Nick Sabalausky a@a.a wrote in message news:is3tk5$1j2n$1...@digitalmars.com... Timon Gehr timon.g...@gmx.ch 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

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

2011-05-31 Thread Nick Sabalausky
Nick Sabalausky a@a.a 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/ Thanks

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
bearophile bearophileh...@lycos.com 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?