First, thanks!

David B. Held wrote:
> "Philippe A. Bouchard" <[EMAIL PROTECTED]> wrote in message
> b1tvp7$da3$[EMAIL PROTECTED]">news:b1tvp7$da3$[EMAIL PROTECTED]...

[...]

> Here's the "raw pointer c'tor":
>
>         template <typename U>
>         smart_ptr(U const& p)
>         : base_type(p, detail::init_first_tag())
>         { checking_policy::on_init(get_impl(*this)); }

Great to know there is now some pre-condition like checking_policy.

> Here's what your storage_policy might look like:
>
>     template <typename T>
>     class shifted_storage
>     {
>     public:
>         typedef shifted_object<T>*  stored_type;        // the type
> of the pointee_
>         typedef shifted_object<T const>*    const_stored_type;  //

One little thing: the pointee_ must be of type T * because of polymorphic
objects with multiple inheritance that keep shifting the pointer implicitly;
and to have a fast operator *.

>         object typedef T*          pointer_type;       // type
> returned by
> operator->
>         typedef T const*    const_pointer_type;

[...]

>         shifted_storage(pointer_type p)
>         : pointee_(static_cast<stored_type>(
>             static_cast<char*>(static_cast<void*>(p)) -
> sizeof(shifted_header)
>         ))
>         { }
>         // I think the arithmetic above is valid, because we're
>         dealing with // POD types, but IANALL, so take it with a
> grain of salt

Maybe it would be better to use 'shifted_address<size_t, size_t>::get()'
instead of 'static_cast<void*>(p)) - sizeof(shifted_header)' because
pointer_type does not necessarily point to the beginning of the object.

[...]

>     public:
>         friend inline pointer_type get_impl(shifted_storage const& sp)
>         { return &sp.pointee_->m_object; }
>
>         friend inline stored_type& get_impl_ref(shifted_storage& sp)
>         { return sp.pointee_; }

[...]

>     protected:
>         void release()
>         { pointee_ = 0; }
>
>         static stored_type default_value()
>         { return 0; }
>
>     private:
>         stored_type pointee_;
>
>     public:
>         BOOST_MPL_AUX_LAMBDA_SUPPORT(1, shifted_storage, (T))
>     };
>
> #ifdef __BORLANDC__
>     namespace mpl { BOOST_MPL_AUX_VOID_SPEC(1, shifted_storage) }
> #endif
>
> Dave

It's interesting to know that some checking_policy is provided.  It kind of
open doors to test the validity of the address at run-time.  Conversions
will be interesting also.



Philippe A. Bouchard





_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Reply via email to