alias type reduction

js.mdnq js_adddot+mdng at gmail.com
Sun Dec 16 15:04:09 PST 2012


On Sunday, 16 December 2012 at 15:21:17 UTC, Philippe Sigaud
wrote:
>>
>>
>> The real issue I'm having now is not having to mangle the 
>> names and hide
>> the `_NestLevel` and `_Offset` dependencies.
>>
>> alias works for the case of one template argument to _A. 
>> Simply `alias
>> _A!(true) A`. But when I have more than one such as `class 
>> _A(T1, bool)` I
>> can't do `alias _A!(T1, true) A(T1)` analogous to the first 
>> case.
>>
>
> Because A(T1) would itself be a template, hence our proposal:
>
> template A(T1) { ... }
>
>
> You could also use overloads, as for functions:
>
> class A ( 3 args version) { ... }
> class A (2 args version) { ... }
> class A (1 arg ) { ... }
>
>
>>
>>> You should try to use templated factory functions:
>>>
>>> auto makeA(..., bool _NestLevel = true)
>>> {
>>>     return new A!(..., _NestLevel)();
>>> }
>>>
>>
>>
>> Ok, I'm not familiar with these, I've seen a lot of "weird" 
>> notation
>> dealing with a variable number of template args(I think it's 
>> `T...`?)
>
> and such. I'll play around with it and hopefully get somewhere 
> ;)
>>
>
> Yes, Symbol... (three dots) is the template tuple parameter 
> syntax. They
> are heavily used and are one of the most useful parts of D 
> templates. Docs
> are here:
>
> http://dlang.org/template.html#TemplateTupleParameter
> http://dlang.org/tuple.html
> http://dlang.org/variadic-function-templates.html
> http://dlang.org/templates-revisited.html
>
> They are a bit old (they were already there in 2008 when I 
> began with D),
> but still useful.
>
> Also, I wrote a tutorial on templates with other people being 
> kind enough
> to put example code in it. You'll find it here:
>
>
> https://github.com/PhilippeSigaud/D-templates-tutorial/blob/master/dtemplates.pdf?raw=true

Thanks, I'll look into these. It's nice D has such features but
it's a pain to find all the documentation to help get a grip on
how to use it ;)


More information about the Digitalmars-d-learn mailing list