How to explicitly qualify my modules with the package
Daniel Keep
daniel.keep.lists at gmail.com
Sun Mar 4 02:57:03 PST 2007
Andy Little wrote:
> 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
This fails because gcd is in the 'meta.mod_gcd' module. It would be
like saying 'std.writefln'.
> //##########################################
> }
> else{
> std.stdio.writefln("%d\n",gcd!(int,8,64).value);
> }
>
> return 0;
> }
--
Unlike Knuth, I have neither proven or tried the above; it may not even
make sense.
v2sw5+8Yhw5ln4+5pr6OFPma8u6+7Lw4Tm6+7l6+7D
i28a2Xs3MSr2e4/6+7t4TNSMb6HTOp5en5g6RAHCP http://hackerkey.com/
More information about the Digitalmars-d-learn
mailing list