Thread overview | |||||||||
---|---|---|---|---|---|---|---|---|---|
|
January 25, 2014 Printing type name in static assert | ||||
---|---|---|---|---|
| ||||
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? |
January 25, 2014 Re: Printing type name in static assert | ||||
---|---|---|---|---|
| ||||
Posted in reply to Martin Cejp | 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?
|
January 25, 2014 Re: Printing type name in static assert | ||||
---|---|---|---|---|
| ||||
Posted in reply to Martin Cejp | I think what you are looking for is Class.stringof: template XYZ(Class) { // ... static assert(index != -1, "No such annotation on "~ Class.stringof) ); // ... } |
January 25, 2014 Re: Printing type name in static assert | ||||
---|---|---|---|---|
| ||||
Posted in reply to Rikki Cattermole | On Saturday, 25 January 2014 at 11:41:54 UTC, Rikki Cattermole
wrote:
> ...
Damn, beaten by 1 second!
|
January 25, 2014 Re: Printing type name in static assert | ||||
---|---|---|---|---|
| ||||
Posted in reply to Martin Cejp | 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. |
January 25, 2014 Re: Printing type name in static assert | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dicebot | 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:
>> 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.
Thanks, that will do.
fullyQualifiedName was the first that came to mind, but it's broken.
|
January 25, 2014 Re: Printing type name in static assert | ||||
---|---|---|---|---|
| ||||
Posted in reply to Martin Cejp | 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 :-) |
Copyright © 1999-2021 by the D Language Foundation