On 12/20/13 5:45 AM, Joseph Rushton Wakeling wrote:
On 20/12/13 10:06, Meta wrote:
     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
             && isUniformRNG!RandomGen)  // <--- needs
std.random.isUniformRNG
     {
         static assert(ss == SwapStrategy.unstable,
                 "Stable topN not yet implemented");
         while (r.length > nth)
         {
             auto pivot = uniform(0, r.length, rng);
             // ... etc. ...
         }
     }

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.


Andrei

Reply via email to