alias type reduction
Philippe Sigaud
philippe.sigaud at gmail.com
Sun Dec 16 07:21:07 PST 2012
>
>
> 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20121216/9d567326/attachment.html>
More information about the Digitalmars-d-learn
mailing list