Boost logo

Boost :

Subject: Re: [boost] Conversion Library (Was: string convert)
From: Vicente BOTET (vicente.botet_at_[hidden])
Date: 2011-05-09 16:26:35

> Message du 09/05/11 21:26
> De : "Stewart, Robert"
> A : "'boost_at_[hidden]'"
> Copie à :
> Objet : Re: [boost] Conversion Library (Was: string convert)
> Vicente BOTET wrote:
> > De : "Stewart, Robert"
> > > Vicente BOTET wrote:
> > > > De : "Vladimir Batov"
> > > > > > From: "Stewart, Robert"
> > > > > > ...
> > > > > >> int i = boost::convert::to(str);
> > > > > >
> > > > > > That's good.
> > > > >
> > > > > How about we simplify the API down to just:
> > > > >
> > > > > T convert::to(S, boost::parameter-list);
> > > >
> > > > As Robert said, the name of a free function must be
> > > > readable when introducing a using namespace. Or is convert
> > > > a class?
> > >
> > > I think to("FF") is readable.
> >
> > Maybe, but the name doesn't scale. So I will prefer to preserve
> > the convert_to prefix.
> What do you mean it "doesn't scale?"

With a convert namespace we need to name your functions using prepositions. This limit a lot the choice of names. I will comment to your 9 interface later.

> > > > Vladimir, as I said you my library doesn't pretend to take
> > > > care of string conversions or conversions via a stream.
> > >
> > > I presume you mean string-to-string conversions when you
> > > write "string conversions" ...
> >
> > No, I meant conversion from string to a type and from a type to
> > a string.
> OK, but just after that you stated that your "library will specialize the convert_to function when one of the parameters is a string," which means it will handle that case, even if by using another library behind the scenes.

Yes, Boost.Conversion will have such overload using a specific library.

> > As I tried to explain in this and other posts, to take care of
> > a type-to-type conversion via a streams you needs to state
> > which manipulators are applied to the ostream and which one to
> > the istream. Your in_, out_ is first trial but must be
> > generalized to several manipulators.
> Yes, I just noticed the problem with multiple manipulators when replying above.
> It's also possible to punt on this issue by deciding that manipulators should only be supported for extractions, which is what Vladimir did. When one needs more control, one can use streams directly. Following that idea, then Vladimir's use of the extraction operator, which clearly indicated which part of the streaming was manipulated, was reasonable, if unusual as a function argument.

Yes. This could be a good compromise and the documentation should state clearly when the manipulators are applied.

> > The intent of Boost.Conversion is to support generic conversion
> > that can be specialized for specific types. One of the major
> > differences between Boost.Conversion and Boost.Convert, a part
> > from the interface is the customization point. In the case of
> > Boost.Convert it is the class convert and defaults conversion
> > using a iostream. Boost.Conversion is customized by overloading
> > the convert_to function, and by default uses the target
> > conversion operator from a source.
> I don't think it's necessary to continue to distinguish between the (now withdrawn) Boost.Convert and your Boost.Conversion library. Instead, we should focus on the future of conversion in Boost. For that, I see both approaches being appropriate, which is why I enumerated an API that includes the stream-based and non-stream-based interfaces. I thought the combination would support what you've been trying to develop and what Valdimir was trying to promote as a unified library for future review. Whether that library is yours or a collaboration is unimportant.

I'm not against a collaborative work. I think that both default behaviors are useful, and we can not have both without having two interfaces. I will push for a generic conversion interface based on Boost.Conversion default behavior and a string/stream specific based on Boost.Convert default behavior. We can have all in one library on on two, I have no problem with that. Note that there are other conversion in Boost, NumericConversion that offers specific and rich interface adapted to the kind of conversion that are addressed. I expect something similar for stream based conversion, a stream converter class and a streamable_cast function. Unfortunately I don't know which could be a good namespace to use for this specific conversions yet.

If my distinction is not enough clear and justified I could try to be more explicit.


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