Re: Opinions on iterating a struct to absorb the decoding of a CSV?

2024-03-31 Thread cc via Digitalmars-d-learn
On Monday, 1 April 2024 at 04:54:46 UTC, cc wrote: I scoured [Traits](https://dlang.org/spec/traits.html) and [std.traits](https://dlang.org/phobos/std_traits.html) looking for a simple method to tell whether a member was declared as enum but couldn't find one, so if anyone knows a proper way t

Re: Opinions on iterating a struct to absorb the decoding of a CSV?

2024-03-31 Thread cc via Digitalmars-d-learn
On Thursday, 28 March 2024 at 17:23:39 UTC, Andy Valencia wrote: I wanted a lightweight and simpler CSV decoder. I won't post the whole thing, but basically you instantiate one as: That's pretty much the best way to do it. While `.tupleof` does look kind of hacky, and you could instead itera

Re: Opinions on iterating a struct to absorb the decoding of a CSV?

2024-03-28 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Mar 28, 2024 at 05:23:39PM +, Andy Valencia via Digitalmars-d-learn wrote: [...] > auto t = T(); > foreach (i, ref val; t.tupleof) { > static if (is(typeof(val) == int)) { > val = this.get_int(); > } else { > val = this.get_str(); >

Opinions on iterating a struct to absorb the decoding of a CSV?

2024-03-28 Thread Andy Valencia via Digitalmars-d-learn
I wanted a lightweight and simpler CSV decoder. I won't post the whole thing, but basically you instantiate one as: struct Whatever { ... } ... f = File("path.csv", "r"); auto c = CSVreader!Whatever(f); foreach (rec; c) { ... CSVreader is, of course, templated: struct CSVreader