
Seems natural to use boost::optional with program_options. Has anyone tried this? For example, consider this: int main (int argc, char** argv) { namespace po = boost::program_options; optional<double> x; po::options_description desc("Allowed options"); desc.add_options() ("help", "produce help message") ("x", po::value<double>()->notifier (var(x)=_1)) ; To set the optional<double> x, this uses boost::lambda. Is there a more direct approach?

Hi Neal,
Seems natural to use boost::optional with program_options. Has anyone tried this?
This request is amount my "todo" list since formal review, but I still haven't implemented it. The biggest problem is to make it work without adding dependency on <boost/optional.hpp>
("help", "produce help message") ("x", po::value<double>()->notifier (var(x)=_1)) ;
To set the optional<double> x, this uses boost::lambda. Is there a more direct approach?
One thing I consider is to forward-declare boost::optional and then add a templated constructor to 'typed_value' which will do the same thing that notifier (var(x)=_1) does above. Another possibility is to make the type of pointer stored in 'typed_value' into a template parameter. But that would not help, since optional can be read like pointer, but can't be assigned with *opt = 10; I'll try to think more about the first approach, but it might take some time, since now I'm primarily focused an fixing regression test failures. - Volodya
participants (2)
-
Neal D. Becker
-
Vladimir Prus