Distinguish recursive Templates

Matt Kline via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri May 22 15:01:54 PDT 2015


On Friday, 22 May 2015 at 21:13:50 UTC, Manfred Nowak wrote:
> How can one determine the recursion depth for templated types?
>
> Example code:
>
> import std.stdio;
> class Set(T){
>   override string toString(){
>     return "Set";
>   }
> }
> void main(){
>   auto s0= new Set!uint;
>   writeln( s0); // writes Set
>
>   auto s1= new Set!(Set!uint);
>   writeln( s1); // should write SetSet
> }

Why should the last line write SetSet? (It doesn't.) toString 
isn't making any use of the template argument T, so no recursion 
occurs.


More information about the Digitalmars-d-learn mailing list