Boost logo

Boost :

From: Kevlin Henney (kevlin_at_[hidden])
Date: 2005-05-12 08:59:31


In message <427A7A31.8000504_at_[hidden]>, Andrey Melnikov
<melnikov_at_[hidden]> writes
>
>The purpose of lexical cast is conversion through serializaton and
>deserialization. boost::lexical_cast is called lexical cast because it
>uses STL object serialization framework based on << and >> operators.
>
>Semantically convert_to is a different operation.
[...]
>I think we can leave lexical_cast alone as it is, but add separate
>functions for safe conversions between ascii and binary representation
>of numbers. These functions should be fast and properly named according
>to their semantic. Performance requirement can also force us to
>implement additional interface with error flag instead of throwing
>exceptions. convert_to<int>("abc") can be so fast that in some
>applications overhead of throwing an exception will be very noticeable.

I think that the specialisation (conceptual as opposed to templated)
perspective is the right way to go. lexical_cast caters for a general
need, but not all specific needs (it is stream-based and not
performance-centric), so functions that cater to more specific
conversions -- convert_to with default, string_to, etc -- seem to make
sense. It is not a load that lexical_cast should be carrying all of,
IMHO.

Kevlin

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

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