Boost logo

Boost :

Subject: Re: [boost] [convert] Version in the Vault ready for review.
From: Stewart, Robert (Robert.Stewart_at_[hidden])
Date: 2009-03-24 10:36:38


On Sunday, March 01, 2009 7:02 PM
Vladimir.Batov_at_[hidden] wrote:
>
> it will be very useful to many developers (like me) not
> satisfied with
> lexical_cast and not (yet?) needing (or ready for) something
> like upcoming
> Spirit 2.0.

It does seem as if the middle ground would be useful.

> The current interface can be summed up as with as little as
>
> int i = convert<int>::from(str); // Throws on failure
> int i = convert<int>::from(str, -1); // Returns -1 on failure
>
> More details can be found in the accompanying document (just
> remember I am
> not Shakespeare).

There's room to improve the document, of course, but it is a very nice start. The result type's documentation is rather hidden, unfortunately, as it appears in the "Conversion-Failure Check" section. It should be prominently featured in one of the early sections.

I wonder about making the result returning interface explicit. That is, change the two interfaces shown above to return TypeOut and add a new call, something like the following, that returns a result instance:

   convert<int>::result result(convert<int>::try_from(str));

That eliminates all conversion, template deduction, and temporary object overhead issues for the first two calls. It also makes explicit when there's a result object.

I think the result type's conversion functions should throw an exception if !good(). Then, there's no need for your dothrow:

   convert<direction>::result result(convert<direction>::try_from(str, up_dir));
   direction dir(result); // throws exception if !result.good()

I dislike the nothrow idea since it implicitly provides a default of TypeOut() and there's already an interface for specifying a default. I'd rather folks wrote this:

   int i(convert<int>::from("not an int", 0));

than this:

   int i(convert<int>::from("not an int") >> boost::nothrow);

Your locale example fails to break a line:

   std::locale...// Windows-style locale d1 = convert...

which should be:

   std::locale new_locale(...); // Windows-style locale
   string d1 = convert<string>::from(d)

I have some issues with the implementation, but I'll defer to another time.

_____
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