|
Boost : |
From: Philippe A. Bouchard (philippe_at_[hidden])
Date: 2003-09-30 16:27:52
David Abrahams wrote:
[...]
> No, I was suggesting making the constructor private, making
> make_shifted_ptr a friend, and have make_shifted_ptr<T>(...) return a
> shifted_ptr<T>.
>
> Your approach seems very complicated. Is there a reason to do it
> that way?
make_shifted_ptr<T>() is the best solution, but it would be possible also to
create a new type explicitly allocated with the standard operator new, if we
are to use infinite overloads:
template <typename T>
class stype
{
shifted_header h;
char s[sizeof(T)];
public:
stype();
template<class Arg1>
stype(Arg1 &);
template<class Arg1, class Arg2>
stype(Arg1 &, Arg2 &);
...
};
template<typename T>
class shifted_ptr
{
public:
template <typename U>
shifted_ptr(shifted_ptr::details::stype<U> &);
...
};
This way it would be possible to force the following syntax:
shifted_ptr<int> p = new stype<int>(9);
Eventually it would be possible to implement something similar to the
garbage collector's black listing of pointers. It uses fast heap page
detection to isolate pointer allocations that differs:
http://www.hpl.hp.com/personal/Hans_Boehm/gc/gcdescr.html
Philippe
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk