Boost logo

Boost :

From: John Maddock (John_Maddock_at_[hidden])
Date: 2000-08-23 06:19:50


Kevlin,

What stage is lexical_cast in? Is it ready for prime time yet?

The reason I ask is that I really need some (easy) mechanism for converting
between regular expression sub-matches and int's (possibly other types as
well but int's are the most important). It seems to me that lexical_cast
is a natural match for this (thanks to Dave for reminding me of this one),
to make this work I would need to overload lexical_cast on
boost::sub_match<iterator> (within regex.hpp) and then use
basic_stringstream<typename std::iterator_traits<iterator>::value_type> for
the actual conversion:

template<typename Target, typename Iterator>
Target lexical_cast(const boost::submatch<Iterator>& arg);

There are a lot of gory details missing here - in particular I anticipate
endless complications with VC6 (no partial ordering, no partial
specialisation support) - but it is probably possible.

BTW I have two questions about lexical_cast (sorry if these have come up
before, but I couldn't find any reference after quick search on the list):

1) Why do you need lexical_context? It seems to add unnecessary complexity
and makes the code non-thread safe.
2) Can lexical_cast be moved into namespace boost, it seems to be
unnecessarily verbose to have to use boost::cast::lexical_cast.
3) What happens if there is spurious input (other than whitespace) after
the result? I think it should throw in that case.
4) What happens if the result is a string? Shouldn't it return the whole
of the string not just the first token?
5) How about support for gcc (and the broken old iostreams), yes I know
that this is a pain, but it is important for some people.

Thanks!

- John.


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