Generic collection/element function signatures in D2 versus D1

Nick Sabalausky a at a.a
Sat Sep 4 00:57:48 PDT 2010


In D1 I did this sort of thing a fair amount:

void foo(T)(T[] collection, T elem)
{
    // Blah, whatever
}

Worked for any of the string types, worked for any array, or anything with 
the appropriate opIndexes, and for all I know there may be some improvement 
that could still be made. But of course, in D2 strings have that extra 
immutable part that mucks up the above for strings (and then there's 
ranges), so: Is there a typical generally-best way in D2 to declare a 
function signature for operating on collections and elements? I know it 
would involve using the standard range interfaces in the body and choosing 
the most restrictive range type that gets the job done, and I'm fine with 
all that, but is there a good example of a typical "best-practice" 
generic-function signature in D2?

-------------------------------
Not sent from an iPhone.




More information about the Digitalmars-d-learn mailing list