> On 6/19/10 12:53 AM, Jeroen Habraken wrote:
> > Hi,
> >
> > My employer was using boost::lexical_cast for which I laughed at him,
> > saying he should be using boost::spirit. This ended in me having to
> > put my money where my mouth was, and I wrote the attached code. In a
> > trivial benchmark it turned out to be about six times faster than
> > boost::lexical_cast when compiled with -O2 using g++.
> >
> > Maybe someone else has a good use for it, or even better, the time to
> extend it.
>
> You can make this faster:
> 1) Don't use a rule. Make the parser argument a template.
> 2) Use qi::long_long for 64 bit integers.
> 3) Use O3
And, you can make it simpler by utilizing the auto-parser:
template
inline T spirit_cast(std::string const & input)
{
T value;
std::string::const_iterator begin = input.begin();
bool result = boost::spirit::qi::parse(
begin, input.end(), value);
if (!result || begin != input.end())
throw std::bad_cast();
return value;
};
This will work out of the box for all built-in types.
Regards Hartmut
---------------
Meet me at BoostCon
www.boostcon.com
>
> Regards,
> --
> Joel de Guzman
> http://www.boostpro.com
> http://spirit.sf.net
>
>
>
>
>
--------------------------------------------------------------------------
> ----
> ThinkGeek and WIRED's GeekDad team up for the Ultimate
> GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the
> lucky parental unit. See the prize list and enter to win:
> http://p.sf.net/sfu/thinkgeek-promo
> _______________________________________________
> Spirit-general mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/spirit-general
------------------------------------------------------------------------------
ThinkGeek and WIRED's GeekDad team up for the Ultimate
GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the
lucky parental unit. See the prize list and enter to win:
http://p.sf.net/sfu/thinkgeek-promo