Boost logo

Boost :

Subject: [boost] [convert] no-throw and fallback feature
From: Vicente BOTET (vicente.botet_at_[hidden])
Date: 2011-05-08 05:45:59


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);

or just

int i = try_convert_to(*int*)(s).get_value_or(fallback);

or

int i = get_value_or(try_convert_to(*int*)(s), 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);

Best,
Vicente


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