
On Sun, Jan 27, 2013 at 9:39 AM, Ion Gaztañaga <igaztanaga@gmail.com> wrote:
El 27/01/2013 9:02, Matias Capeletto escribió:
Any attempt to use the offset of the member to get to the bimap class seems to be forbidden by the standard.
Yes, i'ts undefined behaviour in theory but not in practice. Boost.Intrusive has a useful function implemented for many compilers:
http://www.boost.org/doc/libs/1_52_0/boost/intrusive/parent_from_member.hpp
This. It is exactly what I was looking for yesterday... any chance to make this more visible? It is a very handy tool.
In your case the pointer to member value can be a compile-time constant (so &Bimap::left can be passed as a template parameter). This constant can be part of the type "left_map" or the compile-time pointer to member could be obtained by left_map by a metafunction, call parent_from_member passing "this" and the compile-time pointer to member value, obtaining the pointer to Bimap. This way you can avoid storing any pointer to Bimap into left_map.
Awesome. This is what I wanted to do, but I failed because the basic piece in the puzzle was missing. Thanks a lot, I didn't actually expected you to directly give it to me :) I will do the changes then so Bimap can be used with Interprocess allocators. Best regards Matias