Boost logo

Boost :

Subject: Re: [boost] [interprocess] [bimap] Using raw pointers
From: Ion Gaztañaga (igaztanaga_at_[hidden])
Date: 2013-01-27 03:39:57


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

It's similar to a "downcast" but using members. Like "static_cast", it
does not work with virtual inheritance.

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.

Best,

Ion


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk