Boost logo

Boost Users :

From: Christian Holmquist (c.holmquist_at_[hidden])
Date: 2008-05-16 20:42:07


2008/5/15 Ion Gaztañaga <igaztanaga_at_[hidden]>:
> 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#intrusive.value_traits.value_traits_example
>
> 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<node*>::get_pointer(n->next_); }

fails to compile due to n->next_ points to void* and not node*.
is it safe to use static_cast<node*>(n->next_) here?

>
> 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_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>


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