As far as I known, when I define a string with enum and it is used at different parts of code, that string is repeated again and again in executable file instead of passing a pointer to string. So, using enum with string doesn't seem like a good idea.

Hence, I defined string as const to make it belong to struct itself instead of instances, but it comes with 'need `this` for ...' error. This indicates that the string doesn't belong to struct itself actually.

Because there is nothing like namespace in D, I used a sub-struct.

[code]
struct TableSchema{
        const string TABLE = "users";

        struct FieldTypes{
                const string ID = "BIGINT";
        }

        const string CREATESQL = "... id " ~ FieldTypes.ID ~ "...";
}
[/code]


But compiler doesn't allow me to access FieldTypes.ID. It says that it needs `this`. I tried with `static shared`, used `class` instead of `struct` etc. But couldn't have come up with a nice solution.

Reply via email to