const

Janice Caron caron800 at googlemail.com
Sat Mar 29 23:58:21 PDT 2008


Another alternative to view is viewof. As in viewof(T).

    void f(viewof(C));

or

    viewof(char)[]

etc. It's a tad longer than "veiw", but even so, that's now my
favorite one so far, just because of the way it looks and sounds in my
head.

Of course, it still looks weird when applied to member functions - but
then, so would anything, because of the confusing const-at-the-front
syntax we currently have:

    class C
    {
        viewof ReturnType f()
        {
            /*...*/
        }
    }

which only further reinforces my conviction that const-at-the-front
for member functions is the problem here, not the keyword for
constancy. The following is infinitely more readable:

    class C
    {
        viewof(this) ReturnType f()
    }

(The function f only gets a view of this). If we had viewof(this) for
member functions, and viewof(T) for types, then it would all be so
intuitive.



More information about the Digitalmars-d mailing list