Templates, templates, templates...

Voitech via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Jan 24 01:02:23 PST 2016


On Saturday, 23 January 2016 at 13:19:34 UTC, anonymous wrote:
> On 23.01.2016 12:30, Voitech wrote:
>> Ok so i want to hold different types in LogicRule maybe 
>> Algebraic
>> implementation would do?
>>
>> private alias ControllTemplate(T) =Rule!(T,ControllFlag);
>> private alias SymbolRule =ControllTemplate!(SymbolType);
>> private alias StringRule =ControllTemplate!(SymbolRule[]);
>> private alias LogicTemplate(T...)
>> =Rule!(Algebraic!(ControllTemplate(T))[],LogicFlag); <--error
>
> You're missing an exclamation mark there, and you've got the 
> order of Algebraic and ControllTemplate wrong. This compiles:
>
> private alias LogicTemplate(T...) = 
> Rule!(ControllTemplate!(Algebraic!T)[],LogicFlag);
>
>> private alias AlgebraicLogicRule = 
>> LogicTemplate!(SymbolRule,StringRule);
>>
>> error:
>> Error: cannot pass type (Rule!(SymbolType, ControllFlag),
>> Rule!(Rule!(SymbolType, ControllFlag)[], ControllFlag)) as a 
>> function
>> argument
> [...]
>> Is there any nicer way to handle this case ?
>
> Instead of Algebraic you could use a common base class, or 
> interface, for the Rule instantiations:
>
> abstract class RuleBase
> {
>     ... whatever common functionality rules have ...
> }
> class Rule(V,F) : RuleBase { ...}
>
> But I have to say that I'm having trouble making sense of all 
> that class and template complexity, and how it helps in 
> actually validating user input.
>
> Since this is a parsing thing, you may want to look into 
> writing parsers an/or using a parse generator. I think Pegged 
> is the most popular one for D. 
> http://code.dlang.org/packages/pegged

Hi, thanks for answering. The complexity is unnecessary as you 
said. I'm just experimenting with D language. I think i try to 
finish implementation in my own way and then will look how it may 
be done with http://code.dlang.org/packages/pegged to have a full 
spectrum of possibilities.

I added base class for Rule -> BaseRule. But this class is just a 
shell without implementation.
Is there any way to avoid this ?






More information about the Digitalmars-d-learn mailing list