phobos dependencies

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Sat Dec 21 09:10:18 PST 2013


On 12/21/13 12:08 AM, Dmitry Olshansky wrote:
> 21-Dec-2013 00:43, Martin Nowak пишет:
>> On 12/20/2013 06:27 PM, Andrei Alexandrescu wrote:
>>>
>>> I had this idea fot a while, and Walter is favorable of it as well -
>>> extend "import" for one-shot use. With that feature the example would
>>> become:
>>>
>>>      void topN(alias less = "a < b",
>>>              SwapStrategy ss = SwapStrategy.unstable,
>>>              Range, RandomGen)(Range r, size_t nth, ref RandomGen rng)
>>>          if (isRandomAccessRange!(Range) && hasLength!Range
>>>              && import.std.random.isUniformRNG!RandomGen)
>>>      { ... }
>>>
>>> In this case "import" would syntactically be placed at the beginning of
>>> a qualified name, meaning "import this module lazily and look up the
>>> symbol in it".
>>>
>>> This would simplify quite a lot of two-liners into one-liners in other
>>> places, too.
>>
>> The fact that template constraints use the module scope is indeed a root
>> cause for a lot of module dependencies, so we should tackle this problem
>> specifically.
>>
>> Couldn't static imports be made lazy without breaking any code?
>> The above example would read.
>>
>> static import std.range.
>>
>> void foo(R)(R range) if (std.range.isForwardRange!R)
>> {
>> }
>>
> That has the disadvantage of importing the whole std.range.

Yah but only if the symbol foo is actually used.

Andrei



More information about the Digitalmars-d mailing list