Boost logo

Boost :

From: David B. Held (dheld_at_[hidden])
Date: 2002-08-20 13:41:30

"Philippe A. Bouchard" <philippeb_at_[hidden]> wrote in message
> - operator +/- (..., offset) now returns char * (less error-prone);
> - ptr_base<T, __false_type>::m_ptr is of type void * to allow perfect
> copies;

Not sure what this means.

> - all reinterpret_cast<>s are justified.

I don't think they need to be justified. It's perfectly clear why they are
used. They need to be *tested* to assure that they work properly on
all intended platforms (if the only intended platform is gcc 2.9x, then
say so, but don't say that it's 98% portable when you've only tested
on one platform).

I believe that your implementation of pos() is not valid C++ code:

template <class C, typename T>
    inline offset pos(T C::* p)
        return size_t(& (reinterpret_cast<C *>(0)->*p));

In particular, I believe it is invalid to dereference a null pointer, even
just to compute a member offset. I believe there is an offsetof macro
that does this in a correct way. Try:

#include <cstddef>

member_offset = offsetof(C, p);

Finally, do you have a problem with Larry's implementation of the
conversion c'tor?

template <typename U>
    ptr_base(ptr_base<U, __false_type> const & a_p) : m_ptr(a_p.share())
        if (s_offset.size() <= ptr_base<U, __false_type>::s_id)
            s_offset.resize(ptr_base<U, __false_type>::s_id + 1);

        char c[sizeof(U)];
        U* u(reinterpret_cast<U*>(c));
        T * p(u);
        s_offset[ptr_base<U, __false_type>::s_id] = size_t(p - offset(u));

It seems like it ought to be just as fast, and avoids the ugly pU(1)
construct (which I think happens to stink ;).


Boost list run by bdawes at, gregod at, cpdaniel at, john at