Creating Structs/Classes at runtime?
H. S. Teoh
hsteoh at quickfur.ath.cx
Sun Feb 17 16:57:18 PST 2013
On Mon, Feb 18, 2013 at 01:44:49AM +0100, Brian Brady wrote:
[...]
> I was reading in some data from a csv and wanted to read it into a
> struct called.
> My problem is
> 1) my full csv is 4000 variables wide, and I really don't want to
> declare each variable in the struct (I've created a smaller one to
> test)
> 2) what if I wanted to read in different csvs of different sizes, I
> don't want to have to change my program each time?
[...]
It seems to me that what you need is not any struct or class per se, but
a runtime container that stores different kinds of data depending on
runtime input. I would recommend using an associative array instead of
trying to shoehorn dynamic data into struct fields. Say something like:
import std.variant;
Variant[string] data;
data[fieldName] = value;
...
auto myField = data[fieldName];
...
Etc.
T
--
There is no gravity. The earth sucks.
More information about the Digitalmars-d-learn
mailing list