Boost logo

Boost :

Subject: Re: [boost] [conversion] try_lexical_cast and 200$
From: Krzysztof Czainski (1czajnik_at_[hidden])
Date: 2013-12-12 10:02:11


2013/12/12 Peter Dimov <lists_at_[hidden]>

> Krzysztof Czainski wrote:
>
>> Whether this or try_lexical_cast, I prefer the function to return an
>> optional.
>>
>
> As I said, it's appealing, but I suspect that it will prove much less
> convenient in practice.
>
> struct X
> {
> int a;
> int b;
> };
>
> bool parse( X& x, std::string a, std::string b )
> {
> return try_lexical_cast( a, x.a ) && try_lexical_cast( b, x.b );
>
> }
>

True, but I don't think you should leave it that simple. When parsing of a
succeeds, and parsing of b fails, you get x with new value of a, and old
value of b. This may or may not be acceptable, and at the very least
deserves a heads-up comment.

Regards,
Kris


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