Boost logo

Boost :

Subject: Re: [boost] [review] string convert
From: Matthew Chambers (matt.chambers42_at_[hidden])
Date: 2011-05-04 12:03:29


On 5/4/2011 10:51 AM, Gordon Woodhull wrote:
>> (I'm confused by the following, which look pointless; have I missed something?)
>
> I think you have. But I'll go through it one last time.
>
>>> int i = convert_cast<int>(s, 17, throw_even_though_i_specified_a_failback_);
>>> optional<int> i = convert_cast<int>(s, 17, use_optional_instead_of_throwing_);
>
> These are for nondefaultable types. I probably shouldn't have used int in my example; what's a well-known example of a nondefaultable type? You must supply an initial value, but you don't want to use it.
>
> Pretty rare, but if you're in that case, you'll be annoyed if you don't have these. That's why they're the ones which still take ugly extra tags even after either Barend's or Matt's simplifications.

I understand these cases and indeed illustration would be much clearer with a non-default type.
Honestly I think it's a rare enough use case that it shouldn't pollute the general interface.
Separate names would perhaps be more appropriate like:

non_defaultable_type i = no_default_convert_cast<non_defaultable_type>(s, 17);
optional<non_defaultable_type> i = try_no_default_convert_cast<non_defaultable_type>(s, 17);

I don't really like it either. I haven't yet seen a tasteful way to support these non-defaultable types.

-Matt


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