Re: Compile-time variables

2018-04-06 Thread Kayomn via Digitalmars-d-learn
On Friday, 6 April 2018 at 14:15:08 UTC, Kayomn wrote: On Friday, 6 April 2018 at 13:55:55 UTC, nkm1 wrote: [...] Figured I had a handle on how it worked doing but guess not. One final question, however. [...] Nevermind, I'm blind. I missed the post-increment in newID().

Re: Compile-time variables

2018-04-06 Thread Kayomn via Digitalmars-d-learn
On Friday, 6 April 2018 at 13:55:55 UTC, nkm1 wrote: On Friday, 6 April 2018 at 13:10:23 UTC, Kayomn wrote: ID tags are unique and spsecific to the class type. There shouldn't be more than one type ID assigned to one class type. The idea behind what it is I am doing is I am implementing a sol

Re: Compile-time variables

2018-04-06 Thread nkm1 via Digitalmars-d-learn
On Friday, 6 April 2018 at 13:10:23 UTC, Kayomn wrote: ID tags are unique and spsecific to the class type. There shouldn't be more than one type ID assigned to one class type. The idea behind what it is I am doing is I am implementing a solution to getting a type index, similar to std.variant

Re: Compile-time variables

2018-04-06 Thread Kayomn via Digitalmars-d-learn
Besides this, I tried something with types used as user defined attributes. https://dlang.org/spec/attribute.html#uda Automatic compile time tagging is not my speciality, however, I think is also achievable with mixins somehow? But I don't know how to workaround the bug https://issues.dlang.

Re: Compile-time variables

2018-04-06 Thread aliak via Digitalmars-d-learn
On Friday, 6 April 2018 at 02:20:29 UTC, Kayomn wrote: Wrong example code, here's the correct example: switch (queryString(childJson,"type")) { case (typeof (Sprite).name): child = this.addCh

Re: Compile-time variables

2018-04-06 Thread Alex via Digitalmars-d-learn
On Friday, 6 April 2018 at 02:20:29 UTC, Kayomn wrote: Wrong example code, here's the correct example: switch (queryString(childJson,"type")) { case (typeof (Sprite).name): child = this.addCh

Re: Compile-time variables

2018-04-05 Thread Kayomn via Digitalmars-d-learn
On Friday, 6 April 2018 at 02:18:28 UTC, Kayomn wrote: 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 {}

Re: Compile-time variables

2018-04-05 Thread Kayomn via Digitalmars-d-learn
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 () {

Re: Compile-time variables

2018-04-05 Thread Kayomn via Digitalmars-d-learn
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);

Re: Compile-time variables

2018-04-05 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, April 06, 2018 00:35:39 Kayomn via Digitalmars-d-learn wrote: > On Friday, 6 April 2018 at 00:21:54 UTC, H. S. Teoh wrote: > > On Thu, Apr 05, 2018 at 11:53:00PM +, Kayomn via > > Digitalmars-d-learn wrote: [...] > > > >> [...] > > > > [...] > > > >> [...] > > > > `lastID`, as declar

Re: Compile-time variables

2018-04-05 Thread ketmar via Digitalmars-d-learn
Kayomn wrote: I'll give a better example of what it is I'm trying to do. These are node types. Their contents are not important in this explanation, only that they operate as a tree structure. class Node; class RootNode : Node; class SpriteNode : Node; The result of getNodeID on a specifi

Re: Compile-time variables

2018-04-05 Thread Kayomn via Digitalmars-d-learn
I'll give a better example of what it is I'm trying to do. These are node types. Their contents are not important in this explanation, only that they operate as a tree structure. class Node; class RootNode : Node; class SpriteNode : Node; The result of getNodeID on a specific type is always

Re: Compile-time variables

2018-04-05 Thread Kayomn via Digitalmars-d-learn
On Friday, 6 April 2018 at 00:21:54 UTC, H. S. Teoh wrote: On Thu, Apr 05, 2018 at 11:53:00PM +, Kayomn via Digitalmars-d-learn wrote: [...] [...] [...] [...] `lastID`, as declared above, are runtime variables. The 'static' in this case just means it's thread-local, rather than allocat

Re: Compile-time variables

2018-04-05 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Apr 05, 2018 at 11:53:00PM +, Kayomn via Digitalmars-d-learn wrote: [...] > --- > alias NodeTypeID = uint; > > enum NodeTypeID getNodeID() { > static NodeTypeID lastID = 0; > > return lastID++; > }

