std.conv - custom string to struct conversion ?
Jonathan M Davis
jmdavisProg at gmx.com
Fri Aug 2 02:11:06 PDT 2013
On Friday, August 02, 2013 10:35:22 monarch_dodra wrote:
> On Friday, 2 August 2013 at 07:59:59 UTC, Jonathan M Davis wrote:
> > On Friday, August 02, 2013 08:40:51 monarch_dodra wrote:
> >> There was a request for enhancement to provide a "fromString"
> >> for
> >> arbitrary types. The idea is that once we have that, then
> >> functions such as parse or to!S(string) will be generic, and
> >> work
> >> on mostly anything. Unfortunatly, (AFAIK), nobody is working on
> >> this.
> >>
> >> Here is a discussion I opened:
> >> http://forum.dlang.org/thread/gzodptjyzpqnhxctbbuv@forum.dlang.org
> >>
> >> ...and I just noticed it ends with me saying "I'll try to
> >> write a
> >> DIP then :)" and then not doing it :/
> >
> > What's the point of fromString when a constructor will do the
> > job just fine?
> >
> > - Jonathan M Davis
>
> Really? Because it's not generic. Unless I'm missing something,
> I'm sure you can appreciate that the goal is to allow:
>
> to!S("string")
As long as S defines a constructor which takes a string, this works just fine.
All fromString would be doing would be to declare a function which did the
same thing as the constructor.
> or
> myFile.readf("Entry: %s", &s);
>
> And a simple constructor doesn't (*CAN'T*) allow that.
Really? All it would have to do wolud be to pass the string that is the user
input into the constructor for typeof(s) and set s to that.
- Jonathan M Davis
More information about the Digitalmars-d-learn
mailing list