Bug 8264 – [std.conv.to] constructing conversion doesn't work with alias this

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-06-18T22:28:00Z
Last change time
2012-06-20T21:05:33Z
Keywords
pull, rejects-valid
Assigned to
nobody
Creator
k.hara.pg

Comments

Comment #0 by k.hara.pg — 2012-06-18T22:28:24Z
from http://forum.dlang.org/thread/[email protected]#post-cetlbrtfhbtunchppikq:40forum.dlang.org ---- This kind conversions should be possible with std.conv.to. import std.conv; struct Wrap { string wrap; alias wrap this; } void main() { Wrap[] y = to!(Wrap[])(["foo", "bar"]); // shold work } If you can construct Wrap object with the syntax Wrap("foo"), std.conv.to runs 'conversion by construction'. And if S is convertible to T, std.conv.to!(T[])(S[] source) runs 'element-wise array conversion'. As a result, string[] to Wrap[] will be converted. ...but, this does not work in 2.060head, it is a bug.
Comment #1 by issues.dlang — 2012-06-18T22:45:19Z
Is it really bug? What if you have struct Wrap { string wrap; int i; double d; string s; alias wrap this; } Should Wrap("foo") create the same thing as Wrap("foo", int.init, double.init, string.init)? Or should it not work? Maybe it should work, but it seems a bit funny to me to create a Wrap from just a string considering that the alias doesn't define how to initialize the rest of the object.
Comment #2 by k.hara.pg — 2012-06-18T23:16:52Z
(In reply to comment #1) > Is it really bug? Yes. The problem is that declaring alias this is incorrectly matches more than two templates. If you remove 'alias wrap this' from Wrap type, the conversion will succeed. > What if you have > > struct Wrap > { > string wrap; > int i; > double d; > string s; > > alias wrap this; > } > > Should Wrap("foo") create the same thing as Wrap("foo", int.init, double.init, > string.init)? Or should it not work? Maybe it should work, but it seems a bit > funny to me to create a Wrap from just a string considering that the alias > doesn't define how to initialize the rest of the object. I also it seems a bit funny, but it should work. std.conv.to supports constructing conversion based on _syntactic possibilities_ - like range interface: r.empty, r.front, and r.popFront(). I think such limitation provides no benefit.
Comment #3 by k.hara.pg — 2012-06-18T23:39:56Z
Comment #4 by github-bugzilla — 2012-06-20T20:59:39Z
Commits pushed to master at https://github.com/D-Programming-Language/phobos https://github.com/D-Programming-Language/phobos/commit/18564f4fa20bd7d3c66e0d37494d4305edb048fd fix Issue 8264 - [std.conv.to] constructing conversion doesn't work with alias this https://github.com/D-Programming-Language/phobos/commit/32d9b329057a01b5775c4cfdebc869f86ca0c691 Merge pull request #640 from 9rnsr/fix8264 Issue 8264 - [std.conv.to] constructing conversion doesn't work with alias this
Comment #5 by github-bugzilla — 2012-06-20T21:02:02Z