Boost logo

Boost :

Subject: Re: [boost] [Review] Boost.Convert library, last day
From: Thomas Heller (thom.heller_at_[hidden])
Date: 2011-05-03 08:19:38


On Tue, May 3, 2011 at 12:41 PM, Vladimir Batov <vbatov_at_[hidden]> wrote:
>> Hartmut Kaiser <hartmut.kaiser <at> gmail.com> writes:
>> From reading the docs I came away puzzled. It was highly confusing to me to
>> have the convert::from<> return different things in different contexts.
>
> I was under impression that from the user perspective convert::from returns
> either the converted value or convert::result in all contexts. If users "really
> just want to do the conversion without spending much time reading the docs",
> then they'll use
>
> int i = convert<int>::from(string)
>
> as described in "Getting Started" without even knowing there is convert::result.
> Hardly puzzling and confusing.
>
>
>> As Thomas Heller pointed out, the existence of several default conversion
>> paths for the result type will (with high probability) create havoc for
>> users who really just want to do the conversion without spending much time
>> reading the docs.
<snip>
> Secondly, I am not sure about "existence of several default conversion paths for
> the result type". Again, the only types convert::from result is converted to are
> the Target type and the convert::result type. Both types are for different uses
> and are described in the docs. As for Thomas Heller's doomsday predictions, then
> it must be so if he says so. Or may be not. I do not see it that way anyway.

Sorry, this statement is wrong.
At the very least convert<T>::from returns exactly one thing which is
this converter thingy,
which is implicitly converted to either convert<T>::result or T. And
yes, this means that
the result is different based on the LHS of from, which is out of your
control and doomed to fail.
I wonder how much codes breaks by having this.
Consider the following example:

#include <boost/convert.hpp>
#include <string>

template <typename Char, typename Allocator>
void f(std::basic_string<Char, Allocator> string)
{}

int main()
{
    f(boost::convert<std::string>::from(123));
}

Which is not working because of this design flaw I constantly keep
mocking about.

Sorry to be the party pooper here. But your design is just confusing
and does not
really work like you are advertising it.


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