Subject: Re: [boost] Conversion Library (Was: string convert)
From: Stewart, Robert (Robert.Stewart_at_[hidden])
Date: 2011-05-09 15:25:13
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<int>("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?"
> > > > // The predictable. Throws on failure
> > > > int i = convert::to("FF", (format_ = std::hex))
> > >
> > > Would this overload exist only when the source parameter is
> > > string? Sorry, but I don't see how it could be used for
> > > type-to-type conversions
> > If it supports type-to-type conversion via an I/O stream, it
> > would apply, wouldn't it?
> It would, but I will prefer to use the stream syntax for that
> kind of conversion instead of using additional parameters.
> > > I think the interface must state clearly when these
> > > manipulators are applied.
> > I think it should be something like this:
> > convert::as(aValue, (in_ = std::hex, out_ = std::hex));
> Hmmm, I don't tisk this is enough readable.
Perhaps not, especially when one might wish to supply multiple manipulators.
> > > 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.
> 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.
> 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.
Please comment on my 9 point API list, particularly if I've missed something you think is important.
Rob Stewart robert.stewart_at_[hidden]
Software Engineer using std::disclaimer;
Dev Tools & Components
Susquehanna International Group, LLP http://www.sig.com
IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk