www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Real naive template question

reply WhatMeForget <kheaser gmail.com> writes:
module block_template;

void main()
{
     template BluePrint(T, U)
     {
         T integer;
         U floatingPoint;
     }

     BluePrint!(int, float);
}

// DMD returns
// template.d(13): Error: BluePrint!(int, float) has no effect

// I was expecting something like the following to be created 
after compilation:

module block_template;

void main()
{
     {
         int integer;
         float floatingPoint;
     }
}


I realize this is a corner case, but shouldn't the 
BluePrint!(int, float); statement blindly create a block of code?
Aug 13 2017
parent Nicholas Wilson <iamthewilsonator hotmail.com> writes:
On Monday, 14 August 2017 at 00:44:05 UTC, WhatMeForget wrote:
 module block_template;

 void main()
 {
     template BluePrint(T, U)
     {
         T integer;
         U floatingPoint;
     }

     BluePrint!(int, float);
 }

 // DMD returns
 // template.d(13): Error: BluePrint!(int, float) has no effect

 // I was expecting something like the following to be created 
 after compilation:

 module block_template;

 void main()
 {
     {
         int integer;
         float floatingPoint;
     }
 }


 I realize this is a corner case, but shouldn't the 
 BluePrint!(int, float); statement blindly create a block of 
 code?
you want https://dlang.org/spec/template-mixin.html
Aug 13 2017