Boost logo

Boost :

Subject: Re: [boost] [convert] no-throw and fallback feature
From: Vicente BOTET (vicente.botet_at_[hidden])
Date: 2011-05-08 07:41:49


> Message du 08/05/11 12:57
> De : "Vladimir Batov"
> A : boost_at_[hidden]
> Copie à :
> Objet : Re: [boost] [convert] no-throw and fallback feature
>
> > From: "Vicente BOTET"
> > Hi,
> >
> > I was thinking on the fallback feature a little bit more and I've the
> > impression that we can get it for free. If we accept that we need a
> > no-throw
> > function such as try_convert_to that returns an optional Target we can
> > have
> > the fallback using the optional::get_value_or function
> >
> > auto r = try_convert_to(*int*)(s);
> > int i = r.get_value_or(fallback);
> > ...
> > I don't know if it is worth adding a function that does all in one
> >
> > int i = convert_to_or(*int*)(s, fallback);
>
> Vicente,
>
> Your suggestion of deploying get_value_or() indeed provides the fallback
> feature quite easily. However, the original 2 args function
>
> Target v = convert_to_or(s, fallback);
>
> does that and more. :-) It does not require the Target type to be
> DefaultConstructible. Something dear to my heart. :-)

You are right, convert_to_or can be specialized for non default constructible types and could even perform better. What others think of the naming and signatures?

Best,
Vicente


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