1 Jun 2011 01:00
Re: [Article Submission] Have Your Efficiency, and Flexibility Too
Timon Gehr <timon.gehr <at> gmx.ch>
2011-05-31 23:00:38 GMT
2011-05-31 23:00:38 GMT
Nick Sabalausky wrote:
>"Timon Gehr" <timon.gehr <at> gmx.ch> wrote in message
>news:is2lts$2fcn$1 <at> 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) {
>>> foreach (b; TypeTuple!(true, false))
>>> if (isSpinnable == b)
>>> addGizmosTo!(np, b)(numGizmos);
>>> return;
>>> }
>>>
>>> throw new Exception(text(numPorts) ~ "-port Gizmo not supported.");
>>> }
>>>
>>> Bye,
>>> bearophile
>>
>> Nice, but isSpinnable is always checked twice with your approach. Better:
>>
>> void addGizmos(int numPorts, bool isSpinnable, int numGizmos) {
>> foreach (np; TypeTuple!(1, 2, 3, 5, 10))
>> if (numPorts == np) {
>> if (isSpinnable) addGizmosTo!(np, true)(numGizmos);
>> else addGizmosTo!(np, false)(numGizmos);
>> return;
(Continue reading)
RSS Feed