March 12, 2009
On Thu, Mar 12, 2009 at 4:26 PM, Andrei Alexandrescu <SeeWebsiteForEmail@erdani.org> wrote:
>
> Nice. The problem however is that very, very often I need to store intermediate results, otherwise the code becomes quickly unreadable or spread across too many different non-reusable templates. What I now do is e.g. create a short template Blah(X, Y, Z) that aliases itself to BlahImpl!(X, Y, Z).Result. Hardly elegant.

That's true.

> I suggested Walter to allow templates using the eponymous trick to be able to define private symbols.

That seems like a reasonable solution.  I'm assuming you'd allow templates to define at most one public symbol.
March 12, 2009
Reply to Denis,

> 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; }
> 

That covers my one major concern with the exactly one rule; local values.

OTOH I have used template with many public value as a type of compile time structs. It's an absolute must for anything thing that require data structures like parsing of strings.


March 12, 2009
On Thu, 12 Mar 2009 23:56:55 +0300, BCS <ao@pathlink.com> wrote:

> Reply to Denis,
>
>> 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; }
>>
>
> That covers my one major concern with the exactly one rule; local values.
>
> OTOH I have used template with many public value as a type of compile time structs. It's an absolute must for anything thing that require data structures like parsing of strings.
>
>

You could use a tuple or struct for that purpose:

template Blah(Stuff)
{
   struct Blah
   {
       // code that defines multiple symbols here
   }
}
March 12, 2009
On Thu, 12 Mar 2009 16:37:06 -0400, Jarrett Billingsley <jarrett.billingsley@gmail.com> wrote:

> On Thu, Mar 12, 2009 at 4:20 PM, Steven Schveighoffer
> <schveiguy@yahoo.com> wrote:
>>
>> 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
>> ;)
>
> I'm not suggesting it be removed.  I'm suggesting that if you were
> only able to put one symbol in the template, it would be completely
> unnecessary.  Templates would always resolve to the single symbol that
> they declare.

So without requiring the alias how do you rewrite my example?  I'm not saying you are wrong, I just don't grasp what you are saying.  An example would be helpful.

-Steve
March 12, 2009
Reply to Denis,

> On Thu, 12 Mar 2009 23:56:55 +0300, BCS <ao@pathlink.com> wrote:
> 
>> Reply to Denis,
>> 
>>> 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; }
>> That covers my one major concern with the exactly one rule; local
>> values.
>> 
>> OTOH I have used template with many public value as a type of compile
>> time structs. It's an absolute must for anything thing that require
>> data  structures like parsing of strings.
>> 
> You could use a tuple or struct for that purpose:
> 
> template Blah(Stuff)
> {
> struct Blah
> {
> // code that defines multiple symbols here
> }
> }

Under some conditions (I never figured out the details) you end up being forced to do that anyway. However in heavy code you can literally get MB of meta data generated for struct that are never actually used for anything.


March 12, 2009
Thu, 12 Mar 2009 06:33:34 -0700, Andrei Alexandrescu 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?
> 
> Thanks,
> 
> Andrei

maybe parametrized alias
March 12, 2009
On Fri, 13 Mar 2009 00:56:48 +0300, BCS <ao@pathlink.com> wrote:

> Reply to Denis,
>
>> On Thu, 12 Mar 2009 23:56:55 +0300, BCS <ao@pathlink.com> wrote:
>>
>>> Reply to Denis,
>>>
>>>> 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; }
>>> That covers my one major concern with the exactly one rule; local
>>> values.
>>>  OTOH I have used template with many public value as a type of compile
>>> time structs. It's an absolute must for anything thing that require
>>> data  structures like parsing of strings.
>>>
>> You could use a tuple or struct for that purpose:
>>  template Blah(Stuff)
>> {
>> struct Blah
>> {
>> // code that defines multiple symbols here
>> }
>> }
>
> Under some conditions (I never figured out the details) you end up being forced to do that anyway. However in heavy code you can literally get MB of meta data generated for struct that are never actually used for anything.
>
>

These should be stripped by linked, shoudn't they?
That's a separate issue if linker doesn't do it properly.
March 12, 2009
"Nick Sabalausky" <a@a.a> wrote in message news:gpbnms$2ba1$1@digitalmars.com...
> "Andrei Alexandrescu" <SeeWebsiteForEmail@erdani.org> wrote in message news:gpb2vd$18uf$1@digitalmars.com...
>> Hello,
>>
>>
>> I'm looking for a catchy phrase denoting this D idiom:
>>
>> template Blah(Stuff)
>> {
>>    alias ... Blah;
>> }
>>
>
> Unitemplate?

...Unless you're talking specifically about an alias (as opposed to the general case of it being an alias or a const char[] or a function or a class, etc), in which case it should just be "alias template" to go along with "function template" and "class template".


March 12, 2009
Andrei Alexandrescu 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?
> 
> 
> Thanks,
> 
> Andrei

Eigentemplate.
March 12, 2009
Reply to Denis,

> On Fri, 13 Mar 2009 00:56:48 +0300, BCS <ao@pathlink.com> wrote:
> 
>> Under some conditions (I never figured out the details) you end up
>> being  forced to do that anyway. However in heavy code you can
>> literally get MB  of meta data generated for struct that are never
>> actually used for  anything.
>> 
> These should be stripped by linked, shoudn't they? That's a separate
> issue if linker doesn't do it properly.
> 

That would help some, but they cause problems both that the link level (extra IO) and the the compile time level (I have seen dmd spend *minutes* generating the meta data.