On Wednesday, September 26, 2018 at 10:35:48 AM UTC-4, Philipp Klaus Krause wrote:
...
> So far the only idea I have come up is creating an instance of T_t with
> at least one vertex, and then using decltype(T[0].x). But that seemed
> too ugly even by C++ standards, so I decided to ask on comp.lang.c++
> instead.
decltype() requires an expression as it's argument. If T is a type, T[0]
could be a typename for an array containing 0 elements of type T - which
would be a problem because of the 0 length. However, the immediately
following '.' would make it a syntax error. A type name can appear in an
expression, but only as the argument of a sizeof, alignof, new, or
typeid expression, never as the the starting portion of the expression.
I think you mean _t[0].x rather than T{0].x. If that's the simplest
expression that you can think of which gives you the value of the x
member, then decltype(_t[0].x) is the best you can do. I'm not sure why
you consider that "too ugly". Any construct that gives you the type of
that member has to be given enough information to identify which member
it is, of which struct type. Could you give an example of less ugly
syntax that could have been used for this purpose (possibly in an
entirely different language from C++), so I can better understand your
judgement of this particular syntax as "too ugly"?