digitalmars.D - Printing type name in static assert
- Martin Cejp (10/10) Jan 25 2014 I'm trying to do something to this effect:
- Rikki Cattermole (2/12) Jan 25 2014 Class.stringof perhaps?
- Jason White (3/4) Jan 25 2014 Damn, beaten by 1 second!
- Jason White (9/9) Jan 25 2014 I think what you are looking for is Class.stringof:
- Dicebot (5/15) Jan 25 2014 for just printing `Class.stringof` is most simple thing to do.
- Martin Cejp (4/21) Jan 25 2014 Thanks, that will do.
- Martin Cejp (12/12) Jan 25 2014 alias Field = typeof(__traits(getMember, Vertex, fieldName));
I'm trying to do something to this effect: template XYZ(Class) { ... static assert(index != -1, "No such annotation on " ~ typeid(Class)); ... } However, typeid is not a string and I can't do to!string. Nor is typeid().name implemented at compile time. What would be the correct way to do this?
Jan 25 2014
On Saturday, 25 January 2014 at 11:28:40 UTC, Martin Cejp wrote:I'm trying to do something to this effect: template XYZ(Class) { ... static assert(index != -1, "No such annotation on " ~ typeid(Class)); ... } However, typeid is not a string and I can't do to!string. Nor is typeid().name implemented at compile time. What would be the correct way to do this?Class.stringof perhaps?
Jan 25 2014
On Saturday, 25 January 2014 at 11:41:54 UTC, Rikki Cattermole wrote:...Damn, beaten by 1 second!
Jan 25 2014
I think what you are looking for is Class.stringof: template XYZ(Class) { // ... static assert(index != -1, "No such annotation on "~ Class.stringof) ); // ... }
Jan 25 2014
On Saturday, 25 January 2014 at 11:28:40 UTC, Martin Cejp wrote:I'm trying to do something to this effect: template XYZ(Class) { ... static assert(index != -1, "No such annotation on " ~ typeid(Class)); ... } However, typeid is not a string and I can't do to!string. Nor is typeid().name implemented at compile time. What would be the correct way to do this?for just printing `Class.stringof` is most simple thing to do. There are also `__traits(identifier, Class)` and `std.traits.fullyQualifiedName!Class` that are more specialized and usually used in code generation.
Jan 25 2014
On Saturday, 25 January 2014 at 11:44:04 UTC, Dicebot wrote:On Saturday, 25 January 2014 at 11:28:40 UTC, Martin Cejp wrote:Thanks, that will do. fullyQualifiedName was the first that came to mind, but it's broken.I'm trying to do something to this effect: template XYZ(Class) { ... static assert(index != -1, "No such annotation on " ~ typeid(Class)); ... } However, typeid is not a string and I can't do to!string. Nor is typeid().name implemented at compile time. What would be the correct way to do this?for just printing `Class.stringof` is most simple thing to do. There are also `__traits(identifier, Class)` and `std.traits.fullyQualifiedName!Class` that are more specialized and usually used in code generation.
Jan 25 2014
alias Field = typeof(__traits(getMember, Vertex, fieldName)); const bool normalized = HasAnnotation!(Vertex, fieldName, Normalized); const int fieldOffset = __traits(getMember, Vertex.init, fieldName).offsetof; int i = GetAnnotationInstance!(Vertex, fieldName, Position).pos; glVertexAttribPointer(i, cast(GLint) numElements!Field, TypeToGLEnum!(ElementType!Field), normalized ? GL_TRUE : GL_FALSE, Vertex.sizeof, cast(void*) fieldOffset); glEnableVertexAttribArray(i); I'm starting to like this language :-)
Jan 25 2014