Some more details on my proposa based on UDA:
// applies to next decl
@deps!({import std.algorithm;})
void test1(){}
// applies to a set of decls
@deps!({import std.stdio;}){
void test2(){}
void test3(){}
}
// applies to all following decls (':')
@deps!({import std.array;}):
// can specify other dependencies beyond imports and have arbitrary complex logic:
@deps!({
import std.range;
static int[100] data2;
version(linux){
enum data1=import("foo");//string import
pragma(lib, "curl");
}
}):
void test4(){}
// Can alias some dependencies:
alias deps1=deps!({import std.algorithm;});
@deps1
void test4(){}
NOTE: the above code compiles if we add
`struct deps(T...){}`, but that logic would be implemented in the compiler.
Advantages:
* no new syntax (just new semantics)
* no nesting inside {} required, so no additional indentation
* allows grouping multiple declarations under a single set of imports
* `grep import` will still work unlike many of the existing proposals
* can use existing traits to query for such imports (eg getSymbolsByUDA)
* allows a more general solution (eg also handles `pragma(lib, "curl");` if we want that as well)
(Note: ignore the `variant 2` i had described above)