[Issue 7177] $ should forward to length by default

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Mar 22 09:05:11 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=7177



--- Comment #40 from monarchdodra at gmail.com 2013-03-22 09:05:10 PDT ---
(In reply to comment #39)
> However, we can probably make opDollar a special case, it's not really an
> operator but a special symbol that $ gets translated into.

By that logic, opBinary is not really an operator, but a special symbol "+"
gets translated into. Besides, you could do very stupid stuff with opDollar the
same as with any operator.

//Convenience to transform a pointer into a slice:
size_t opDollar(T)(T* p)
{
    return 1;
}
...
void main()
{
    int   i = 1;
    int*  p = &i;
    int[] s = p[0 .. $]; //Now legal!
}

So allowing opDollar as non-member operator could be used unsafely just the
same as any other operator.

> I don't think it
> would be inconsistent to allow UFCS opDollar and not allow other operators via
> UFCS.

I'm really just questioning why we don't allow UFCS for *all* operators? Seems
like a restriction when you take into account the fact that you have UFCS.
After all, it can already be used to give built-in types new attributes. Why
are operators different from functions?

There will always be stupid users to do stupid things with code. I don't see
why it should prevent us from having useful and smart tools.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list