ARMmbed / mbed-events

DEPRECATED! This project has moved to mbed-os
https://github.com/ARMmbed/mbed-os/tree/master/events
Apache License 2.0
11 stars 6 forks source link

Increase type-infering functions to all possible event permutations #23

Closed geky closed 7 years ago

geky commented 7 years ago

EventQueue::event is now defined for the following overloads:

event(R (*)(A...),                                       C...);
event(F,                                                 C...);
event(const F,                                           C...);
event(volatile F,                                        C...);
event(const volatile F,                                  C...);
event(T *,                R (T::*)(A...),                C...);
event(const T *,          R (T::*)(A...) const,          C...);
event(volatile T *,       R (T::*)(A...) volatile,       C...);
event(const volatile T *, R (T::*)(A...) const volatile, C...);

This insures cleaner error messages when invalid types are used.

It should be noted that different types are used for the infered function parameters and the arguments supplied to event, this is important for inducing implicit casts.

Otherwise, deceptively confusing bugs can occur:

    void doit(unsigned value);
    queue.event(doit, 1); // Error - 1 is signed without implicit casts

With the stricter type inference on the convenience event function, it is trivial to determine the quantity of parameters present in a function type.

With the arity of the function type, we can determine which Event class must be generated entirely based on type inference. This is a huge benefit to the value of the convenience event functions and removes any lingering limitations on the event function usage.