Boost logo

Boost :

From: Beman Dawes (bdawes_at_[hidden])
Date: 2003-02-02 15:48:16


At 07:49 PM 1/30/2003, David B. Held wrote:

>"Beman Dawes" <bdawes_at_[hidden]> wrote in message
>news:4.3.2.7.2.20030130190434.022c2af8_at_mailhost.esva.net...
>> [...]
>> The use case I was interested in was an array being managed,
>> and the conversion to T* also being present.
>
>Ouch! I haven't worked through the details, but I have a gut level
>feeling that it's going to be nasty.
>
>> The difficulty, of course, is that the public interface has to change
>> based on the interaction between two policies. The problem didn't
>> arise in the original Loki::smart_ptr because it didn't allow arrays.
>
>Well, since array support has been mandated, I will face this issue
>eventually. When it crops up, rest assured you will probably hear
>from me. ;)

Because the solution affects how you structure a PBSP's inheritance, it
probably needs to be dealt with early in the design.

Here is the problem:

    If T is not an array, the interface must supply:

        T& operator*() const;
        T* operator->() const;

    If T is an array && conversion to T* is not desired, the
    interface must supply:

        T& operator[](size_t i) const;

    If conversion to T* is desired, the interface must supply:

        operator T*() const;

In other words, there are four interface combinations:

    When T is not an array && conversion to T* is not desired:

        T& operator*() const;
        T* operator->() const;

    When T is not an array && conversion to T* is desired:

        T& operator*() const;
        T* operator->() const;
        operator T*() const;

    When T is an array && conversion to T* is not desired:

        T& operator[](size_t i) const;

    When T is an array && conversion to T* is desired:

        operator T*() const;

HTH,

--Beman

     


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