digitalmars.D - std.conv.parse for user defined structs/objects
- Ilya Yaroshenko (23/23) Dec 27 2013 Hello!
- H. S. Teoh (10/37) Dec 27 2013 I've been thinking about this too. It shouldn't be too hard to add this
- Ilya Yaroshenko (1/5) Dec 27 2013 Is "fromString" good in case of InputRange?
- H. S. Teoh (14/20) Jan 05 2014 Good point. Maybe "parse"?
- Dmitry Olshansky (4/22) Jan 06 2014 --
- Jacob Carlborg (4/24) Jan 06 2014 Isn't this starting to look like serialization?
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. 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. Best Regards, Ilya
Dec 27 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.
Dec 27 2013
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).Is "fromString" good in case of InputRange?
Dec 27 2013
On Fri, Dec 27, 2013 at 08:43:25PM +0000, Ilya Yaroshenko wrote:Good point. Maybe "parse"? class T { static T parse(R)(R inputRange) if (is(ElementType!R : dchar)) { T result; ... // parse inputRange return result; } } T -- To err is human; to forgive is not our policy. -- Samuel AdlerI'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).Is "fromString" good in case of InputRange?
Jan 05 2014
06-Jan-2014 08:19, H. S. Teoh пишет:On Fri, Dec 27, 2013 at 08:43:25PM +0000, Ilya Yaroshenko wrote:Parse from an input range... That's going to be tricky and inefficient.Good point. Maybe "parse"?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).Is "fromString" good in case of InputRange?class T { static T parse(R)(R inputRange) if (is(ElementType!R : dchar)) { T result; ... // parse inputRange return result; } } T-- Dmitry Olshansky
Jan 06 2014
On 2013-12-27 20:38, 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. 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!).Isn't this starting to look like serialization? -- /Jacob Carlborg
Jan 06 2014