mayah / tinytoml

A header only C++11 library for parsing TOML
BSD 2-Clause "Simplified" License
167 stars 31 forks source link

Macro for adding custom types to Value::as<T>() #45

Open heyx3 opened 4 years ago

heyx3 commented 4 years ago

It would be nice to be able to support our own custom types to the TOML parser through templates, so that we could simply write value.as<My_t>() for any My_t that we want . Based on my reading of the source, it's already possible without touching the source by adding new template specialization for a few types. I made a macro in my project to do this; I haven't tested it yet, but would you be interested in a pull request to add this type of functionality?

I'd also like to provide an automatic way to deserialize a custom type, but I'm not sure how to do that yet; it might require source modification.

Edit: forgot to mention, I also used this in my project to provide parsers for all the different integer and float types, because the project currently only accepts int64_t and double. Would you be interested in that as well?