Boost logo

Boost :

Subject: Re: [boost] [convert] Version in the Vault ready for review.
From: Gottlob Frege (gottlobfrege_at_[hidden])
Date: 2009-04-09 11:04:38

On Wed, Apr 8, 2009 at 4:59 PM, Stewart, Robert <Robert.Stewart_at_[hidden]> wrote:
> On Monday, April 06, 2009 1:23 PM
> Gottlob Frege wrote:
>> A)
>> int i = convert<int>::from(str);   // throws if necessary
>> B)
>> int i = convert<int>::from(str, 0);   // default supplied so no throw

Let's split case 'C' into 'C' and 'D':

>> C)
>> convert<int>::result res;
>> int i = convert<int>::from(str, res);    // no throw - error/status


>> result returned in 'res'
>> int i =  convert<int>::from(str, 0, res);   // default + status

> I've been pondering this suggestion.  I like that from() always returns a value and that the converted value isn't part of the result object when using one.  I also like the clarity of using overloading to select the result-producing calls.  I don't care much for having to default construct the result to pass it to the call, however, but it simplifies the reasoning needed to determine whether an exception will be thrown.

Case 'C' is problematic - let's get rid of it:
       i = from(str, res);
is difficult when the type is NOT default constructible. So let's get
rid of it.
If you want a status result, supply a default (case D):
      i = from(str, 0, res);

*Alternatively*, since we know the type, we could probably use some
type-inference tricks to only allow case C to compile when the type is
default constructible:

    int i = convert<int>::from(str, res); // OK

- compiles as int is default constructible.
- does NOT throw as you get status back in res.

   class C { public: C(int, int); };
   C c = convert<int>::from(str, res); // does NOT compile
   C c = convert<int>::from(str, C(1, 2), res); // default required



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