Boost logo

Boost :

Subject: Re: [boost] [review] string convert
From: Gordon Woodhull (gordon_at_[hidden])
Date: 2011-05-04 10:03:11

Hi Barend,

On May 4, 2011, at 9:46 AM, Barend Gehrels wrote:
> What about:
> int i = convert_cast<int>(s); // agreed
> optional<int> i = convert_cast<optional<int> >(s); // so optional indicated in template parameter as return type - as always
> int i = convert_cast<int>(s, 17); // agreed
> int i = convert_cast<int, throw_even_though_i_specified_a_failback_>(s, 17); // template parameter as optional one there
> optional<int> i ... (similar as other one with optional)
> pair<bool, int> i = convert_cast<pair<bool, int> >(s, 17); // pair indicated in template parameter
> This would never need any runtime parameter -> dispatching possible on compile-time -> no if's or cases necessary in implementation.
> And it always returns the type is in the (first) template parameter of convert.

Yeah, I like that better too. I just wasn't sure exactly how to implement that, since there's a template parameter OutType which is deduced from the argument. But I bet it's possible.

The last one points out another big difference between string-to-type and type-to-type: lexical_cast explicitly does not deal with complex types; otherwise that could be ambiguous. (Likewise someone could conceivably want to come up with a string representation of optional<T>.)

Either way, it's a job for someone with decent knowledge of Boost.Parameter (not me yet).


Boost list run by bdawes at, gregod at, cpdaniel at, john at