catchy phrase for this idiom?

Denis Koroskin 2korden at gmail.com
Thu Mar 12 13:30:07 PDT 2009


On Thu, 12 Mar 2009 23:20:07 +0300, Steven Schveighoffer <schveiguy at yahoo.com> wrote:

> On Thu, 12 Mar 2009 16:11:49 -0400, Jarrett Billingsley wrote:
>
>> On Thu, Mar 12, 2009 at 9:33 AM, Andrei Alexandrescu
>> <SeeWebsiteForEmail at erdani.org> wrote:
>>> Hello,
>>>
>>>
>>> I'm looking for a catchy phrase denoting this D idiom:
>>>
>>> template Blah(Stuff)
>>> {
>>>   alias ... Blah;
>>> }
>>>
>>> i.e., defining inside a template a symbol of the same name as the  
>>> template
>>> itself. Then you can use Blah!(X, Y) to mean Blah!(X, Y).Blah.
>>>
>>> What would be a catchy, descriptive, and memorable phrase for this?
>>
>> ...Unnecessary?
>>
>> You know i have to be contrary :P but I have never found a use for
>> multiple declarations inside a template _except_ when it's used as a
>> mixin.  Most of the time, I declare exactly one symbol inside the
>> template, and it's always the same name as the template.  Having to
>> specify the name of the template over and over inside it is a blatant
>> violation of DRY, easy to mess up (typos, changing the template name
>> etc.) and is hard to diagnose when you do it wrong, since the compiler
>> just has no idea what you're trying to do and you end up with all
>> sorts of confusing errors about voids having no value.
>
> How do you do this without the Template Identity syntax?
> (I'm going to start calling it this to promote the term I thought was  
> best ;)
>
> tempalte Blah(T)
> {
>     static if(is(T : int))
>        alias T Blah;
>     else
>        alias T* Blah;
> }
>
> -Steve

A new 'tempalte' keyword?

Back on topic, I don't see anything wrong with this code. It defines exactly one alias.

I also think that it should define exactly one /public/ alias:

template Blah(T)
{
    private alias Foo!(T).A Tmp1;
    private alias Bar!(Tmp1!(T)).B Tmp2;

    static if (Tmp2.C!(T)) {
        private alias Tmp2.ResultA Tmp3;
    } else {
        private alias Tmp2.ResultB Tmp3;
    }

    /*public*/ alias Tmp3!(Tmp2!(Tmp1!())).C Blah;
}

This syntax makes little sense for template mixins, and that's one more reason why I proposed separating them (see my other post nearby).




More information about the Digitalmars-d mailing list