Boost logo

Boost :

Subject: Re: [boost] [review] Convert library
From: Gavin Lambert (gavinl_at_[hidden])
Date: 2014-05-26 03:24:24


On 26/05/2014 02:59, quoth Thijs (M.A.) van den Berg:
> The value of convert to me seems to be more in the context of
> generic programming for a wide range of types with a uniform
> interface than for a simple interface for specific types for
> which there are already simple & standard alternatives.

This comment in the context of strings made me think of stateful
converters. I haven't really looked at the proposed library too
closely, but is it supported/expected to have mutable converters?

An example of this in another conversion library was one that provided
for conversion from std::wstring to const char *. This was handled by
having a local instance of a "context" object (possibly analogous to the
converter) that internally stored any memory allocated during the course
of the conversion, such that the returned pointer remained valid as long
as the context object was in scope, and no memory was leaked.

Furthermore, the way the templates were defined made it a compile error
to try to perform that type of conversion without supplying a context
object (whereas converting from std::wstring to std::string could be
done with or without one, as it did not require intermediate storage).

The same context object could be used in multiple conversions and each
would be kept distinct (so no conflicts between returned pointers), but
all freed at the end.


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