std.conv.parse for user defined structs/objects
H. S. Teoh
hsteoh at quickfur.ath.cx
Fri Dec 27 12:13:32 PST 2013
On Fri, Dec 27, 2013 at 07:38:59PM +0000, Ilya Yaroshenko wrote:
> Hello!
>
> Can we introduce std.conv.parse for user defined structs/classes?
>
> I think we can define inner static method:
>
> -----------
> struct UserStruct
> {
> static typeof(this) parseImpl(Range)(Range range)
> if(...)
> {
> typeof(this) ret;
> ...
> return ret;
> }
> }
> -----------
> or something like that.
I've been thinking about this too. It shouldn't be too hard to add this
to std.conv (I'd call it "fromString", though, by analogy with
"toString" -- "parseImpl" looks a bit ugly).
> And then use it in standard parse function.
>
> The reason is common parse, formattedRead and io/stdio.readf
> functions that can be used for user defined types (and for voldemort
> user defined types too!).
>
>
> If DIP is preferred in this case, please tell me about.
[...]
I generally support this idea, though it might be a good idea to discuss
the exact design here first.
T
--
Food and laptops don't mix.
More information about the Digitalmars-d
mailing list