Boost logo

Boost :

Subject: [boost] Convert library to use Boost.Optional?
From: Andrzej Krzemienski (akrzemi1_at_[hidden])
Date: 2014-05-21 05:45:45

Hi Vladimir,
I have just made one observation regarding the return type. Now, that you
are using your custom boost::convert<TypeOut>::result, you can choose what
exception type you want to throw from function value(). Your current choice
is probably not the best one because you cannot distinguish with a type
alone between the failure to convert form string to T from any other std::
invalid_argument thrown in a big program. I recommend that you invent your
own type that can derive from
std::invalid_argument. This will work fine, but the problem will reappear
when you switch to boost::optional, because the latter is a general purpose
library and it does not know the history behind the failure. It will throw
a generic "empty optional" error rather than something speciffic to
conversions. So, there is one disadvantage of using boost::optional. I do
not know how important you consider it to be. If it is a deal, and you do
not want to invent your own return type. Perhas you could use 'Expected': It is proposed for Standard
C++, And I think some work is being done to include it into Boost too. It
is similar to Boost.Optional, but conveys more information about the reason
of failure. Might be worth considering.


Boost list run by bdawes at, gregod at, cpdaniel at, john at