Boost logo

Boost :

Subject: Re: [boost] [convert] Version in the Vault ready for review.
From: Stewart, Robert (Robert.Stewart_at_[hidden])
Date: 2009-04-08 16:59:03


On Monday, April 06, 2009 1:23 PM
Gottlob Frege wrote:
>
> Sorry if I skimmed over some of the conversation too quickly, but if
> not already mentioned, I'd like to suggest passing in the result as a
> (by ref) param when you want more status information:
>
> A)
> int i = convert<int>::from(str); // throws if necessary
>
> B)
> int i = convert<int>::from(str, 0); // default supplied so no throw
>
> C)
> convert<int>::result res;
> int i = convert<int>::from(str, res); // no throw - error/status
> result returned in 'res'
> int i = convert<int>::from(str, 0, res); // default + status

I've been pondering this suggestion. I like that from() always returns a value and that the converted value isn't part of the result object when using one. I also like the clarity of using overloading to select the result-producing calls. I don't care much for having to default construct the result to pass it to the call, however, but it simplifies the reasoning needed to determine whether an exception will be thrown.

> I could also see using nothrow/dothrow in there somwhere, but it seems
> redundant.

dothrow is only useful in the case when the destination type has no default constructor because your case B) doesn't throw because of the default, while A) won't work for such a type. If the result type provides a means to generate the same exception as would convert<int>::from(str), then there's no need for dothrow. That is, the caller can inspect the result object and trigger the exception on conversion failure, perhaps calling a function that does both. However, that's requires extra code, whereas including dothrow in the expression somehow, makes it part of the conversion.

nothrow isn't useful in this scheme. There can be no useful return value for a nothrow call without a default or the ability to determine that the conversion failed. Passing a default or a result object handles those cases.

I think this is a nice scheme overall.

_____
Rob Stewart robert.stewart_at_[hidden]
Software Engineer, Core Software using std::disclaimer;
Susquehanna International Group, LLP http://www.sig.com

IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.


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