
19 Mar
2004
19 Mar
'04
1:35 p.m.
Why not a default validator? namespace po = boost::program_options; namespace boost { namespace program_options { template<typename T> void validator<T>::operator()(any& v, const vector<string>& xs) { validators::check_first_occurence(v); string s(validators::get_single_string(xs)); try { v = any(lexical_cast<T>(s)); } catch(const bad_lexical_cast&) { throw validation_error("'" + s + "' doesn't look like a double value."); } } }} This solves my immediate problem, which is that (strangely) program_options has a validator for float but not for double.