Thread overview |
---|
May 27, 2015 Template problem - if arg[0]==something; call arg[1]; | ||||
---|---|---|---|---|
| ||||
I have some code that I'd really like to template-ize. Currently, I've the same construct all over my code, repeated(yet slightly different) about 15 times. Too much for me, and I'd like to make it into a template. This is a sample of my current code: http://dpaste.dzfl.pl/76814846898e I essentially want to change the string helper(){ <snip> foreach(child; toSpawn.children){ switch(child.name){ case "NameOfArg1": str ~= FunctionToCall1; break; case "NameOfArg2": str ~= FunctionToCall2; break; <snip> } function to something like: handleParseTreeHelper!( string NameOfArg1, delegate FunctionToCall1, string NameOfArg2, delegate FunctionToCall2 ); Any idears? |
May 27, 2015 Re: Template problem - if arg[0]==something; call arg[1]; | ||||
---|---|---|---|---|
| ||||
Posted in reply to wobbles Attachments: | On Wed, 27 May 2015 22:35:54 +0000, wobbles wrote: quick looking thru your code raises two questions: 1. didn't you forgot to add `.stringof` in `constructCases`? 2. didn't you forgot `!` in `constructCases(Aliases[2..$])`? i.e. `constructCases~(Aliases[2..$])` it may work with that. |
May 27, 2015 Re: Template problem - if arg[0]==something; call arg[1]; | ||||
---|---|---|---|---|
| ||||
Posted in reply to ketmar Attachments: | On Wed, 27 May 2015 22:49:18 +0000, ketmar wrote: > i.e. `constructCases~(Aliases[2..$])` `constructCases!(Aliases[2..$])`, of course ;-) |
May 28, 2015 Re: Template problem - if arg[0]==something; call arg[1]; | ||||
---|---|---|---|---|
| ||||
Posted in reply to ketmar | On Wednesday, 27 May 2015 at 22:49:50 UTC, ketmar wrote:
> On Wed, 27 May 2015 22:49:18 +0000, ketmar wrote:
>
>> i.e. `constructCases~(Aliases[2..$])`
> `constructCases!(Aliases[2..$])`, of course ;-)
Only getting back to this now...
Doesnt seem to work, I think I might rethink it and write a function (A usual function, rather than a Template). Easier for me to get my puny brain around it!
|
Copyright © 1999-2021 by the D Language Foundation