Boost logo

Boost :

Subject: Re: [boost] Is there any interest in a smart pointer facade class?
From: Krzysztof Czainski (1czajnik_at_[hidden])
Date: 2010-09-23 06:26:30


>
> Stefan Strasser <strasser_at_[hidden]>:
>
>> Recently I wrote two smart pointer classes, and felt the need for such a
>>>> class. I would like to write such a class, and if everything goes well,
>>>> perhaps add it to the Boost library.
>>>>
>>>
>>> It is supposed to be something like a more powerful intrusive_ptr?
>>> Can you give a usage example?
>>>
>>
>> I think the general idea is that this would be closer to a policy-based
>> smart pointer.
>>
>>
> I think it`s neither, but a CRTP class implementing the "pointer concept":
>
> struct my_ptr
> : smart_ptr_facade<my_ptr,...>{
> void set(T *rhs){ ptr=rhs; }
> T *get() const{ return ptr; }
> T *ptr;
> };
>
> => my_ptr has ptr semantics, including operator->, operator=, ...
>
> iterator_facade simplifies implementing iterators a lot, so could this
> class for pointers, and other facades, e.g. a vector_facade that implements
> the std::vector interface in terms of 3 or 4 user-supplied functions.
>

Yes, this is what I have in mind. In a simplified case, smart_ptr_facade
would require from my_ptr to provide a T* get() const;, and smart_ptr_facade
would provide operator*, operator->, operator==, operator< (in order to be
able to keep my_ptr in std::set).


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