nested templates using Complex! with slices, ... confused, I am!

james.p.leblanc james.p.leblanc at gmail.com
Mon Aug 9 18:51:03 UTC 2021


On Monday, 9 August 2021 at 18:44:34 UTC, Paul Backus wrote:
> On Monday, 9 August 2021 at 18:35:56 UTC, james.p.leblanc wrote:
>>>```d
>>>T[] foo_temp(Complex!T[])(T x, T y){
>>>   auto r = [x, x];
>>>   auto i = [y, y];
>>>   auto z = [ Complex!T(x, y), Complex!T(x,y) ];
>>>   return z;
>>>}
>>>```
>>>
>>>void main(){
>>>   auto yd = foo_double(1.1, 2.2);
>>>   writeln(yd); ...
>>> }
>>
>> But, no ... I am WRONG!  I get the message:
>>
>> qqq.d(18): Error: identifier expected for template value 
>> parameter
>
> I think what you want is:
>
> ```d
> Complex!T[] foo_temp(T)(T x, T y) {
>   auto r = [x, x];
>   auto i = [y, y];
>   auto z = [ Complex!T(x, y), Complex!T(x,y) ];
>   return z;
> }
> ```
>
> This is what I get when I take one of the non-template versions 
> and replace `float` or `double` with `T`.

H.S & Paul,

Wow, thanks for the quick replies!

It all seems so simple now ... but I just could not see it!

I had been completely (and confidently, unfortunately) 
misunderstanding
the syntax of that left most column.

Thanks again,
James




More information about the Digitalmars-d-learn mailing list