1

I want to set an individual option with the boost::program_options library. The documentation doesn't seem to cover this. The variables_map structure the library populates inherits a map, so adding the following to my program (seems to) work:

namespace boost {
    namespace program_options {
        template <typename T>
        void set_in_options(variables_map m, const std::string& option_name, const T& value) {
            m.insert(std::make_pair(option_name, variable_value(value, false)));
        }
        void set_in_options(variables_map m, const std::string& option_name) {
            m.insert(std::make_pair(option_name, variable_value(true, false)));
        }
    }
}

But surely the library author has some "right way" to do this?

einpoklum
  • 118,144
  • 57
  • 340
  • 684
  • Can you tell us what is "not right" about this (except of course definining it in `boost::program_options`)? Seems that the `variables_map` is exactly what you need and have used. – sehe Jul 21 '15 at 07:58
  • @sehe It's not right that in order to set an option I would need to construct a pair and to refer to something which should be entirely an implementation detail (the 'isdefaulted' boolean). – einpoklum Jul 21 '15 at 09:58
  • Ah. I think that the isdefaulted could be important, but if that was not part of documented API I see your point. +1 – sehe Jul 21 '15 at 10:07
  • @sehe: Umm, you haven't actually +1 'ed me :-) – einpoklum Jul 21 '15 at 10:56
  • corrected. I was on mobile and it's easy to forget (because not in-frame) – sehe Jul 21 '15 at 13:16

0 Answers0