From: Tom Bachmann (e_mc_h2_at_[hidden])
Date: 2007-03-20 09:33:25
-----BEGIN PGP SIGNED MESSAGE-----
>> > And I have a (unrelated) suggestion for an improvement: add an auxiliary
>> > functor for validating. Often there are certain conditions imposed on
>> > the options, e.g. a numeric option has to be in some interval or such.
>> > This checking can be done once after parsing, but it'd be cleaner to
>> > directly incorporate it. One could encode all the information in the
>> > type, but that'd be ugly. Using Boost.Lambda, I could imagine a syntax
>> > like:
>> > po::checked_value<int> (_1 > 0 && _1 < 5)
>> > instead of
>> > po::value<checked_val<int, bounds_checker<int, 1, 4> > > ()
> Sigh. This is on todo list, but I haven't had any time for that.
I forgot to mention that this is especially useful in my case, because
then the UI can detect (some) wrong inputs and complain directly.
I think one easy way to implement this would be to (1) pass a reference
to value_semantic to the validation functions, (2) add a virtual
is_correct function to value_semantic that defaults to accepting
everything, (3) call value_semantic::is_correct in the validation
functions, (4) subclass typed_value to hold a functor that is invoked
upon overwritten is_correct, and (5) provide a checked_value function
similar to value.
(2), (4) and (5) are mostly trivial, and I'm happy to provide you a
patch for that. (1) and (3) shouldn't be hard either, but require more
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
-----END PGP SIGNATURE-----
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk