Boost logo

Boost :

From: Neal D. Becker (nbecker_at_[hidden])
Date: 2003-05-23 06:46:03


Why not a generic default validator?
BTW, I know "typeid (T).name()" doesn't really work, but I'm not sure what
would be better.

If not totally generic, then instead at least all fundamental types could be
handled by a single generic function, using maybe is_pod to dispatch.

namespace boost { namespace program_options {
    template<typename T>
    void validator<T>::operator()(any& v, const vector<string>& xs)
    {
        check_first_occurence(v);
        string s(get_single_string(xs));
        try {
            v = any(lexical_cast<T>(s));
        }
        catch(bad_lexical_cast&) {
            throw validation_error("'" + s + "' doesn't look like a " + typeid
(T).name());
        }
    }
} }


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk