|
Boost : |
Subject: Re: [boost] [convert] no-throw and fallback feature
From: Vladimir Batov (vbatov_at_[hidden])
Date: 2011-05-08 06:54:33
> From: "Vicente BOTET" <vicente.botet_at_[hidden]>
> Hi,
>
> 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);
> ...
> I don't know if it is worth adding a function that does all in one
>
> int i = convert_to_or(*int*)(s, fallback);
Vicente,
Your suggestion of deploying get_value_or() indeed provides the fallback
feature quite easily. However, the original 2 args function
Target v = convert_to_or<Target>(s, fallback);
does that and more. :-) It does not require the Target type to be
DefaultConstructible. Something dear to my heart. :-)
V.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk