|
Boost : |
Subject: Re: [boost] [review] Convert library
From: Vladimir Batov (vb.mail.247_at_[hidden])
Date: 2014-05-26 04:45:46
Roland Bock-2 wrote
> On 2014-05-26 01:25, Vladimir Batov wrote:
>> On 05/26/2014 12:59 AM, Thijs (M.A.) van den Berg wrote:
>>>> ...
>>> In C++11 has std::to_string and various flavours of stoul, stoull,
>>> stof. To me it makes more sense to use those for conversions between
>>> strings and integral types. Not just because of portability, but also
>>> because the interface is so simple.
>>>
>>> The value of convert to me seems to be more in the context of generic
>>> programming for a wide range of types with a uniform interface than
>>> for a simple interface for specific types for which there are already
>>> simple & standard alternatives.
>
> If the ability to be used in generic programming is the main value, then
> why are almost all the examples in the documentation string->int?
Well, clearly there are many reasons the docs are far from satisfactory...
You are not suggesting I spend weeks and weeks writing a bestseller just to
see all that rejected during the review and going to the rubbish bin, right?
So, I had to be mindful of that.
> And I was not (knowingly) suggesting API changes that reduce
> applicability for generic programming. In fact the ability to provide a
> callable to handle the conversion problems is much better suited than
> returning a default value and testing for it, IMHO. It is probably also
> performing better than throwing and catching exceptions.
I never thought of that. It sounds potentially interesting. I myself have no
experience of such deployment... Might be an overkill as so far "optional"
served my purposes well... It'd be easier to see real compilable code with
realistic examples... even if it is merely string->int. ;-)
Many suggestions might well be legit. I just can't possibly try coding all
the suggestions and dealing with and working around all potential issues by
myself. People should start contributing code.
We might start with
namespace boost
{
template<typename TypeOut, typename TypeIn, typename Converter>
optional<TypeOut>
convert(TypeIn const& value_in, Converter const& converter)
{
optional<TypeOut> result;
bool success = converter(value_in, result);
return success ? result : optional<TypeOut>();
}
template<typename TypeOut, typename Converter>
typename boost::conversion::algorithm_helper<TypeOut, Converter>
convert(Converter const& cnv)
{
return boost::conversion::algorithm_helper<TypeOut, Converter>(cnv);
}
}
So, for ex., the second convert() signature makes another 1-arg or 2-args
with the default, well, difficult. So, suggestions should be backed up by
how to actually achieve that in code. IMO. Just a potentially more effective
way to move forward.
-- View this message in context: http://boost.2283326.n4.nabble.com/review-Convert-library-tp4662821p4662881.html Sent from the Boost - Dev mailing list archive at Nabble.com.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk