How to explicitly qualify my modules with the package
Andy Little
andy at servocomm.freeserve.co.uk
Sun Mar 4 02:25:27 PST 2007
Cant figure out how the package qualifier should work or what syntax I should use to get it working.
E.g.
Where gcd is defined in sub-dir meta of this-file source dir as:
/*
"D:/projects/dmd/meta/mod_gcd.d"
//------------------------------------------------------
module meta.mod_gcd;
template gcd( T, T N, T D){
static if (D== 0){
static const T value = N;
}
else {
static const T value = gcd!(T,D, (N % D)).value;
}
}
//------------------------------------------------------
*/
static import std.stdio;
// works ok...
static if(1){
static const bool USE_PACKAGE_QUALIFIER =false;
//######################
import meta.mod_gcd;
//#####################
}
else {
/* in this path compilation fails with:
D:\Projects\dmd>dmd -c test1.d
test1.d(49): Error: template identifier gcd is not a member of meta
Error: no property 'value' for type 'int'
*/
static const int USE_PACKAGE_QUALIFIER =true;
//###########################
static import meta.mod_gcd;
//###########################
}
int main(char[][] args)
{
static if(USE_PACKAGE_QUALIFIER){
//##########################################
std.stdio.writefln("%d\n",meta.gcd!(int,8,64).value); //# line 49
//##########################################
}
else{
std.stdio.writefln("%d\n",gcd!(int,8,64).value);
}
return 0;
}
More information about the Digitalmars-d-learn
mailing list