On 18/01/12 18:05, Timon Gehr wrote:
On 01/18/2012 05:40 PM, Jerome BENOIT wrote:


On 18/01/12 17:07, Timon Gehr wrote:
On 01/18/2012 04:57 PM, Timon Gehr wrote:
On 01/18/2012 02:32 PM, Jerome BENOIT wrote:


On 18/01/12 04:36, Jonathan M Davis wrote:
On Wednesday, January 18, 2012 02:33:25 Jerome BENOIT wrote:
And I cannot figure why :-(

http://d.puremagic.com/issues/show_bug.cgi?id=1528

As a workaround, templatize the last function by changing its
signature to

int[] find()(int[] longer, int[] shorter)

actually it does not work either: gdmd gives an other error message
now.

------------------------------------------------------------------------

T[] find(T, E)(T[] haystack, E needle)
if (is(typeof(haystack[0] != needle) == bool)) {
while (haystack.length > 0 && haystack[0] != needle) {
haystack = haystack[1 .. $];
}
return haystack;
}

TL[] find(TL, TS)(TL[] longer, TS[] shorter)
if (is(typeof(longer[0 .. 1] == shorter) : bool)) {
while (longer.length >= shorter.length) {
if (longer[0 .. shorter.length] == shorter) break;
longer=longer[1 .. $];
}
return longer;
}

int[] find()(int[] longer, int[] shorter) {
while (longer.length >= shorter.length) {
if (longer[0 .. shorter.length] == shorter) break;
longer=longer[1 .. $];
}
return longer;
}

unittest {
// Test the introduced overloads
long[] a1 = [ 6, 1, 2, 3 ];
long[] a2 = [ 1 , 2 ];
int[] b1 = [ 6, 1, 2, 3 ];
int[] b2 = [ 1 , 2 ];
assert(find(a1, a2) == a1[1 .. $]);
assert(find(a1, b2) == a1[1 .. $]);
assert(find(b1, b2) == b1[1 .. $]);
}

void main() {}
------------------------------------------------------------------------


The message is now:
searching_05.d:34: Error: template searching_05.find(T,E) if
(is(typeof(haystack[0] != needle) == bool)) find(T,E) if
(is(typeof(haystack[0] != needle) == bool)) matches more than one
template declaration, searching_05.d(9):find(TL,TS) if
(is(typeof(longer[0..1] == shorter) : bool)) and
searching_05.d(18):find()

Is partial ordering really supported ?


Yes it is, and your code snippet indeed compiles on my machine. Are you
maybe using an outdated version of the compiler?



Nevermind, I forgot to pass the -unittest switch. It indeed gives that
error. The reason it still does not compile is that the workaround
proposed by Jonathan has slightly different semantics than it would
have if the compiler already supported overloading of functions
against function templates.

If exactly one of two equally good matched functions is a templated
one, the other one is chosen.

So the D code in my first post may work and thus the workaround is not
necessary.


The language does not mandate the workaround, but the workaround is necessary 
until the compiler is fixed.

Thanks for the precision. So I will move to the next section and come back to 
this part when the compiler is fix:
I guess it will be fixed for the next release as it sounds as an important bug.

Jerome

Reply via email to