Skip to content

Callback: nullptr adjustments #1184

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 14, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docs/api/platform/Callback.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ void run_timer_event(Callback<void(float)> on_timer) {
}
```

The only thing to watch out for is that the Callback type has a null Callback, just like a null function pointer. Uninitialized callbacks are null and assert if you call them. If you want a call to always succeed, you need to check if it is null first.
The only thing to watch out for is that the Callback type has an empty Callback, just like a null function pointer. Default initialized callbacks are empty and assert if you call them. If a callback may be empty, you need to check if it is empty before calling it.

``` c++
void run_timer_event(Callback<void(float)> on_timer) {
Expand All @@ -24,6 +24,8 @@ void run_timer_event(Callback<void(float)> on_timer) {
}
```

You can reset Callbacks to empty by assigning `nullptr`.

The Callback class is what’s known in C++ as a “Concrete Type”. That is, the Callback class is lightweight enough to be passed around like an int, pointer or other primitive type.

## Callback class reference
Expand Down