Am I misusing with?

faissaloo faissaloo at gmail.com
Sat Jan 19 17:49:31 UTC 2019


This seems to work fine

     file = File("test.txt", "r");
     with (file)
     {
       scope(exit) close();

       foreach (string line; file.lines())
       {
         line_array ~= line;
       }
     }

however:

     file = File("test.txt", "r");
     with (file)
     {
       scope(exit) close();

       foreach (string line; lines())
       {
         line_array ~= line;
       }
     }

Tells me I'm attempting to read from an unopened file, what's 
going on here? It seems like I'm able to use lines() like this 
within with statements unless they're in my foreach iterator. Is 
this a bug or intended behaviour?


More information about the Digitalmars-d-learn mailing list