Comment #0 by bearophile_hugs — 2010-06-04T15:42:55Z
A syntax like x.typeof can be considered.
There are situations where you will need to parenthesize anyway, like:
import std.stdio;
void main() {
int x = 1;
float y = 1.5;
writeln(typeid(typeof(x + y)));
}
You will have to write:
(x + y).typeof
But in many situations with this change you will be able to avoid the ().
This syntax is more similar/uniform to the x.sizeof syntax too (that is sizeof(x) in C).
Comment #1 by hoganmeier — 2010-06-13T17:49:40Z
Then typeid should probably also be .typeid instead of typeid()
Comment #2 by monarchdodra — 2012-09-14T11:17:24Z
*** Issue 8661 has been marked as a duplicate of this issue. ***
Comment #3 by issues.dlang — 2012-09-14T14:20:26Z
typeof isn't a property or a function, unlike sizeof. It's like an is-expression, and I think that treating it like a property would be a mistake.
Comment #4 by nick — 2012-10-06T06:22:10Z
(In reply to comment #3)
> typeof isn't a property or a function, unlike sizeof. It's like an
> is-expression, and I think that treating it like a property would be a mistake.
I think (x + y).typeof should not be allowed, use the existing syntax instead.
However, x.typeof is a useful shorthand that helps cut down on nested brackets in is expressions and elsewhere. So I would allow both typeof(expression) and identifier.typeof to be used, but *not* expression.typeof.
The type of an instance is a natural property of the instance IMO.
Comment #5 by maxim — 2012-10-06T06:41:10Z
(In reply to comment #4)
> (In reply to comment #3)
> > typeof isn't a property or a function, unlike sizeof. It's like an
> > is-expression, and I think that treating it like a property would be a mistake.
>
> I think (x + y).typeof should not be allowed, use the existing syntax instead.
>
> However, x.typeof is a useful shorthand that helps cut down on nested brackets
> in is expressions and elsewhere. So I would allow both typeof(expression) and
> identifier.typeof to be used, but *not* expression.typeof.
>
> The type of an instance is a natural property of the instance IMO.
The problem is that UFCS was made to work with functions and typeof is not a function. Accepting identifier.typeof would result in questions about which identifiers are valid for this and what else works besides typeof with them.
Comment #6 by nick — 2012-10-06T10:28:49Z
(In reply to comment #5)
> The problem is that UFCS was made to work with functions and typeof is not a
> function. Accepting identifier.typeof would result in questions about which
> identifiers are valid for this and what else works besides typeof with them.
This is not to do with UFCS. There are already many built in properties like x.sizeof, x.init:
http://dlang.org/property.html
typeof fits nicely as a built in property, and helps cut down on nested brackets.
Comment #7 by maxim — 2012-10-07T01:08:41Z
(In reply to comment #6)
> (In reply to comment #5)
> > The problem is that UFCS was made to work with functions and typeof is not a
> > function. Accepting identifier.typeof would result in questions about which
> > identifiers are valid for this and what else works besides typeof with them.
>
> This is not to do with UFCS. There are already many built in properties like
> x.sizeof, x.init:
> http://dlang.org/property.html
>
> typeof fits nicely as a built in property, and helps cut down on nested
> brackets.
Typeof is not a property either. And it differs from all those properties which, given a type or expression, provide fundamental information about their types like size, default value, name, alignment. Typeof works in opposite direction - given some expression it gives its type.
BTW, identifier is a primary expression (http://dlang.org/expression.html), so, making idenfier.typeof possible and expression.typeof not (as mentioned above), raises some questions.
However, if typeof is made a property too, it would be logical and consistent.
Comment #8 by razvan.nitu1305 — 2019-10-23T10:52:52Z
Closing this as there is not sufficient evidence that this will improve anything and special casing for symbols is not the way to go.