Thread overview
[BUG] nested overload fails
Mar 27, 2004
larry cowan
Mar 27, 2004
J Anderson
Mar 27, 2004
larry cowan
Mar 27, 2004
J Anderson
March 27, 2004
Shouldn't this nested overloaded function compile and work?

void main ()
{
void Test ( int i ) { printf("i=%d\n",i); }
void Test ( int i, int j ) { printf("i=%d, j=%d\n"); }
// over.d(4): declaration main.Test is already defined
Test(1);
Test(2,3);
}

-larry


March 27, 2004
larry cowan wrote:

>Shouldn't this nested overloaded function compile and work?
>
>void main ()
>{
>void Test ( int i ) { printf("i=%d\n",i); }
>void Test ( int i, int j ) { printf("i=%d, j=%d\n"); }
>// over.d(4): declaration main.Test is already defined
>Test(1);
>Test(2,3);
>}
>
>-larry
>
Apparently you can't have nested overloads.  Frankly I don't see much use for this here (generally) anyhow as your not going to get much reuse of overloads in nested scope and overloads like this are about reuse.

-- 
-Anderson: http://badmama.com.au/~anderson/
March 27, 2004
In article <c44b7r$nko$1@digitaldaemon.com>, J Anderson says...
>
>larry cowan wrote:
>
>>Shouldn't this nested overloaded function compile and work?
>>
>>void main ()
>>{
>>void Test ( int i ) { printf("i=%d\n",i); }
>>void Test ( int i, int j ) { printf("i=%d, j=%d\n"); }
>>// over.d(4): declaration main.Test is already defined
>>Test(1);
>>Test(2,3);
>>}
>>
>>-larry
>>
>Apparently you can't have nested overloads.  Frankly I don't see much use for this here (generally) anyhow as your not going to get much reuse of overloads in nested scope and overloads like this are about reuse.
>
>-- 
>-Anderson: http://badmama.com.au/~anderson/

Just trying to get the same convenience I would have had with #defines in C/C++. No big thing, but I don't see why it should work at global scope, but not when nested in a function.  In C, I use local #defines to make repetitive code clearer to read, it's useful.

/* ****************************************** *
*       main() - used for testing only       *
* ****************************************** */
debug (Wildmatch) {

void main ( char[][] args )
{
version (win32) bit igncase = true;
version (linux) bit igncase = false;
assert(igncase);

if (args.length != 2 && args.length != 3) {
printf("Usage: filename [pattern]\n");
return;
}

char[] fn = args[1];

void TESTPATTERN ( int n, char[] patrn ) {
WildMatch wc = new WildMatch(patrn);
printf("wc%d%s1(%.*s) is %.*s\n"
,n
,igncase ? "ci" : "cs"
,wc.w()
,wc.test(fn) ? "true" : "false");
}

void TESTpattern ( int n, char[] patrn, bit caseins ) {
WildMatch wc = new WildMatch(patrn,caseins);
printf("wc%d%s1(%.*s) is %.*s\n"
,n
,caseins ? "ci" : "cs"
,wc.w()
,wc.test(fn) ? "true" : "false");
}

if (args.length == 3) {
TESTPATTERN(0,args[2]);
return;
}

TESTpattern(1,"wildmatch.d",true); // force 1 case-sensitive test
TESTpattern(2,"WILDMATCH.d",false); // force 2 case-sensitive tests
WildMatch[] wc = { new Wildmatch(3,"*match.d?",false)
,new WildMatch(4,"*") };
printf("wc%d%s1(%.*s) is %.*s\n",3,"cs"
,wc[0].w(),wc[0].test(fn) ? "true" : "false");
printf("wc%d%s1(%.*s) is %.*s\n",4,igncase ? "ci" : "cs"
,wc[1].w(),wc[1].test(fn) ? "true" : "false");
TESTPATTERN(5,"*.*");
TESTPATTERN(6,"*.d");
TESTPATTERN(7,"s*");
TESTPATTERN(8,"S*.*");
TESTPATTERN(9,"s*.d");
TESTPATTERN(10,"?*");
TESTPATTERN(11,"*?");
TESTPATTERN(12,"**");
TESTPATTERN(13,"??");
TESTPATTERN(14,"*********");
TESTPATTERN(15,"*?**?***?****?*****");
TESTPATTERN(16,"wild[j-n][aaaaaeiou]tch.[cd]");
TESTPATTERN(17,"WILD[^NJ-KL][^EIOU]TCH.[^D]XE");
TESTPATTERN(18,"wildMATCH.D");
TESTPATTERN(19,"wildmatch.d*");
TESTPATTERN(20,"w?ld??*.?");
TESTpattern(21,"a-z",false); // force...cs
TESTpattern(22,"[b-y4-8]",true); // force...ci
}
}


March 27, 2004
larry cowan wrote:

>In article <c44b7r$nko$1@digitaldaemon.com>, J Anderson says...
>  
>
>>larry cowan wrote:
>>
>>    
>>
>>>Shouldn't this nested overloaded function compile and work?
>>>
>>>void main ()
>>>{
>>>void Test ( int i ) { printf("i=%d\n",i); }
>>>void Test ( int i, int j ) { printf("i=%d, j=%d\n"); }
>>>// over.d(4): declaration main.Test is already defined
>>>Test(1);
>>>Test(2,3);
>>>}
>>>
>>>-larry
>>>
>>>      
>>>
>>Apparently you can't have nested overloads.  Frankly I don't see much use for this here (generally) anyhow as your not going to get much reuse of overloads in nested scope and overloads like this are about reuse.
>>
>>-- 
>>-Anderson: http://badmama.com.au/~anderson/
>>    
>>
>
>Just trying to get the same convenience I would have had with #defines in C/C++.
>No big thing, but I don't see why it should work at global scope, but not when
>nested in a function.  In C, I use local #defines to make repetitive code
>clearer to read, it's useful.
>  
>
It would be nice for consistency.

-- 
-Anderson: http://badmama.com.au/~anderson/