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 ?

Jerome




- Jonathan M Davis

Reply via email to