Spurious imports in Phobos ?

Jacob Carlborg doob at me.com
Wed Nov 9 05:50:56 PST 2011


On 2011-11-09 13:45, Somedude wrote:
> Le 09/11/2011 13:15, Jacob Carlborg a écrit :
>> Phobos contains a lot of templates and if a template isn't instantiated
>> it won't be compiled. Meaning there can be hidden compile errors if you
>> start to remove imports and they will not show until a template that
>> uses something from the import is instantiate.
>>
>
> I see, but then
> 1. is there a systematic procedure to know if a an import is really
> needed ?

Not that I know of. You can make sure that every template is 
instantiated at least once.

> 2. what is your opinion about public import ? In C++, "hidden" or
> "implicit" #includes is a common source of compilation problems (order
> of #includes), I tend to think it's a bad thing.

Sometimes public imports are useful. It's possible to emulate Java's 
import foo.* using public imports:

// a._.d

public import a.foo;
public import a.bar;

// foobar.d
import a._;

It can also be useful to have public imports if you have a module with 
array functions and a module with string functions. Then the string 
module can publicly import the array module since all(most) array 
functions will work with strings as well.

-- 
/Jacob Carlborg


More information about the Digitalmars-d-learn mailing list