Js event mechanism implemented by cjiajia

  node.js, question

I want to simulate the EventEmitter mechanism in node.js from c plus, and only need to realize explicit callback registration and explicit callback triggering.
About the explanation and usage of EventEmitter in node.jsHere

I mainly want to implement a simplified version of the event class. It is enough to call emit to explicitly trigger events.
This class has two main methods
One is to register the callback function:
on(name,callback,callback_args);
One is the trigger callback function:
emit(name);
Or ..
emit(name,callback_args);

However, the problem here is that when registering a callback function, the callback function may have multiple parameters, and the callback function may also be triggered with parameters.
How can this be achieved here?

Come on bit by bit, C Gaga needs a lot of work to do this node.js inside looks very common.
If I do not store this callback function first, I want to invoke(func, args) to achieve the effect of calling func(args). I need to do this:

#include <iostream>
 
 template <typename Func, typename... Args>
 void invoke(Func routine, Args... args) {
 routine(args...);
 bracket
 
 void print(int c, double d) {
 std::cout << c  << d << std::endl;
 bracket
 
 int main(int argc, char** argv) {
 invoke(print, 3, 3.14);
 return 0;
 bracket

Output: 33.14
If you want to save args … and func for later calls, then you need to save args … in c plus
Std::tuple<Args … >, then you need a generator when you take it out of tuple inside, and then call func.