Compile-time variables

2018-04-05 Thread Kayomn via Digitalmars-d-learn
Hi, I've got a scene graph which contains multiple inheriting types. As such, I've been tagging them with a type enum for whenever I need to do things such as loading a structure from binary. Up until now I've been using an enum that looks like this: -

Re: Static Foreach + Marking "compile time" variables

2018-03-28 Thread Chris Katko via Digitalmars-d-learn
On Wednesday, 28 March 2018 at 23:42:26 UTC, Simen Kjærås wrote: On Wednesday, 28 March 2018 at 23:02:53 UTC, Chris Katko wrote: There's many things that can be done to make the code easier to follow. These lines: [...] [...] WOW. Thank you. That's the kind of tricks for (or more properly:

Re: Static Foreach + Marking "compile time" variables

2018-03-28 Thread Simen Kjærås via Digitalmars-d-learn
On Wednesday, 28 March 2018 at 23:02:53 UTC, Chris Katko wrote: There's many things that can be done to make the code easier to follow. These lines: static if (!hasPosition) { assert(0, "Need to pass a position!"); } Can be replaced with thi

Re: Static Foreach + Marking "compile time" variables

2018-03-28 Thread Chris Katko via Digitalmars-d-learn
On Wednesday, 28 March 2018 at 17:42:45 UTC, Steven Schveighoffer wrote: On 3/28/18 11:46 AM, Chris Katko wrote: enum hasRotate = anySatisfy!( isa(pos), a);  //if of type "pos" anySatisfy!(isa!pos, a) anySatisfy takes a template alias (in this case, an instantiation of isa with a speci

Re: Static Foreach + Marking "compile time" variables

2018-03-28 Thread Chris Katko via Digitalmars-d-learn
On Wednesday, 28 March 2018 at 17:08:39 UTC, Chris Katko wrote: On Wednesday, 28 March 2018 at 15:49:39 UTC, Chris Katko wrote: On Wednesday, 28 March 2018 at 15:46:42 UTC, Chris Katko wrote: [...] Whoops! Wrong error message. That's if I replace isa(pos) with IsIntegral. [...] Okay, the

Re: Static Foreach + Marking "compile time" variables

2018-03-28 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/28/18 11:46 AM, Chris Katko wrote: enum hasRotate = anySatisfy!( isa(pos), a);  //if of type "pos" anySatisfy!(isa!pos, a) anySatisfy takes a template alias (in this case, an instantiation of isa with a specific type), and then applies the template to all the elements of the alias

Re: Static Foreach + Marking "compile time" variables

2018-03-28 Thread Chris Katko via Digitalmars-d-learn
On Wednesday, 28 March 2018 at 15:49:39 UTC, Chris Katko wrote: On Wednesday, 28 March 2018 at 15:46:42 UTC, Chris Katko wrote: [...] Whoops! Wrong error message. That's if I replace isa(pos) with IsIntegral. [...] Okay, the key appears to be here: funct2(123); //a function call void fu

Re: Static Foreach + Marking "compile time" variables

2018-03-28 Thread Chris Katko via Digitalmars-d-learn
clean, elegant solution that simply passes through each parameter, and then reacts to the combined result, and end up with something that has to "step toward" the result, or perhaps, test every possible permutation individually--so as to not need variables. D does not have compile-

Re: Static Foreach + Marking "compile time" variables

2018-03-28 Thread Chris Katko via Digitalmars-d-learn
and then reacts to the combined result, and end up with something that has to "step toward" the result, or perhaps, test every possible permutation individually--so as to not need variables. D does not have compile-time variables. The way you'd generally do what you descri

Re: Static Foreach + Marking "compile time" variables

2018-03-28 Thread Simen Kjærås via Digitalmars-d-learn
thing that has to "step toward" the result, or perhaps, test every possible permutation individually--so as to not need variables. D does not have compile-time variables. The way you'd generally do what you describe is with the templates in std.meta. Instead of something like thi

Static Foreach + Marking "compile time" variables

2018-03-28 Thread Chris Katko via Digitalmars-d-learn
I have a static foreach that goes through the parameter list and if it sees a class like "rotate", ideally, I want it to mark a boolean "has_rotate=true" Then simply later on, once I've parsed the list, I pick an output path: static if(has_rotate && has_position && has_scale) { /