Boost logo

Boost :

From: Terje Slettebø (tslettebo_at_[hidden])
Date: 2004-09-27 16:11:26


>From: "Arkadiy Vertleyb" <vertleyb_at_[hidden]>

> "Maxim Yegorushkin" <e-maxim_at_[hidden]> wrote
>
> > In generic code lexical_cast<> is sometimes used as a cast to the same
> > type. I would like to shortcut this rather then going all the way by
> > writing it to a stream and reading back. In my code I use the following
> > workaround:
> >
> > template<class U, class T>
> > inline typename boost::disable_if<boost::is_same<T, U>, U>::type
> > lexical_cast(T const& t)
> > {
> > return boost::lexical_cast<U>(t);
> > }
> >
> > template<class T>
> > inline T const& lexical_cast(T const& t)
> > {
> > return t;
> > }
> >
> > Does it make any sense to put it in lexical_cast.hpp?
>
> Unless somebody already started using it to get the first token from a
> string, like:
>
> boost::lexical_cast<string>(string("I am a string with spaces")); // now
> returns just "I"

lexical_cast doesn't work like that, anymore. Now, it handles strings with
whitespace in them, so the above would have identical semantics to Maxim's
suggestion. I've mailed Kevlin Henney about this thread (as I don't think he
follows the Boost list).

Regards,

Terje


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