Thread overview | ||||||
---|---|---|---|---|---|---|
|
December 22, 2013 How can I explicitly qualify things from module? | ||||
---|---|---|---|---|
| ||||
Hello everybody. In C++ it is considered good practice to qualify names in namespaces, as in: std::vector<int> v; std::cout << std::endl; How can this be done in D, with its std module? For example I tried the following and it doesn't work. import std.stdio; void main() { std.writeln("Hello world!"); } Thank you for your time. |
December 22, 2013 Re: How can I explicitly qualify things from module? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Cpluspluser | On Sunday, 22 December 2013 at 19:23:50 UTC, Cpluspluser wrote:
> Hello everybody.
>
> In C++ it is considered good practice to qualify names in namespaces, as in:
>
> std::vector<int> v;
> std::cout << std::endl;
>
> How can this be done in D, with its std module?
> For example I tried the following and it doesn't work.
>
> import std.stdio;
>
> void main()
> {
> std.writeln("Hello world!");
> }
>
> Thank you for your time.
std.stdio.writeln("Hello world!");
|
December 22, 2013 Re: How can I explicitly qualify things from module? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Cpluspluser | On Sunday, December 22, 2013 19:23:49 Cpluspluser wrote:
> Hello everybody.
>
> In C++ it is considered good practice to qualify names in namespaces, as in:
>
> std::vector<int> v;
> std::cout << std::endl;
>
> How can this be done in D, with its std module?
> For example I tried the following and it doesn't work.
>
> import std.stdio;
>
> void main()
> {
> std.writeln("Hello world!");
> }
>
> Thank you for your time.
You have to give the full module path:
std.stdio.writeln
- Jonathan M Davis
|
December 22, 2013 Re: How can I explicitly qualify things from module? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Cpluspluser | Cpluspluser:
> In C++ it is considered good practice to qualify names in namespaces, as in:
>
> std::vector<int> v;
> std::cout << std::endl;
>
> How can this be done in D, with its std module?
Beside the answers already given you by others (of using std.stdio.writeln after a normal import), in D there are also static imports:
static import std.stdio;
And qualified imports:
import std.stdio: writeln;
All this should be more than enough for your needs.
Bye,
bearophile
|
Copyright © 1999-2021 by the D Language Foundation