Today I was playing around with using std.format to read/write data, and
I discovered that while writing %s works for almost anything (via
.toString for user types), reading %s is not extensible.

I tried overloading parse() and unformatValue, but due to the way D
modules are handled, this doesn't work. It would be nice if reading %s
allowed user-defined types, perhaps via a .fromString method? Something
like:

        struct T {
                T fromString(R)(R inputRange)
                        if (is(ElementType!R : dchar))
                {
                        ...
                }
        }

Then std.format.formattedRead, if it fails to find a suitable built-in
convertor for %s, will attempt to call fromString as defined above for
the given type T passed in as argument, which will consume just enough
input to construct an instance of T.

Would this be a worthwhile addition to std.format?


T

-- 
The irony is that Bill Gates claims to be making a stable operating system and 
Linus Torvalds claims to be trying to take over the world. -- Anonymous

Reply via email to