@safe question

forkit forkit at gmail.com
Sun Jan 9 20:58:05 UTC 2022


Do not understand why one line is not considered @safe, but the 
other is.

//----

module test;

import std;

@safe void main()
{
     immutable string[] strings = ["one", "one", "two"];

     immutable(string)*[] pointers = null;

     foreach(size_t i, ref str; strings)
     {
         if(str == "one")
         {
             //pointers ~= &str; // not allowed in @safe ??

             pointers ~= &strings[i]; // for @safe, I have to 
revert to using an index into strings.
         }
         i++;
     }
}

//-----


More information about the Digitalmars-d-learn mailing list