Boost logo

Boost Users :

Subject: [Boost-users] lexical_cast specializations
From: Alan M. Carroll (amc_at_[hidden])
Date: 2010-02-08 19:19:53


I did some searching but did not find anything that directly addresses
my issue.

I have been working with the QT library and I wanted to optimize
boost::lexical_cast for QString. My goal is to have the speed of
direct conversions (as QString provides specialized methods for char*
and std::string) while keeping the convenience of using lexical_cast
by reflex. My results (which seem to work) look like this:

namespace boost {
    template <> inline QString lexical_cast<QString, char const *>(char const * const& src) {
        return src ? QString(src) : QString();
    }
    template <> inline QString lexical_cast<QString, char *>(char * const& src) {
        return src ? QString(src) : QString();
    }
}

Is this an appropriate / recommended approach? If not, is there a
better one? There are some other cases of a similar nature that I
would like to optimize as well.


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