Scoped Imports for Structs/Classes/Template Constraints

jmh530 via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Aug 31 14:22:05 PDT 2015


On Monday, 31 August 2015 at 20:54:53 UTC, Enamex wrote:
>
> You can't use it with foo(S) because the type is used /outside/ 
> the scope of the function, in its head. You have to qualify it 
> ( void foo(local.S s) )  or import the type as:
>
> { import local: S;
>     void foo(S s) { ... }
> }

I figured the scoping was the issue. Just curious if there was a 
trick around it. The only thing I could think of was just using 
more sub-modules to break up the code by imports. The downside is 
that it might lead to longer compile times.

I'm not sure about how the first local.S resolves things. I had 
been using a selective import for S before. To get the local.S to 
compile, I have to change the import to a normal one. I'm 
concerned about the case where local contains more than just S. 
Suppose I import app : foo; in another module, wouldn't this 
import all of local? Alternately, suppose I create some function 
baz that does not use S in any way, then if I import app : baz, 
then I will inadvertently import local, correct?

The second thing does not compile for me (I had tried that 
already...). I get

app.d(3): Error: declaration expected, not '{'
app.d(10): Error: unrecognized declaration


More information about the Digitalmars-d-learn mailing list