Hello, World!
Petar
Petar
Tue Mar 29 16:23:12 UTC 2022
On Tuesday, 29 March 2022 at 14:00:20 UTC, jmh530 wrote:
> On Tuesday, 29 March 2022 at 13:49:41 UTC, Max Samukha wrote:
>> [snip]
>>
>> Nice! I didn't know it'd been added to object.d.
>
> Same.
>
> I can't recall, but in the examples where they have
> imported!"std.XXX".YYY, am I right that it all of XXX for that
> declaration?
`imported!"XXX".YYY` imports the symbol `YYY` from the module
named `XXX`. It doesn't use selective imports (although I think
it could with `opDispatch`), so the whole module named `XXX` will
be imported. `XXX` could be `std.algorithm.iteration`, but also
`mir.ndslice`, `vibe.core.net`, or any other module from a D
library (of course, assuming you have that third-party library
installed somehow, say with Dub).
In the case of Phobos, [there's a convenience module called
`std`][1] that publicly imports most of Phobos, so you simply say
`imported!"std".map`, instead of `imported!"std.algorithm".map`,
or `imported!"std.algorithm.iteration".map`. Of course, importing
the whole Phobos will make your compilation slower, but for now
that's the price to pay for a bit of convenience.
Even though some regard `import std;` as an anit-pattern, I think
it's a nice feature and it's the compiler's job to make it fast
(e.g. assuming the Phobos source files rarely change, the
compiler could generate an import cache file to make look ups
faster).
[1]:
https://github.com/dlang/phobos/blob/v2.099.0/std/package.d#L4
More information about the Digitalmars-d
mailing list