Generic collection/element function signatures in D2 versus D1
Brad Roberts
braddr at puremagic.com
Sat Sep 11 21:42:01 PDT 2010
On 9/11/2010 9:32 PM, Nick Sabalausky wrote:
> "Jacob Carlborg" <doob at me.com> wrote in message
> news:i5t61q$2j76$1 at digitalmars.com...
>>
>> If you're not going to modify the content of the array I think this will
>> work:
>>
>> void foo (T) (const(T)[] collection, T elem) {}
>>
>> This will allow both mutable, immutable and const arrays. But it will not
>> let you modify the array like this:
>>
>> collection[3] = 'a';
>>
>
> On DMD 2.048, This isn't working for me:
>
> -----------------------------------------
> void foo(T)(const(T)[] coll, T elem)
> {
> }
>
> void main()
> {
> string x = "hello";
> foo(x, x[1]);
> }
>
> -----------------------------------------
>
> Result:
> -----------------------------------------
> testStringAndChar.d(8): Error: template testStringAndChar.foo(T) does not
> match any function template declaration
> testStringAndChar.d(8): Error: template testStringAndChar.foo(T) cannot
> deduce template function from argument types !()(string,immutable(char))
> -----------------------------------------
>
> I figured that was just because 'const(immutable(T))[]' doesn't make much
> sence, so I tried this and got the exact same error messages:
>
> -----------------------------------------
> import std.traits;
>
> void foo(T)(const(Unqual!T)[] coll, T elem)
> {
> }
>
> void main()
> {
> string x = "hello";
> foo(x, x[1]);
> }
> -----------------------------------------
>
> It seems to be a problem with IFTI, because this does work with both
> versions:
> foo!char(x, x[1]);
>
> Kind of a pain.
>
http://d.puremagic.com/issues/show_bug.cgi?id=2594
More information about the Digitalmars-d-learn
mailing list