Import all?

monarch_dodra monarchdodra at gmail.com
Wed Jul 17 04:45:07 PDT 2013


On Wednesday, 17 July 2013 at 10:04:53 UTC, JS wrote:
> On Wednesday, 17 July 2013 at 09:57:04 UTC, monarch_dodra wrote:
>> On Wednesday, 17 July 2013 at 09:34:58 UTC, JS wrote:
>>> Is is possible to import all modules using something import 
>>> a.b.*;?
>>>
>>> I'd like to partition some modules up into smaller pieces to 
>>> simplify modification(reduce scrolling) but, of course, this 
>>> increases the number of imports drastically.
>>
>> I *think* that if you use a boost like scheme, you can do it. 
>> I'd look like this:
>>
>> +
>> + a.d
>> + a //Dir
>> +-+ b.d
>>  + c.d
>>
>> Where a.d contains:
>> //----
>> public import a.b, a.c;
>> //----
>>
>> It requries a bit of maintenance though.
>> It work for me, although I think there are open bugs about 
>> this in regards to conflicting modules/packages.
>>
>> For example, testing this, it works with dmd, but it fails for 
>> me with rdmd...
>
> so you are saying that by using public import it will make all 
> imports of imports available?
>
> e.g.,
>
> a.d
> public import a.b, a.c;
>
> test.d
> import a; // will also import a.b and a.c?

Yes, that should be it. Note, however, that a simple "public 
import" will *also* import the imported "module" as if it was 
inside, eg:

//===============================
//a.b.d:
module a.b;
void foo();

//a.c.d:
module a.c;
void bar();

//main.d
import a;
void main()
{
     foo(); //OK
     bar(); //OK
     a.foo(); //OK (!!!)
     a.bar(); //OK (!!!)
     a.b.foo(); //OK
     a.c.bar(); //OK
}
//===============================

To be frank, I don't know if this is a bug, or a feature...


More information about the Digitalmars-d-learn mailing list