www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Extending std.format.formattedRead

reply "H. S. Teoh" <hsteoh quickfur.ath.cx> writes:
What's the correct way of implementing formattedRead support for
user-defined types? I tried overloading the unformatValue() template,
but for some reason the compiler doesn't seem to be picking it up.


T

-- 
People walk. Computers run.
Apr 24 2012
next sibling parent reply "Kenji Hara" <k.hara.pg gmail.com> writes:
On Tuesday, 24 April 2012 at 21:50:03 UTC, H. S. Teoh wrote:
 What's the correct way of implementing formattedRead support for
 user-defined types? I tried overloading the unformatValue() 
 template,
 but for some reason the compiler doesn't seem to be picking it 
 up.
Unfortunately, there is not yet general way. The definition of unformatValue for user-defined type in different module isn't considered by std.format module. D's module system is closed in basic. Kenji Hara
Apr 24 2012
parent "H. S. Teoh" <hsteoh quickfur.ath.cx> writes:
On Wed, Apr 25, 2012 at 03:42:25AM +0200, Kenji Hara wrote:
 On Tuesday, 24 April 2012 at 21:50:03 UTC, H. S. Teoh wrote:
What's the correct way of implementing formattedRead support for
user-defined types? I tried overloading the unformatValue()
template,
but for some reason the compiler doesn't seem to be picking it up.
Unfortunately, there is not yet general way. The definition of unformatValue for user-defined type in different module isn't considered by std.format module. D's module system is closed in basic.
[...] 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. T -- "Life is all a great joke, but only the brave ever get the point." -- Kenneth Rexroth
Apr 24 2012
prev sibling parent "bearophile" <bearophileHUGS lycos.com> writes:
H. S. Teoh:

 What's the correct way of implementing formattedRead support for
 user-defined types? I tried overloading the unformatValue() 
 template,
 but for some reason the compiler doesn't seem to be picking it 
 up.
Maybe do you want to open this discussion in the main D newsgroup? I think this is not a very important issue, but it's a nice thing to have. Bye, bearophile
Apr 24 2012