Any word on the return-type const syntax?

Janice Caron caron800 at googlemail.com
Sat Dec 8 14:59:17 PST 2007


But I think there's still a problem. If I write

    class MyArray(T)
    {
        T[] a;
        TransferConst!(U,T*) ptr(this U)()
        {
            return a.ptr;
        }
    }

    const MyArray!(int) aa;
    auto p = aa.ptr;

Then presumably it won't compile, becase aa is not mutable, and
therefore cannot call a member function which has not been declared
const. To make it compile, I'd have to change it to

    class MyArray(T)
    {
        T[] a;
        TransferConst!(U,T*) ptr(this U)() const
        {
            return a.ptr;
        }
    }

But doesn't that now mean that "this" will /always/ be const within
that function? Hence, if I now do

    MyArray!(int) aa;
    auto p = aa.ptr;

won't the type of p end up being const(int)[] rather than int[] ?



More information about the Digitalmars-d mailing list