
Hi,
I have a class X : public intrusive::list_base_hook<> and would like
to embed an additional member bool using the pointer_plus_bit.
Can this be achieved using the value_traits somehow, and have the list
working 'appropriately'?
example code:
#include

Christian Holmquist wrote:
Hi,
I have a class X : public intrusive::list_base_hook<> and would like to embed an additional member bool using the pointer_plus_bit.
Can this be achieved using the value_traits somehow, and have the list working 'appropriately'?
It can be achieved using value_traits. Just repeat the following example:
http://www.boost.org/doc/libs/1_35_0/doc/html/intrusive/value_traits.html#in...
but instead of defining this value_traits:
//Define the node traits. A single node_traits will be enough.
struct simple_node_traits
{
typedef simple_node node;
typedef node * node_ptr;
typedef const node * const_node_ptr;
static node *get_next(const node *n)
{ return n->next_; }
static void set_next(node *n, node *next)
{ n->next_ = next; }
// ...
};
Use this (supposing you want to embed the bit in the next pointer):
struct simple_node_traits
{
// ...
static node *get_next(const node *n)
{ return pointer_plus_bit

2008/5/15 Ion Gaztañaga
Christian Holmquist wrote:
Hi,
I have a class X : public intrusive::list_base_hook<> and would like to embed an additional member bool using the pointer_plus_bit.
Can this be achieved using the value_traits somehow, and have the list working 'appropriately'?
It can be achieved using value_traits. Just repeat the following example:
http://www.boost.org/doc/libs/1_35_0/doc/html/intrusive/value_traits.html#in...
but instead of defining this value_traits:
//Define the node traits. A single node_traits will be enough. struct simple_node_traits { typedef simple_node node; typedef node * node_ptr; typedef const node * const_node_ptr;
static node *get_next(const node *n) { return n->next_; } static void set_next(node *n, node *next) { n->next_ = next; } // ... };
Use this (supposing you want to embed the bit in the next pointer):
struct simple_node_traits { // ...
static node *get_next(const node *n) { return pointer_plus_bit
::get_pointer(n->next_); }
fails to compile due to n->next_ points to void* and not node*.
is it safe to use static_cast
FYI, I've just erased pointer_plus_bit.hpp and substituted it with a more generic pointer_plus_bits.hpp in Trunk. Now that I see that it's being used, I will need to provide backwards compatibility.
Ah well,it's not production code, so to me it's not important with backward compatibility. What I'm trying to do is to build a rollback mechanism that's more robust to exceptions due to failing memory allocations. since i'm doing some optimizations on the way, it just seemed as a good idea using the pointer_plus_bit feature. BI is a great lib by the way, the most inspiring addition to boost in 1.35 (although I've been using it from trunk for quite a while)!
I hope it works,
Ion _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

Christian Holmquist wrote:
fails to compile due to n->next_ points to void* and not node*. is it safe to use static_cast
(n->next_) here?
Sorry for the late reply. Why is n->next_ void*? It should be node*. Anyway, it would be safe to cast it. I attach here the legacy_value example but with an additional pointer_plus_bit trick.
BI is a great lib by the way, the most inspiring addition to boost in 1.35 (although I've been using it from trunk for quite a while)!
Thanks. If you have suggestions to improve the library, please let me know. Regards, Ion
participants (2)
-
Christian Holmquist
-
Ion Gaztañaga