Boost logo

Boost :

Subject: Re: [boost] [review] string convert
From: Vladimir Batov (vbatov_at_[hidden])
Date: 2011-05-05 18:46:58

> Stewart, Robert <Robert.Stewart <at>> writes:
> ...
> OK, that means we're down to the following now:
> 1 - default_value<T> customization point
> 2 - converter<T,S> customization point, main logic, functor
> 3 - T convert_cast<T,S>(S, formatting = none); can throw
> 4 - T convert_cast<T,S>(S, T, formatting = none)
> 5 - bool try_convert_to<T,S>(S, T &, formatting = none)
> ...

#3, #4. I do not think these can cause any controversy (although people who
refuse reading documentation might be surprised by #2 throwing or #3 not
throwing ;-) ).

#5 IMO can. It deploys the Pascal-style parameter passing and modifications. I
remember reading Stroustrup (I think) long time ago advising against passing
non-const references and I personally agree. That's due to potential confusion
and wrong expectations. I am not aware of any function in std and boost doing
that. Introducing such a precedent might be a hard-sell. Especially confusing
might be the fact that #4 does not modify the second parameter when #5 does. IMO

std::pair<T, bool> try_convert_to<T,S>(S, T, formatting = none)

is far less-controversial and even familiar (even though I personally dislike
std::pair due to unreadability of the resulting code sprinkled with faceless
first and second). Could I suggest convert_result as a more palatable
alternative? :-)

#1. I am personally not thrilled with default_value because it looks to me like
additional/avoidable/arbitrary piece of machinery that I have to implement to
incorporate my class into the framework. I've been managing without it. I'd
expect a new design not to force me to work harder.

Additional note. While you are on the interface, it probably needs to be kept in
mind that the current (as I understand it anyway) Boost policy is to avoid
introducing content directly in the boost namespace. Therefore, I presume fully
qualified it'll be something like

    int i = boost::conversion::convert_cast<int>(str);

So, maybe you might consider shortening it to something like

    int i = boost::convert::cast<int>(str);
    int i = boost::convert::to<int>(str);
    int i = boost::convert<int>::from(str); // Just kidding.

because otherwise the user will be implicitly forced to

    namespace cvt = boost::conversion;

or worse

    using namespace boost::conversion;


P.S. Posting this message via Gmane and it wants me to type 'grouchiness' to
confirm. How appropriate. LOL

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