• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Pretty Cool Variadic Functions ^)^

Status
Not open for further replies.
Level 31
Joined
Jul 10, 2007
Messages
6,306
Later, I might consider moving more towards a callback style, or rather a Trigger. This library isn't well written. For now, I don't have time to change it. I was only sharing it. It wasn't open to discussion for edits =P. I don't have time to edit it either way.

I do think careful consideration should be spent on vector vs list and that the underlying data structure should possibly be changed via a template, so long as it follows an interface =). The default data structure should probably be a vector, prioritizing execution performance over maintenance performance.

I have accepted your criticism, I'm just not going to do it. Changing it at this point would be major refactoring all over a massive project. I simply do not have time.

The style I would go for would be this

Trigger<argTypes, structure = std::vector> trigger
trigger.fire(args)

Will likely remove double references or something to give more freedom =)


Examples of use

Trigger<> trigger
trigger.register(callback, args)
trigger.fire()

Trigger<const int&> trigger
trigger.register(callback, args)
trigger.fire(int)


Will be for later of course, when and if I have time =)

edit
thank you

in the future, if I reuse this library, I'll be sure to edit it with your suggestions in mind =)
 
Level 31
Joined
Jul 10, 2007
Messages
6,306
Ok, I have updated this with your suggestions and a few other tweaks.


I really wanted a syntax like this

event += function
event -= function

However, std::function can't be compared : |. I want to support lambda expressions and methods and I don't know how else to do it =(.


Could/should throw an exception when trying to remove a callback that doesn't exist.

edit
lol... lost all references to a running lambda in my tests so I got to witness a lambda destroying itself + its captures while it was in the middle of running. Wonderful.
 
Last edited:
Status
Not open for further replies.
Top