Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2003-09-30 17:07:25


"Philippe A. Bouchard" <philippe_at_[hidden]> writes:

> 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);

Why is that good?

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com

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