|
Boost Users : |
From: Vladimir Prus (ghost_at_[hidden])
Date: 2005-08-24 08:15:34
Hi Fredrik,
> Here is what I have now:
>
> /*! Check for values greater than min.
> */
> template <typename T>
> class value_gt {
> public:
> value_gt(std::string const & msg, T min) : msg_(msg), min_(min) {}
> void operator()(T const & v) const {
> if (v > min_) return;
.......
> void doSetProgram(Options & options)
> {
> options.add_options()
> ("help,h", "show this message")
> ("density",
> pgmopt::value<double>()->notifier(
> value_gt<double>("density", 1.0)),
.....
> 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
> or?
I'd suggest creating a class template derived from typed_value<T>,
overriding the 'xparse' method and adding the check there, after calling
the inherited version. This will bring your example down to:
("density",
pgmopt::value_gt<double>("density", "1.0")
It would be nicer to write:
("density",
pgmopt::value<double>()->validator(_1 < 1.0)
(Using boost.lambda to create validator expression), but it's not supported
yet. It's something I'd like to add, though.
- Volodya
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net