Boost logo

Boost :

Subject: Re: [boost] [gsoc] Pointer Plus Bits Behavior and Interface
From: Stewart, Robert (Robert.Stewart_at_[hidden])
Date: 2010-07-16 07:36:28


vicente.botet wrote:
> From: "Stewart, Robert" <Robert.Stewart_at_[hidden]>
>
> > Now, we could rethink the extrinsic view approach and instead
> > provide two accessors that return a smart pointer and a
> > payload object. That is, one calls a member function to get
> > the equivalent of Joaquin's pb:
> >
> > x.pb.ptr->foo() vs x.pointer()->foo()
> > x.pb.b vs x.bits()
>
> The bitfield_tuple class will be extended so the user is able
> to pack a pointer and some bitfields as follows
>
> struct a;
> struct b;
> struct c;
> typedef bitfield_tuple<
> pointer<foo, a>,
> flag<b>,
> flag<c>
> > foo_bool_bool;
>
> This can be used as
>
> foo_bool_bool fbb = make_bitfield_tuple<foo_bool_bool>(new
> foo(), true, false);
>
> get<a>(fbb)->foo_member
>
> if (get<a>(fbb)!=0) {}
>
> This design gives the separated view of each one of the
> components as suggested by Joaquin, Stefan.

Nice.

> The question was if we stop there or we provide some kind of
> smart pointer that stores a pointer but that allows to use
> the spare bits to store other info. Brian suggested me to
> rename pointer_plus_bits something like twiddling_ptr or
> stuffling_ptr (Brian could you recall the term you used).
> This class would have as major interface the interface of a
> smart pointer, but would have also the interface as it was a
> bitfield_tuple. We can consider that
>
> twiddling_ptr<foo, flag<b>, flag<c> >
>
> is
>
> bitfield_tuple<
> pointer<T, ptr_tag>,
> flag<b>,
> flag<c>
> >
>
> adding the smart pointer operations.

That's the wrong place to add the pointer knowledge.

> As the bitfield_tuple, can not have more than a pointer (at
> least not for now), we could think in providing a specific
> accessor so no tag is needed
>
> bitfield_tuple<
> pointer<T>,
> flag<b>,
> flag<c>
> > pbb;
>
> pbb.pointer()->
>
> This function could be disabled (using SFINAE) if the
> bitfield_tuple has no pointer member.

That's an interesting approach. However, a wrapper of bitfield_tuple could determine how (and how many of) the extra bits are used and provide an accessor or operators for pointer use. That is, one wrapper might implement the smart pointer interface with accessors for the bits, while another might provide pointer() to access the pointer.

_____
Rob Stewart robert.stewart_at_[hidden]
Software Engineer, Core Software using std::disclaimer;
Susquehanna International Group, LLP http://www.sig.com

IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.


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