$include_dir="/home/hyper-archives/boost/include"; include("$include_dir/msg-header.inc") ?>
From: Aleksandr Golovanov (silvery_at_[hidden])
Date: 2003-08-14 00:07:13
"Ross Smith" <rosss_at_[hidden]> wrote in message
news:bher8m$gnq$1_at_sea.gmane.org...
> 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
of
> > (const)? reference to a source. I have a class which I would prefer to
be
> > noncopyable and castable with laxical_cast at the same time. I've been
> > forced to reject noncopyable concept because of that strange feature of
the
> > 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:
std::numeric_limits<Source>::is_specialized
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.
Thanks.
Aleksandr Golovanov,
MetaCommunications Engineering.