Extending readf?
monarch_dodra
monarchdodra at gmail.com
Thu Feb 7 05:27:12 PST 2013
Not so long ago, there was an amazing article about how user
defined types and formated writes behaved:
http://wiki.dlang.org/Defining_custom_print_format_specifiers
As cool as it is, I was writting a little user defined type, and
I wanted to the the contrary: un-format it to read it.
Apparently. You can't do it. I'm not talking about "you can't
customize it", I mean "you can't do it, at all."
For all the bashing C++'s ">>" and "<<" operators get, they at
least work both ways for UDTs.
I found this thread:
http://forum.dlang.org/thread/mailman.2107.1335304266.4860.digitalmars-d-learn@puremagic.com
And the forked thread:
http://forum.dlang.org/thread/20120424215103.GA28525@quickfur.ath.cx
Which basically amounts to "Maybe do you want to open this
discussion in the main D newsgroup?" and the suggestion "Does it
make sense to add a fromString() method to user-defined types for
this? D's toString support is awesome (you can basically call
to!string on just about anything and it works). It would be nice
to have similar support for the reverse operation." To which no
one added anything.
That was in .learn, so it might not have gotten much coverage.
How complicated wold it be to have things specify a "fromString"
method? Is it worth the effort?
Is it possible to have a "fromString" default generated? If not,
would it be OK if formatted read could work for only on things
that define "fromString"?
In any case, it feels like a pretty wide hole in regards to a
high level statically typed language.
More information about the Digitalmars-d
mailing list