Boost logo

Boost :

From: David B. Held (dheld_at_[hidden])
Date: 2002-08-12 14:22:34

"Philippe A. Bouchard" <philippeb_at_[hidden]> wrote in message
> > I'm not sure if this ptr<> type under discussion works this way, but in
> > general you can't conformingly use char* arithmetic with offsets to find
> > the sub-parts of non-POD types.
> The offsets are what static_cast<>s return. I cheat in the syntax when I
> say ptr_base<T, __false_type>::m_ptr is of type T *; it's just to make the
> code cleaner. understanding is that what Dave is talking about is exactly
what you are doing. After all, what is the business with
reinterpret_cast<char*> to do offset arithmetic?

> [...]
> template <typename T>
> struct ptr_block
> {
> int m_counter;
> int m_typeid;
> union
> {
> int;
> T;
> } m_object;
> };
> But operator new (size_t, rc_type const &) won't be easy to implement
> because size_t is not a compile-time constant.

I spent a while trying to see if it was possible to make this "invisible
wrapper", but ran into the same problem: you need to know the type,
because operator new only provides the size of the type as a runtime
value. I don't see how you can make a safe, conforming, portable count
wrapper without explicitly naming the type somewhere (like your original
placement new operator which passed in the type).


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