Boost logo

Boost :

Subject: Re: [boost] [lexical_cast] Error casting void* to std::string
From: GMan (gmannickg_at_[hidden])
Date: 2011-11-23 19:08:06

On Wed, Nov 23, 2011 at 2:18 PM, Marshall Clow <mclow.lists_at_[hidden]>wrote:

> gcc 4.2.1 complains about this code, too:
> [...]
> Interestingly enough, clang doesn't mind it at all.

Ah yes, I see it now; should have before. In the case where Source is
void*, removed_ptr_t is void, and sizeof(void) is an error. (Perhaps clang
allows sizeof(void) as an extension?)

In any case, it seems a specialization/branch is needed for void*, but I
don't know the internals of lexical_cast well enough to know what the
result of that branch should be in this situation.

> What do you expect this code to do?

In my mind, lexical_cast is a nicer/safer/optimized version of a
std::stringstream cast. That is, in the case of no errors
lexical_cast<R>(x) has the same result as:

template <typename S>
R lexical_cast_exposition(const S& x) // assumes no errors
    std::stringstream ss;
    ss << x;

    R y;
    ss >> y;

   return y;

In my case, S is void* and R is std::string (and it uses ostream&
operator<<(const void*)).

GMan, Nick Gorski

Boost list run by bdawes at, gregod at, cpdaniel at, john at