Boost logo

Boost Users :

From: Terje Slettebų (tslettebo_at_[hidden])
Date: 2003-04-06 19:02:12


>From: "Tom Matelich" <tmatelich_at_[hidden]>

> I'm going to embark on it, but I thought I'd ask in parallel. One of the
> things about Terje's proposed lexical_cast was a lot of documentation of
how
> to specialize it. That doesn't seem to be addressed in 1.30.0's version.

Yes, in my proposal - which then was exchanged for Kevlin's new version, the
latter I also found better - it was possible to e.g. specialise an
implementation class, to make it work on other types, or for handling of
special cases, e.g. for efficiency, as you mention.

However, it was found that it could be better to just make one version of
lexical_cast which works in the general case, especially due to the lack of
time on the end, to get such a user-defined specialisation feature reviewed,
so there was actually no docs for this specialisation in the latest version
of the proposal.

However, one can still simply overload/specialise the lexical_cast function
template, to get the same effect, even though this is not documented. It's
similar to being able to specialise components in the standard library. I
think this is a simpler way of doing it than the earlier way.

For example:

#include <boost/lexical_cast.hpp>

namespace boost
{
  template<>
  double lexical_cast<double>(const std::string &source)
  {
    // ...
  }
}

It may be a good idea to explicitly document this possibility for
lexical_cast, so it may be relied on.

> The reason I'm asking is that we did some profiling and strtod kicked
> lexical_cast's butt for string -> double. I currently use lexical_cast in
> some template'd xml code, so I could overload my function, but I'd have to
> do it in about 5 spots due to an evolving interface. I'd like to just do
it
> once for lexical_cast. I suppose I could use Terje's implementation, but
> I've stuck with boost canon for a long time now intentionally. Any
> suggestions?

See above. :)

Regards,

Terje


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net