Boost logo

Boost :

Subject: Re: [boost] [review] string convert
From: Stewart, Robert (Robert.Stewart_at_[hidden])
Date: 2011-05-05 12:57:20


Vicente BOTET wrote:
> De : "Vladimir Batov"
> > "Stewart, Robert" wrote
>
> > Maybe to avoid the temptation of pairing up we could simplify
> > (at least from the user perspectives) down to:
> >
> > 1. T convert_cast(S)
> > 2. T convert_cast(S, T, throw_t =nothrow)
>
> I don't see why (2) the user could want to throw when is giving
> a fallback. So the throw_t =nothrow is not needed.

That's the non-DefaultConstructible, no-sentinel use case:

struct example
{
   example(int);
};

To get an exception on conversion failure, one writes:

example const e(convert_cast<example>("1")); // exception

However, without the default_value CP, that fails because example is non-DefaultConstructible.

One can avoid the exception by providing a fallback value:

example const e(convert_cast<example>("1", 3)); // no exception

(I'm assuming the fallback value can be of type U implicitly convertible to T.)

In that case, e == example(3).

But if one wants an exception to indicate conversion failure, an initial value is needed and the desire for an exception must be noted:

example const e(convert_cast<example>("1", 3, throw_)); // exception

Obviously, with your default_value CP, the second argument isn't needed for the last use case:

template <>
default_value<example>
{
   static example
   apply()
   {
      return example(3);
   }
};

example const e(convert_cast<example>("1")); // exception

HTH,

_____
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