On 12/11/2013 10:34 PM, Gavin Lambert wrote:
On 12/12/2013 18:41, Quoth Peter Dimov:
<snip>
optional<> is cute because you can use if( auto x = try_lexical_cast<Out>(in) ), but not very convenient for the common case of try_lexical_cast(in1, out1) && try_lexical_cast(in2, out2).
Optional would work in that case too, eg:
if ((out1 = try_lexical_cast
(in1)) && (out2 = try_lexical_cast (in2))) { // both casts worked, do something with out1 and out2 }
<snip>
Also having to specify both types is more annoying than in the bool form, where the compiler can infer the parameters.
(I'm not really a fan of output parameters either, but c'est la vie.)
On the other hand, if it's not going to resemble "result = name<T>(source)" then it's not very cast-like, so the name seems a little odd now. But not enough to bother me much. :)
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. -- Michael Caisse ciere consulting ciere.com