Scoped Imports for Structs/Classes/Template Constraints

2015-08-31 Thread jmh530 via Digitalmars-d-learn
I've been thinking about scoped imports. While it seems like you can use scoped imports a lot of the time, it seems like there are some potential cases where you can't. Most notably if a function input is a struct or class, then I can't figure out a way to use a scoped import. This also applies

Re: Scoped Imports for Structs/Classes/Template Constraints

2015-08-31 Thread Enamex via Digitalmars-d-learn
On Monday, 31 August 2015 at 19:10:45 UTC, jmh530 wrote: module local; struct S { int a = 2; } module app; import local : S; void foo(S s) { import std.stdio : writeln; writeln(s.a); } void bar() { import std.stdio : writeln; import local : S; S s;

Re: Scoped Imports for Structs/Classes/Template Constraints

2015-08-31 Thread jmh530 via Digitalmars-d-learn
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 t

Re: Scoped Imports for Structs/Classes/Template Constraints

2015-08-31 Thread Enamex via Digitalmars-d-learn
On Monday, 31 August 2015 at 21:22:07 UTC, jmh530 wrote: 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

Re: Scoped Imports for Structs/Classes/Template Constraints

2015-09-01 Thread jmh530 via Digitalmars-d-learn
On Monday, 31 August 2015 at 23:36:25 UTC, Enamex wrote: I'm not sure whether a naked 'local.S' should work; sometimes it does and sometimes it doesn't. But an `static import local;` then `voidfoo(local.S)` definitely works. `static import` forces the imported symbols to be fully qualified on

Re: Scoped Imports for Structs/Classes/Template Constraints

2015-09-01 Thread Enamex via Digitalmars-d-learn
On Tuesday, 1 September 2015 at 15:50:40 UTC, jmh530 wrote: I'm following some of your post, but not quite all of it (particularly the part at the end, and I also think static imports can't be selective). Anyway, I was thinking about something like below as one possible alternative struct T {

Re: Scoped Imports for Structs/Classes/Template Constraints

2015-09-01 Thread jmh530 via Digitalmars-d-learn
On Tuesday, 1 September 2015 at 19:48:02 UTC, Enamex wrote: They aren't selective, yeah. But the rationale is good: There's not supposed to be any way to import modules with the same path so static importing means it's entirely and always unambiguous. I understand that a static import is alw

Re: Scoped Imports for Structs/Classes/Template Constraints

2015-09-01 Thread Enamex via Digitalmars-d-learn
On Tuesday, 1 September 2015 at 21:17:10 UTC, jmh530 wrote: Consider these three different ways to import std.stdio import std.stdio; import std.stdio : writeln; static import std.stdio; and suppose writeln is the only function in std.stdio the program is using. In each case, the size of the e