Is "auto t=T();" not the same as "T t;"?

Salih Dincer salihdb at hotmail.com
Wed Oct 26 02:25:30 UTC 2022


On Wednesday, 26 October 2022 at 00:44:45 UTC, H. S. Teoh wrote:
> 
> If you'll excuse some ASCII art, here's the situation you have:
>
> 	STACK                  GLOBAL DATA
> 	x[0] {
> 	    Y[] y; -----+----> [ Y.init ]
> 	}               |
> 	x[1] {          |
> 	    Y[] y; -----'
> 	}
>
>

Thanks for these detailed explanations, especially the ASCII art 😀

On Wednesday, 26 October 2022 at 00:58:33 UTC, Ali Çehreli wrote:
> On 10/25/22 17:16, Salih Dincer wrote:
> I tested: If you make X a 'static struct', then you see the 
> same output.

It occurred to me too, to use a static struct.  I also tried the 
following example because it can work with static in main():

import std;

void main() {
   //static
   struct X
   {
     static struct Y {
    //...
   }}

   static
   struct Bar {
     string s;

     string toString() {
       return s;
     }
   }

   auto list = "sixtwoone".chunks(3);
        list.map!(c => c.to!string)
            .map!Bar.array.writeln; // [six, two, one]
    //...
}

Thank you...

@SDB79


More information about the Digitalmars-d-learn mailing list