How to use the full namespace path to a function from D

I want to be able to use a function such as writefln(), but without adding import std.stdioto the beginning of the file.

Another way to explain this is the way you do it in C ++. You can enter std::cout << "Test";, and this will not allow you to add using namespace std;. I want to do the same, but in D.

+5
source share
5 answers

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

Static import

. , . , . :

static import std.stdio;

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

+8

, D , ++. D . D /. , D . D : http://www.digitalmars.com/d/2.0/module.html.

, :

. - .

. , , :

  • , .
  • .
  • , ..
  • .
  • .
  • .

, .

:   - .   - , .   - C A B, B C, A.

+6

. // . , std.stdio.writefln( "..." ) , std.stdio( Phobos). , , "writefln".

+5

, . import D , using namespace ++. #include .

+2

/ ( ):

import std.stdio: writef, writefln;
0

All Articles