boostorg / describe

A C++14 reflection library
https://boost.org/libs/describe
67 stars 24 forks source link

Add program_options example with a generic custom validator for enums #16

Open sdebionne opened 3 years ago

sdebionne commented 3 years ago

An example that shows how to support enums as options with Boost.ProgamOptions.

pdimov commented 2 years ago

Maybe update this to use enum_from_string and enum_to_string?

pdimov commented 2 years ago

Also, the op<< overload for described enums probably belongs to operators.hpp?

sdebionne commented 2 years ago

Indeed, this PR needs an update... I have more of these kind of examples (e.g. integration with fmt::format, pybind11...), do you think it's worth merging them to your repos?

pdimov commented 2 years ago

I already added fmtlib examples.

sdebionne commented 2 years ago

Also, the op<< overload for described enums probably belongs to operators.hpp?

AFAIU, using boost::describe::operators::operator<<; only works with described structs/classes not enum, no?

pdimov commented 2 years ago

Yes, but we can add an operator<< for enums there as well. Although that would make it impossible to use just one of the two as they are both called boost::describe::operators::operator<< so using will expose both.

sdebionne commented 2 years ago

I think an overload of operator<< for enums would be welcome (just added in the fixup). What if we put them in different namespaces aka using boost::describe::enum_operators::operator<<;?