|
Boost Users : |
Subject: Re: [Boost-users] [lexical_cast] How is the degenerate case handled?
From: Alexander Nasonov (alnsn_at_[hidden])
Date: 2009-04-20 10:53:45
Robert Jones <robertgbjones <at> gmail.com> writes:
>
> If you use lexical_cast to cast between identical types,eg. lexical_cast< int
>( 4 );does it go through all the machinery of streaming out and back, ordoes
it short circuit? In those circumstances, does the type need
> to be streamable?Thanks, Rob.
This is not a common usecase and I see only one practical use of it. Trivial
conversion can be used for data normalization. But ValueType is supposed to be
always normalized (or to be indistinguishable from a normalized value). In
fact, I can't even give you a good example because all my ideas are based on
a string representation of values, e.g. "+1" -> "1" or "(0,\t1)" -> "(0,1)".
For these, you need two conversions: string -> T -> string.
So, you can't optimize a general case because theoretically one can use
a trivial conversion for normalization. You could optimize for well known
types with no-op normalization such as integers but I don't see a practical
use of it.
Alex
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