Boost logo

Boost :

Subject: Re: [boost] [review] string convert
From: Vicente BOTET (vicente.botet_at_[hidden])
Date: 2011-05-05 16:17:57


> Message du 05/05/11 19:48
> De : "Stewart, Robert"
> A : "'boost_at_[hidden]'"
> Copie à :
> Objet : Re: [boost] [review] string convert
>
> Vicente BOTET wrote:
> >
> > are we discussing here a generic interface from type-to-type or
> > one that uses an intermediary stream to make the conversion?
>
> I've been considering it the former. Why does using a stream to make the conversion affect that?

The fact that we want to add some formatting parameters, apply manipulators and so on to a generic interface disturb me.

> - T convert_cast(S, formatting = none); can throw
> - T convert_cast(S, T, formatting = none)
> - optional name_me_1(S, formatting = none)
> - optional name_me_1(S, T, formatting = none)
> - pair name_me_2(S, T, formatting = none)

I would prefer to don't pay for these defaulted parameters in the generic case.

Maybe I'm wrong, but the manipulators are only useful when converting from a string or to a string. If this is the case, all the stream stuff should be moved to a string conversion interface. I would even prefer that the stream part stay away and independent. In another post I proposed to use an istream proxy when converting from a string to a type

as_istream(str) >> std::hex >> i;

For conversions from a type to a string, we can use an ostream proxy, which is implicitly convertible to string.

string str = as_ostream() << std::hex << i;

Best,
Vicente


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