Immutable immutable strings??

H. S. Teoh hsteoh at quickfur.ath.cx
Fri Feb 10 10:22:42 PST 2012


On Fri, Feb 10, 2012 at 07:17:22PM +0100, Artur Skawina wrote:
> On 02/10/12 19:07, H. S. Teoh wrote:
> > I'm not sure whether the following a compiler/language bug or a Phobos
> > bug, but it's definitely some kind of bug:
> > 
> > 	auto s = "abc";
> > 	immutable t = "def";
> > 
> > 	writeln(typeid(s));	// immutable(char)[]
> > 	writeln(typeid(t));	// immutable(immutable(char)[])
> > 				// (what is this supposed to mean?!)
> 
> The array itself is immutable, not just the elements.

I see.


> > 	char ch = 'c';
> > 	bool b = canFind(s, ch);	// OK
> > 	bool c = canFind(t, ch);	// Compile error??
> > 
> > The compile error is:
> > 
> > test.d:11: Error: template std.algorithm.canFind(alias pred = "a == b",Range,V) if (is(typeof(find!(pred)(range,value)))) does not match any function template declaration
> > test.d:11: Error: template std.algorithm.canFind(alias pred = "a == b",Range,V) if (is(typeof(find!(pred)(range,value)))) cannot deduce template function from argument types !()(immutable(char[]),char)
> > 
> > Can somebody explain what's going on here?
> 
> FWIW, it compiles fine here.
[...]

Is it a Phobos bug that got fixed recently? I'm still using gdc-4.6.


T

-- 
Talk is cheap. Whining is actually free. -- Lars Wirzenius


More information about the Digitalmars-d-learn mailing list