Boost logo

Boost :

Subject: Re: [boost] hex/unhex()?
From: Marshall Clow (mclow.lists_at_[hidden])
Date: 2011-11-02 15:32:51


On Nov 2, 2011, at 12:05 PM, Hartmut Kaiser wrote:

>> On Wed, Nov 2, 2011 at 1:12 PM, Hartmut Kaiser <hartmut.kaiser_at_[hidden]>
>> wrote:
>>> As I said, I wrote nonsense with regard to your question. Sorry for
>>> the confusion.
>>
>> When would generate() fail (return false)?
>
> Generate fails either if one of the used generators fail or if the
> underlying output iterator reports an error.
>
>> 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)

> 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;
        }

( I apologize for my idiosyncratic commenting style; I tend to figure everyone knows that Harry Harrison wrote a science fiction novel titled "Make Room! Make Room!" )
http://en.wikipedia.org/wiki/Make_Room!_Make_Room!

>
> But just to avoid confusion: what API are you looking for?
>
> std::string("61626f6465") --> std::string("abode")
>
> or rather:
>
> 0x61626f6465UL --> string("abode")
>
> (none of which can be easily done with Spirit, btw).

I think that he means the former.

-- 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