Compile-time variables

Kayomn spam at kayomn.net
Fri Apr 6 02:18:28 UTC 2018


On Friday, 6 April 2018 at 01:22:42 UTC, Kayomn wrote:
> On Friday, 6 April 2018 at 01:14:37 UTC, ketmar wrote:
>> Kayomn wrote:
>>
>>> [...]
>>
>> it is already done for you, free of charge.
>>
>> 	class Node {}
>> 	class RootNode : Node {}
>> 	class SpriteNode : Node {}
>>
>> 	void main () {
>> 		auto nodeId1 = typeid(Node);
>> 		auto nodeId2 = typeid(SpriteNode);
>> 		auto comparison = typeid(Node);
>>
>> 		Node n = new SpriteNode();
>>
>> 		assert(typeid(Node) is typeid(Node)); // obviously
>> 		assert(typeid(SpriteNode) !is typeid(Node)); // sure
>> 		assert(typeid(Node) is nodeId1);
>> 		assert(typeid(n) is nodeId2);
>> 	}
>
> Oh neat, thanks. I've been really scraping my head over this, 
> and was worried I wouldn't be able to keep supporting my D 
> version of the project.

Hmm... doesn't seem to operate at compile-time, which is an issue 
if I want to use it in case switch table like I was going to:

--------------------------------------------------------------------------------
switch (queryInteger(childJson,"type")) {
	case NodeType.Sprite:
		child = this.addChild!(Sprite)(childName);

		break;

	default:
		child = this.addChild!(Node)(childName);

		break;
}
--------------------------------------------------------------------------------


More information about the Digitalmars-d-learn mailing list