"Jacob Carlborg" <[email protected]> wrote in message
news:[email protected]...
>
> 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.