Boost logo

Boost :

From: Eric Niebler (eric_at_[hidden])
Date: 2005-03-14 15:06:50

Eric Niebler wrote:
> Peter Dimov wrote:
>> Eric Niebler wrote:
>>>> +// Borland doesn't like casting an array reference to a char
>>>> reference +// but thes overloads work around the problem.
>>>> +template<typename T,std::size_t N>
>>>> +T (*addressof(T (&t)[N]))[N]
>>>> +{
>>>> + return reinterpret_cast<T(*)[N]>(&t);
>>>> +}
>> Why are you reinterpret_casting &t to itself? Is this a Borland
>> problem as well?
> Russell added the reinterpret_casts to my patch. Russell, can you comment?

And here is Russell's reply. Looks like it's necessary.

Truth is, I'm not sure why I reinterpret_cast t to its own type, but
without it (i.e just return &t as Eric's original solution), FOREACH
still gives these errors

[C++] main.cpp(1):
[C++ Error] addressof.hpp(42): E2034 Cannot convert 'int *' to 'int ( *)[5]'
[C++ Error] addressof.hpp(49): E2034 Cannot convert 'const int *' to
'int ( *) const[5]'

As far as I can tell, the reinterpret_cast I've added isn't casting t to
itself, as t is a T(&)[N], I'm reinterpret_casting it to the function
return type, T(*)[N].

If this is incorrect, I can try other solutions if anyone has any
suggestions, but just return &t doesn't work with bcc32-5.6.4.

Eric Niebler
Boost Consulting

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