|
Boost : |
Subject: Re: [boost] [review] string convert
From: Stewart, Robert (Robert.Stewart_at_[hidden])
Date: 2011-05-09 10:21:02
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.
> > Then we specialize it for convert::result type so that
> >
> > convert::result convert::to>(S, boost::parameter-list);
>
> I don't see any inconvenient in introducing a special overload.
I presume you mean that such an overload could be convenient for someone like Vladimir and would not cause a problem for those preferring other approaches.
> I guess a user needs to call it as follows
>
> convert::result r = convert::to>(S, boost::parameter-list);
It's hard to say as that was munged.
> > // 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?
> int i = convert::to(aValue, (format_ = std::hex))
>
> Would the std::hex be applied to the output or the input
> stream?
>
> ios << aValue;
> ios >> std::hex >> i;
>
> or
>
> ios << std::hex << aValue;
> ios >> i;
>
> Are these equivalent?
>
> I think the interface must state clearly when these
> manipulators are applied.
I think it should be something like this:
convert::as<int>(aValue, (in_ = std::hex, out_ = std::hex));
> 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" ...
> My library will specialize the convert_to function when one of
> the parameters is a string and call the best library providing
> it.
...because of that.
_____
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