|
Boost Users : |
From: Zeljko Vrba (zvrba_at_[hidden])
Date: 2007-06-05 11:13:19
On Tue, Jun 05, 2007 at 04:35:16PM +0200, Ion Gaztañaga wrote:
>
> I just realized about this just after sending my previous mail. SunCC
> seems to use the classical cfront approach encoding a pointer to member
> as offset + 1. So it seems that parent_from_member detection is correct
> for SunCC.
>
Slightly off-topic, but: do you know the background WHY did they decide
to implement ptr-to-member as offset +1?
> boost/intrusive/detail/utilities.hpp in the member_value_traits class:
>
> static node_ptr to_node_ptr(reference value)
> {
> MemberHookType* result = &(value.*P);
> return result->to_node_ptr();
> }
>
I have tracked the conversion to here myself. I wondered whether this was
a compiler bug, but the following simple program works, ie. it does NOT
raise an assertion failure. I hope I managed to reproduce correctly the
usage pattern of ptr-to-member..
==
#include <assert.h>
struct A {
int x;
int y;
};
template<typename T, int T::*P>
struct setter {
static void f(T &t)
{
t.*P = 42;
}
};
int main(void)
{
A a;
a.x = a.y = 0;
assert((a.x == 0) && (a.y == 0));
setter<A, &A::y>::f(a);
assert((a.x == 0) && (a.y == 42));
setter<A, &A::x>::f(a);
assert((a.x == 42) && (a.y == 42));
return 0;
}
==
I'm kinda clueless as how to proceed from here. If it _is_ a genuine compiler
bug, we need a more complex test-case, which I'm unable to produce myself
(as I don't know how many intermediate instantiation steps there are in
the intrusive library).
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net