2

I'm trying to compile a program released by Dalal and Triggs which uses the Boost libraries. I got an error in the Boost method validation_error due to the differences between version which the authors used (1.35) and the one that I'm using (1.46).

In the old version, the validation_error method used by the authors had the following structure:

validation_error(const std::string & what);

And the version of Boost I'm running has the following:

validation_error(kind_t kind, const std::string & option_value = "", 
                 const std::string & option_name = "");

In the code, the authors are passing a string to the old validation_error method (example below).

std::ostringstream ost;
ost << "value " << *value
      << " greater than max value " << max;
throw po::validation_error(ost.str());

How can I pass this string to the new version of validation_error?

Yamaneko
  • 3,433
  • 2
  • 38
  • 57

1 Answers1

3

You could do something like

throw boost::program_options::validation_error(
    boost::program_options::validation_error::invalid_option_value,
    "option name",
    *value
);

or

throw boost::program_options::invalid_option_value(ost.str());
Greg
  • 1,660
  • 13
  • 12
  • What does `invalid_option_value` do? And `"option name"`? – Yamaneko Aug 29 '12 at 20:44
  • 1
    You are describing validation error, in 1.35 the only option was to give string with description, what is wrong. In 1.46, you have to describe problem in a more systematic way: you tell what was wrong from kind_t enum (please check http://www.boost.org/doc/libs/1_46_0/doc/html/boost/program_options/validation_error.html), also you pass wrong value and option name which was not validated. – Greg Aug 29 '12 at 20:53
  • How do I also pass the value of `max`? – Yamaneko Aug 29 '12 at 20:57
  • 1
    Do you have to pass max value in exception? Isn't it known anyway? There is also boost::program_options::invalid_option_value which takes only string as a constructor argument. invalid_option_value is subclass of validation_error, so it could be used as drop-in replacement. – Greg Aug 29 '12 at 21:00