Boost logo

Boost :

From: David B. Held (dheld_at_[hidden])
Date: 2003-02-02 22:00:27


"Beman Dawes" <bdawes_at_[hidden]> wrote in message
news:4.3.2.7.2.20030202193833.015d2500_at_mailhost.esva.net...
> At 04:18 PM 2/2/2003, David Abrahams wrote:
> >[...]
> >Why can't operator T*() and operator[](size_t) coexist?
>
> They are ambiguous, or at least GCC, Intel, and Microsoft compilers
> think so, although Borland only warns and Metrowerks accepts.

I see. That's what Comeau says too. I was testing it with an int
parameter, in which case it compiles.

> [...]
> The only way to get it to work with both VC++ 6.0 and 7.0 is to
> remove the operator T*().

Ok. I think this is possible without changing the inheritance hierarchy,
though. We can disable operator T* using the disallow_conversion
policy, and I suspect we can disable operator[] by tweaking the
argument type like so (pseudocode):

class smart_ptr
{
private:
    class disable_index { };
    typedef if_<
        array_policy && disallow_conversion,
        std::size_t,
        disable_index const&
>::type index_arg;

    // ...

public:
    T& operator[](index_arg)
    { ... }

    // ...
};

Dave


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