Subject: Re: [boost] [conversion] try_lexical_cast and 200$
From: Gavin Lambert (gavinl_at_[hidden])
Date: 2013-12-12 02:10:25
On 12/12/2013 19:45, Quoth Michael Caisse:
> On 12/11/2013 10:34 PM, Gavin Lambert wrote:
>> Also having to specify both types is more annoying than in the bool
>> form, where the compiler can infer the parameters.
> You still just write:
> out1 = try_lexical_cast<T1>(in1)
> where the type of out1 is optional<T1> and the type of in1 is deduced.
I thought that ought to work, but I wrote a toy example and it didn't,
which is why I phrased it like that. Thinking back on it now I realise
what the problem was:
On 12/12/2013 18:41, Quoth Peter Dimov:
> Antony Polukhin wrote:
>> And if yes, what signature is preffered:
>> bool try_lexical_cast<Out, In>(Out&, const In&)
>> bool try_lexical_cast<Out, In>(const In&, Out&)
>> boost::optional<Out> try_lexical_cast<Out, In>(const In&)
> bool try_lexical_cast<In, Out>(const In&, Out&), I'd say.
Inference requires the <Out, In> ordering of template parameters (for
the optional version; it doesn't matter for the bool version). I had
them wrong when testing my toy.
My apologies for the noise.