On Friday, 20 December 2013 at 17:57:46 UTC, Andrei Alexandrescu wrote:
On 12/20/13 9:38 AM, H. S. Teoh wrote:
What about extending symbol lookup, so that if a fully-qualified symbol x.y.z can't be found in the current symbol tables, and x/y exists in the current import path, then implicitly try to import x.y and lookup
z in that module. Then you could just write:

        void f(T)(T t) if (std.range.isInputRange!T) ...

Due to a bug that's actually the case today to some extent :o).


Andrei

In regards to template restraints, it *would* be kind of nice to be able to trigger import only when overload resolution begins.

For example, just because a function requires "std.range.isInputRange" to validate its inputs/overloads, doesn't mean it *has* to be globally imported into the entire module.

In this sense, it would be nice to be able to define an "import" block for such a function:
//----
module wow;

void bar(T)(T t)
if (isInputRange!T)
import
{
    std.range;
}
body
{
    ....
}

void foo()
{
    ....
}

//----

With such an approach, "std.range" only gets imported if a call is "attempted" to bar. if no such call is even attempted, then range isn't imported at all.

In this example, "foo" simply does not know about range. It is scoped to bar.

As a client, *if* I make no calls to bar, then I will not trigger a dependency to range in wow at all.

Reply via email to