|
Boost : |
Subject: Re: [boost] [convert] no-throw and fallback feature
From: Stewart, Robert (Robert.Stewart_at_[hidden])
Date: 2011-05-09 11:13:28
Vicente BOTET wrote:
> De : "Vladimir Batov"
> > From: "Vicente BOTET"
>
> > > I was thinking on the fallback feature a little bit more
> > > and I've the impression that we can get it for free. If we
> > > accept that we need a no-throw function such as
> > > try_convert_to that returns an optional Target we can have
> > > the fallback using the optional::get_value_or function
> > >
> > > auto r = try_convert_to(*int*)(s);
> > > int i = r.get_value_or(fallback);
> > > ...
The issue raised before is that "try" indicates a bool return type. Perhaps "maybe_as" would work?
auto o(convert::maybe_as<int>(s));
However, I do like the use of get_value_or().
> > > I don't know if it is worth adding a function that does all
> > > in one
> > >
> > > int i = convert_to_or(*int*)(s, fallback);
Don't forget the name when in its namespace and with the type specified clearly: convert::convert_to_or<int>(s, fallback). The repetition of "convert" is not ideal, but no different than "convert_cast" and stands up well with a using declaration or directive. Unfortunately, "to_or<int>" isn't right. It suggests something other than int is the desire.
I can't think of a good name, so I'm inclined to reject this function. If a better name arises, I can certainly see some value in including such a function, but at some point, there get to be too many ways to do a thing and that, itself, confuses matters. Thus, this function must be considered in light of the entire API.
_____
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