Thread overview | |||||
---|---|---|---|---|---|
|
February 10, 2012 Re: Immutable immutable strings?? | ||||
---|---|---|---|---|
| ||||
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. > 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. artur |
February 10, 2012 Re: Immutable immutable strings?? | ||||
---|---|---|---|---|
| ||||
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 |
February 10, 2012 Re: Immutable immutable strings?? | ||||
---|---|---|---|---|
| ||||
On 02/10/12 19:22, H. S. Teoh wrote:
> 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.
No idea, i'm using gcc version 4.6.3 20120106 (prerelease gdc 0.31 - r748:ab99d67f04c2, using dmd 2.057)
artur
|
Copyright © 1999-2021 by the D Language Foundation