Boost logo

Boost :

From: d.frey_at_[hidden]
Date: 2000-12-05 04:19:08


--- In boost_at_[hidden], Kevlin Henney <kevlin_at_c...> wrote:
> [...]
> >--- In boost_at_[hidden], "Peter Dimov" <pdimov_at_m...> wrote:
> >> Try this:
> >>
> >> template<std::size_t N> string lexical_cast_helper<string,
char[N]>
> >> {
> >> static std::string call(char const * s)
> >> {
> >> return s;
> >> }
> >> };
> [...]
> Great work, Peter: I mucked around with a trait-based approach a few
> months ago, but it ended up with creeping featurism so I abandoned
> it. This solves the problem directly and simply without trying to
> take on any extra bells and whistles.

Peter's approach may also be useful in other cases. I wonder if it
makes sense to start an "advanced FAQ" on boost or something like that
to present solutions to this kind of problems and common ideas from
other boost classes / libraries.

About lexical_cast_helper: I suggest hiding it in a "detail"-namespace
or something like that. You may need to change the specialization to

template< typename T, std::size_t N > class lexical_cast_helper< T,
char[N] >
{
public:
  static T call( const char* arg )
  {
    return lexical_cast_helper< T, string >::call( std::string( arg )
);
  }
};

in order to put lexical_cast itself behind the specialization (at
least I did so in my test source).

Regards, Daniel


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