Methinks function local imports (introduced in 2.054) is a great idea, however if it is to be allowed, I believe it should provide all the functionality of global imports: which it currently does not.

import std.stdio;
import std.string;
import std.conv;

// Note: all of these import formats work if imported here but only
// the first work if imported locally to the function.

//import std.utf;
//import std.utf: toUTF16z;
//import std.utf: wcp = toUTF16z;

void main()
{
        auto s = "漢字を書くのはどうかな~?";
        auto s1 = genText(s);
        writeln(to!string(typeid(s1)));
}

auto genText(string t)
{
        import std.utf; // This works
        //import std.utf: toUTF16z; // This doesn't
        //import std.utf: wcp = toUTF16z; // Neither does this
        
        version(Unicode)
        {
                // Note: Everything here works with global import
                // but only the first line works with function local imports
                
                return toUTF16z(t);   // This works
                //return t.toUTF16z;  // This doesn't
                //return wcp(t);      // Neither does this
                //return t.wcp;       // Or this
        }
        else
        {
                return t.toStringz;
        }
}


[OT - toUTFz]

Wasn't there discussion about adding toUTFz to the std.utf? For some reason I thought that was forthcoming in 2.054... whatever happened there?

Reply via email to