Closed pupbrained closed 3 months ago
@pupbrained , it doesn’t quite work that way. You need to use std::optional:
https://github.com/getml/reflect-cpp/blob/main/docs/optional_fields.md
Then, you can retrieve the values using something like config.general.value_or(General())
@pupbrained , it doesn’t quite work that way. You need to use std::optional:
https://github.com/getml/reflect-cpp/blob/main/docs/optional_fields.md
Then, you can retrieve the values using something like config.general.value_or(General())
I see, I was mostly trying to avoid optionals (to avoid needing multiple value_or's) but if that's necessary that's fine. Thanks for the quick response.
@pupbrained , you can always abstract away the value_or's by using getters:
General get_general() const { return general.value_or(General()); }
I will think about this issue, but you would have to figure out whether a field has a default value at compile time. That's fairly tricky.
I'm trying to use reflect-cpp to serialize and deserialize my configuration values, but I want to give every value a default so the program can still run without a configuration (or an incomplete one). I have the configuration split into structs:
I've been testing with the General part of the config. Even though I'm supplying defaults it still complains that the fields aren't found. Is there something I'm missing or is this intended behavior? I'm not sure what else to try.