Boost logo

Boost :

Subject: Re: [boost] [review] string convert
From: Stewart, Robert (Robert.Stewart_at_[hidden])
Date: 2011-05-03 14:26:08


Vicente BOTET wrote:

Vicente, you really need to try a different mail client or else use it differently. The angle brackets for your template parameter and argument lists are being dropped.

> In order to take care of types without default constructor I
> see several options:
>
> template
> Target convert_to(Source const& s, Target const& t);
>
> template
> Target& assign_to(Target& t, Source const& s);
>
> template
> struct default_value
> {
> T apply() { return T(); }
> };
>
> The user will need to specialize this function for types that
> are not default constructible.
>
> This meta-function will be used instead of declaring a
> defaulted variable in the string conversion function.
>
> T v(default_value::apply());

None of those options work for types without a default constructor *and* without a sentinel value.

> As a user I would prefer the second one

The name "assign_to" just seems odd to me. The problem is that assigning "123" to an int is the wrong idea. It isn't assignment but conversion. I understand you wanted a different name to account for the different behavior, but that's not it.

> In order to take care of no throwing semantics, I will choose
> to add a convert_to overloading with a error code parameter,
> not throwing without not knowing why fails seems too specific
> to me.
>
> template
> Target convert_to(Source const& s, err_code& ec);

That's fine if there are specific errors to report other than "bad input." The err_code type should also support a safe-bool conversion.

> But I could understand there are some cases where the single
> reason is a bad format. We could also use the no_throw_t as
> additional parameter, but in this case the return type should
> allow to know if the operation has succeed or not. If we follow
> the C++ standard interface the use of pair seems to be the more
> appropriated.
>
> template
> pair convert_to(Source const& s, no_thow_t const&);

This was already rejected by several folks. Allow me to add my dislike for it.

> Note also that there could be some conversions that could
> transport whether the conversion succeeds or not

I can't quite parse that.

> optional t = convert_to >(s);

Something important was lost in your message.

> or a Robert suggested overload the pointer to a source
>
> template
> optional convert_to(Source const* s);

Unfortunately, I realized that wouldn't work well for string literals, for example.

_____
Rob Stewart robert.stewart_at_[hidden]
Software Engineer using std::disclaimer;
Dev Tools & Components
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