Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
Change import_ to imported
Browse files Browse the repository at this point in the history
  • Loading branch information
andralex authored and RazvanN7 committed Sep 15, 2021
1 parent 06c8ad5 commit 6545081
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/object.d
Original file line number Diff line number Diff line change
Expand Up @@ -4745,7 +4745,7 @@ Provides an "inline import", i.e. an `import` that is only available for a
limited lookup. For example:
---
void fun(import_!"std.stdio".File input)
void fun(imported!"std.stdio".File input)
{
... use File from std.stdio normally ...
}
Expand All @@ -4755,8 +4755,8 @@ There is no need to import `std.stdio` at top level, so `fun` carries its own
dependencies. The same approach can be used for template constraints:
---
void fun(T)(import_!"std.stdio".File input, T value)
if (import_!"std.traits".isIntegral!T)
void fun(T)(imported!"std.stdio".File input, T value)
if (imported!"std.traits".isIntegral!T)
{
...
}
Expand All @@ -4769,8 +4769,8 @@ made available:
---
void fun()
{
with (import_!"std.datetime")
with (import_!"std.stdio")
with (imported!"std.datetime")
with (imported!"std.stdio")
{
Clock.currTime.writeln;
}
Expand All @@ -4781,19 +4781,19 @@ The advantages of inline imports over top-level uses of the `import` declaration
are the following:
$(UL
$(LI The `import_` template specifies dependencies at declaration level, not at
$(LI The `imported` template specifies dependencies at declaration level, not at
module level. This allows reasoning about the dependency cost of declarations in
separation instead of aggregated at module level.)
$(LI Declarations using `import_` are easier to move around because they don't
$(LI Declarations using `imported` are easier to move around because they don't
require top-level context, making for simpler and quicker refactorings.)
$(LI Declarations using `import_` scale better with templates. This is because
$(LI Declarations using `imported` scale better with templates. This is because
templates that are not instantiated do not have their parameters and constraints
instantiated, so additional modules are not imported without necessity. This
makes the cost of unused templates negligible. Dependencies are pulled on a need
basis depending on the declarations used by client code.)
)
The use of `import_` also has drawbacks:
The use of `imported` also has drawbacks:
$(UL
$(LI If most declarations in a module need the same imports, then factoring them
Expand All @@ -4806,11 +4806,11 @@ dependencies spread throughout the module.)
)
See_Also: The $(HTTP forum.dlang.org/post/tzqzmqhankrkbrfsrmbo@forum.dlang.org,
forum discussion) that led to the creation of the `import_` facility. Credit is
forum discussion) that led to the creation of the `imported` facility. Credit is
due to Daniel Nielsen and Dominikus Dittes Scherkl.
*/
template import_(string moduleName)
template imported(string moduleName)
{
mixin("import import_ = " ~ moduleName ~ ";");
mixin("import imported = " ~ moduleName ~ ";");
}

0 comments on commit 6545081

Please sign in to comment.