|
Boost : |
Subject: Re: [boost] hex/unhex()?
From: Marshall Clow (mclow.lists_at_[hidden])
Date: 2011-11-02 16:43:09
On Nov 2, 2011, at 1:32 PM, Olaf van der Spek wrote:
> On Wed, Nov 2, 2011 at 8:32 PM, Marshall Clow <mclow.lists_at_[hidden]> wrote:
>>>> AFAIK to hex can't fail and in that case a variant that returns
>>>> std::string would be nicer.
>>
>> Sure it can.
>> The container that you are putting it into (std::string, say) could fail on memory allocation.
>> Just because it's really unlikely doesn't mean it can't happen.
>> (If you don't want to worry about it, then don't)
>
> Right, but wouldn't the exception just be propagated to the caller?
Sure - but if you believe that it could happen, then you should handle it.
If you think it won't ever happen, then don't.
>>> Doesn't it 'return' a std::string? If you dislike the current API a small
>>> wrapper function can easily handle that.
>>
>> Right - like this (for example):
>>
>> std::string hexS ( const std::string &input ) {
>> std::string result;
>> result.reserve ( input.size () * 2 ); // Harry Harrison
>> hex ( input, std::back_inserter ( result ));
>> return result;
>> }
>
> Yep, except that it should not be limited to std::string.
Goodness, you're picky.
First you say it needs to "just work on std::string", then you say it shouldn't be limited to std::string.
The iterator-based versions (whose prototypes I posted earlier) work on just about everything.
-- Marshall
Marshall Clow Idio Software <mailto:mclow.lists_at_[hidden]>
A.D. 1517: Martin Luther nails his 95 Theses to the church door and is promptly moderated down to (-1, Flamebait).
-- Yu Suzuki
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk