Add type safe INI field parse macros
I suggest to review this through looking at the individual commits, which makes it easier than looking at all of it at once.
Must not be started before submission of
- #614
Why don't you skip all this macro stuff and just make a templated constructor that checks the types. Would mean you don't need to change every file.
Hmm, what checks would that be able to achieve? It then would not know what type is to be expected, and will just take whatever type is passed, even if incorrect.
Hmm, what checks would that be able to achieve? It then would not know what type is to be expected, and will just take whatever type is passed, even if incorrect.
You would change all the ini pass functions to actually specify type. Then you use the templated constructor to check the types. The issue with this macro pr is you need to go out your way to add the type checking and if you are doing that you probably already know what you are doing so there isn't any benefit.
I made a short example of what i mean. It would need further work to fully align with thyme but i think it would work. http://godbolt.org/z/Y8o53xhsb It will compiler error if you give it an offset for different type to what the function wants.
As far as I am aware there is no syntactic way to call a templated constructor with template type, such that FieldParse<int32>(arg1, arg2, ...) would call the int32 templated one. Templated type on constructor needs to be deduced from passed argument. I could be wrong.
An alternative could be to somehow make a
template <ExpectedType>
constexpr FieldParse Create_FieldParse(arg1, arg2, ...)
helper function to create FieldParse with. However, passing this class member offset conveniently could be a problem. With the macros that is easily done as illustrated in this change. But if we can find good solution for it I would also prefer pure constexpr functions over macros.