Custom type / Typle type formatted reader

Rekel paultjeadriaanse at gmail.com
Mon Dec 28 00:44:21 UTC 2020


It's more of a multi-part question,
I've been trying to read tuples using 'slurp', though later 
realised one of the types was an enum, I'm guessing that's what 
was the problem, which lead me down a whole rabbit hole.

- Can I directly read tuples using slurp? It doesnt seem to like 
slurp!TUPLE_ALIAS_HERE(etc

- Since slurp can read files into tuples, can I somehow tell 
slurp to name the fields?
(For example, I have `alias Instruction = Tuple!(OPERATION, 
"operation", int, "argument");`, but I'm not sure if it's 
possible to make slurp output one), or alternatively, can I 
define it's output tuple 'type'?

- If it's possible to make user types print in certain ways 
(https://wiki.dlang.org/Defining_custom_print_format_specifiers), 
is it possible to also read them back? Say using formattedRead or 
slurp or parse or even to? And if so, how does this work?

- Is it possible to read (formatted) data into enums, as for 
example I would like? I wouldnt be surprised if this question 
stands loose from the previous one, as it's not entirely the same 
situation.
I have an enum;
enum OPERATION {NOP, // Would like to read 'nop' hereto
		ACCUMULATE, // 'acc' likewise
		JUMP // and 'jmp'
		}


More information about the Digitalmars-d-learn mailing list