Boost logo

Boost :

Subject: Re: [boost] [convert] Version in the Vault ready for review.
From: Stewart, Robert (Robert.Stewart_at_[hidden])
Date: 2009-04-09 11:44:07


On Thursday, April 09, 2009 11:05 AM
Gottlob Frege wrote:
> 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 => 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
>
> D)
>
> >> result returned in 'res'
> >> int i = convert<int>::from(str, 0, res); // default + status
>
> 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:
>
> C1:
> int i = convert<int>::from(str, res); // OK
>
> - compiles as int is default constructible.
> - does NOT throw as you get status back in res.
>
> C2:
> 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

I'm in favor of keeping C) for symmetry. Since from() is a member function of a class template, it will not be instantiated unless used and, if used, it will fail to compile. Thus, employing Boost.ConceptCheck can produce a helpful error message to explain the problem.

_____
Rob Stewart robert.stewart_at_[hidden]
Software Engineer, Core Software using std::disclaimer;
Susquehanna International Group, LLP http://www.sig.com

IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.


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