From: Fernando Cacciola (fcacciola_at_[hidden])
Date: 2002-01-25 12:35:18
----- Original Message -----
From: rogeeff <rogeeff_at_[hidden]>
Sent: Friday, January 25, 2002 1:59 PM
Subject: [boost] Re: Proposal for lexical_cast/lexical_convert
> --- In boost_at_y..., "Fernando Cacciola" <fcacciola_at_g...> wrote:
> > I think this would be really useful, but I would use a different
> > template<typename Target, typename Source>
> > Target lexical_convert(Source arg, bool* succeeded = 0 ) ;
> And what this function will return in case of error?
I though about this. Perhaps I didn't understand the intended usage for
Is it 'just' to avoid exceptions to be thrown in case of error?, or is it
intended to be used in
contexts when failure isn't critical and you can ignore it, in which case a
default Target() is ok as long as a boolean flag is also returned
I figured that the usefulness resided in the second case, not the first.
IOWs, I figured that the idea was to have a conversion that always returns
something, but signaling if it is what was expected.
Had I misunderstood the idea?
If the conversion is supposed to return 'nothing' in case of error, then the
original interface is better.
If the conversion is supposed to return something, whether the expected
thing or not, I recommend my interface.
BTW, just for the record I note that the first case could be nicely solved
with my optional class...
template<typename Target, typename Source>
optional<Target> lexical_convert(Source arg) ;
if ( int* n = peek(lexical_convert("2")) ) ...
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk