Bug 13122 – std.algorithm.cartesianProduct output type immutability

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2014-07-13T12:57:00Z
Last change time
2015-01-08T17:45:57Z
Assigned to
nobody
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2014-07-13T12:57:15Z
void main() { import std.algorithm: cartesianProduct; immutable a = "ABC"; foreach (t1; cartesianProduct(a, a)) pragma(msg, typeof(t1)); immutable b = "ABC"d; foreach (t2; cartesianProduct(b, b)) pragma(msg, typeof(t2)); } The latest dmd 2.066beta3 outputs: Tuple!(dchar, dchar) Tuple!(immutable(dchar), immutable(dchar)) Expected output: Tuple!(dchar, dchar) Tuple!(dchar, dchar)
Comment #1 by hsteoh — 2014-09-21T05:55:16Z
Hmm. Isn't this expected behaviour? After all, typeof(a) == immutable(dchar)[], so shouldn't the cartesianProduct result contain the same element type, i.e., immutable(dchar)?
Comment #2 by hsteoh — 2014-09-21T05:56:02Z
Sorry, I meant, typeof(b).
Comment #3 by bearophile_hugs — 2014-09-21T11:25:05Z
(In reply to hsteoh from comment #1) > Hmm. Isn't this expected behaviour? Probably yes, but I have opened a discussion thread: http://forum.dlang.org/thread/[email protected]
Comment #4 by peter.alexander.au — 2015-01-02T21:23:52Z
(In reply to bearophile_hugs from comment #3) > (In reply to hsteoh from comment #1) > > Hmm. Isn't this expected behaviour? > > Probably yes, but I have opened a discussion thread: > http://forum.dlang.org/thread/[email protected] Don't want to bump the thread. The reason filtering a string yields dchar instead of immutable(dchar) is because string.front returns a decoded dchar by value. On the other hand iterating a dstring returns the dchar by ref, so you see its immutability. Shall we close this bug?
Comment #5 by bearophile_hugs — 2015-01-08T14:50:56Z
(In reply to Peter Alexander from comment #4) > The reason filtering a string yields dchar instead of immutable(dchar) is > because string.front returns a decoded dchar by value. On the other hand > iterating a dstring returns the dchar by ref, so you see its immutability. > > Shall we close this bug? The current behaviour is is a little strange, but I guess you are right. I close this down then, as invalid.
Comment #6 by hsteoh — 2015-01-08T17:45:57Z
Yet another unfortunate consequence of autodecoding. :-(