Boost logo

Boost :

From: Kevlin Henney (kevlin_at_[hidden])
Date: 2000-11-20 14:01:02


In message <8vasrt+at8h_at_[hidden]>, d.frey_at_[hidden] writes
>1) Why does lexical_cast requires the Source to be Copy-Constructable?
>Why is lexical_cast's argument defined as 'Source arg' instead of
>'const Source& arg'?

This follows from the style of other cast functions. However, it is a
point of style that we might wish to revisit, which would in turn weaken
the requirement.

>2) I was a bit worried about performance. A small test showed that
>when converting 'int' to 'string' (IMHO a very common case),
>lexical_cast was about 18 times slower than a 'native' function. Maybe
>this depends on my compiler, STL, the weather... but I think that this
>might be a general problem. As I don't know if speed matters for you
>or if you have discussed on this issue before, I'd like to get some
>feedback before sending my test-sources, complaining too loud, etc. ;)

The performance is, in this case, the price you pay for generality. Use
of the I/O streams library raises the cost for the simple satisfaction
of common interface requirements.

However, if I were genuinely concerned about performance, I probably
would not be looking at something based on I/O formatting, and would
probably try to craft a specialized more specific to my application.
However, I have not found that I have been using lexical_cast in such
contexts.

Kevlin
____________________________________________________________

  Kevlin Henney phone: +44 117 942 2990
  Curbralan Limited mobile: +44 7801 073 508
  mailto:kevlin_at_[hidden] fax: +44 870 052 2289
  http://www.curbralan.com
____________________________________________________________


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