Boost logo

Boost :

Subject: Re: [boost] [review] string convert
From: Stewart, Robert (Robert.Stewart_at_[hidden])
Date: 2011-05-04 15:01:27


Matthew Chambers wrote:
> On 5/4/2011 1:18 PM, Stewart, Robert wrote:
>
> > try_convert(s, i) doesn't tell me whether s is being
> > converted to i's type or i to s's type.
>
> I don't think this is a problem in practice. C#'s TryParse has
> the same semantics, albeit you're forced to use the out
> keyword on the second argument, so perhaps that's not a fair
> comparison.

I don't think it's a fair comparison. I realize that folks can become accustomed to "try_convert" and learn to read it correctly, but why make it harder than it needs to be?

> > convert_cast(s, 17) has the same problem and breaks with the
> > new-style cast pattern.
>
> What is the breaking aspect?

New-style casts are of the form xxx_cast<T>(S). Thus, that has to be convert_cast<int>(s, 17) to fit.

> > The target type should be required in all cases, I suspect,
> > to make things clearer:
> >
> > try_convert_to<int>(s, i) clearly indicates that int is the
> > target type.
> >
> > convert_cast<int>(s, 17) is likewise better.
>
> Yes, but thanks to type inference users are free to write
> try_convert_to(s, i) instead and that's even worse than
> try_convert(s, i). :)

You can make the second argument non-deducible thus requiring the target type.

_____
Rob Stewart robert.stewart_at_[hidden]
Software Engineer using std::disclaimer;
Dev Tools & Components
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