How do I use the full namespace path to a function in D

d

Solution

I know this is an old question, but I don't see the right answer, so I'm answering anyway.

Static Imports

Basic imports work well for programs with relatively few modules and imports. If there are a lot of imports, name collisions can start occurring between the names in the various imported modules. One way to stop this is by using static imports. A static import requires one to use a fully qualified name to reference the module's names:

static import std.stdio;

void main()
{
    writefln("hello!");            // error, writefln is undefined
    std.stdio.writefln("hello!");  // ok, writefln is fully qualified
}

Source

Problem

I want to be able to use a function such as `writefln()` but without having to add `import std.stdio` at the top of the file. Another way to explain it is the way you do it in C++. You can type `std::cout << "Test";` and that will stop you from having to add `using namespace std;`. I want to do the same thing, but in D.

Original source