Boost logo

Boost :

From: Aleksandr Golovanov (silvery_at_[hidden])
Date: 2003-08-14 00:07:13

"Ross Smith" <rosss_at_[hidden]> wrote in message
> Aleksandr Golovanov wrote:
> > Hello, I'm pretty new here, but I've extensively used boost library for
> > about a year.
> > Yesterday, I ran into a small problem, lexical_cast accepts copy instead
> > (const)? reference to a source. I have a class which I would prefer to
> > noncopyable and castable with laxical_cast at the same time. I've been
> > forced to reject noncopyable concept because of that strange feature of
> > lexical_cast. Is there any particular reason of such feature? And if
not, is
> > it possible to fix it in new release?
> Wrap the object in boost::cref().

Unfortunately, cref won't work because lexical_cast propagates the source
type as a template parameter to various helper/standard templates:


    typedef typename widest_char<
       typename stream_char<Target>::type,
       typename stream_char<Source>::type>::type char_type;

A simpler solution is explicit providing of the source type:

std::string result = boost::lexical_cast<std::string, T const&>( T() );

And that solution works fine on my very old version of lexical_cast, but it
has the same problem as cref with new version.

Aleksandr Golovanov,
MetaCommunications Engineering.

Boost list run by bdawes at, gregod at, cpdaniel at, john at