Boost logo

Boost Users :

From: Fredrik Hedman (hedman_at_[hidden])
Date: 2005-08-24 05:36:09

I would like to be able to specify different sanity checks
on the input data using the program_options framework. This
should be a common enough requirement, but I can not find any
example that exactly fits the bill. To be more specific I have a
solution that kind of works, but I think it needs a bit to much
Here is what I have now:
  /*! Check for values greater than min.
  template <typename T>
  class value_gt {
    value_gt(std::string const & msg, T min) : msg_(msg), min_(min) {}
    void operator()(T const & v) const {
      if (v > min_) return;
      ostringstream os;
      os << msg_
         << " to small. Must be larger than " << min_
         << " . Found " << v;
      throw pgmopt::invalid_option_value(os.str());
    std::string msg_;
    T min_;
  void doSetProgram(Options & options)
    ("help,h", "show this message")
              value_gt<double>("density", 1.0)),
    "initial density")
            value_gt<unsigned>("particles", 100)),
    "number of particles")
I don't like repeating the type (see code above) and would rather
like to have access to the name of the option in the function
that does the check.
What would be a better solution? Adding to the validators idea


Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at