-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit 161a2ec
committed
callback - Added size-limited function-object overloads to Callback
The callback class can now accept generalized function-objects:
class Thing {
public:
int value;
void operator()() {
printf("hi! %d\n", value);
}
};
Callback<void()> cb(Thing(2));
However, with the intention of avoiding implicit dynamic-memory
allocations, the Callback class is limited to a single word of storage.
Exceeding this size will eliminate the function-object type from the
overload set and fail to compile.
Effort was invested to make this situation very clear to the user. Here
is an example error message with noise removed:
[ERROR] ./main.cpp: In function 'int main()':
./mbed-os/hal/api/Ticker.h:101:10: note:
no known conversion for argument 1 from 'BigFunc' to 'mbed::Callback<void()>'
The real benefit of this change is the ability for users to hook into
the attributes of the Callback class. This mostly allows lifetime
management of the function-objects from third-party libraries (such as
the Event class from mbed-events).
Note: The convenient `callback` function may become ambiguous if
provided with a type that defines multiple incompatible `operator()`
member functions.1 parent 804a621 commit 161a2ecCopy full SHA for 161a2ec
File tree
Expand file treeCollapse file tree
1 file changed
+912
-0
lines changedFilter options
- hal/api
Expand file treeCollapse file tree
1 file changed
+912
-0
lines changed
0 commit comments