openthread-br
0.3.0-72c0388
|
#include <src/common/callback.hpp>
Public Member Functions | |
template<typename T , typename = typename std::enable_if<!std::is_same<OnceCallback, T>::value>::type> | |
OnceCallback (T &&func) | |
OnceCallback (const OnceCallback &)=delete | |
OnceCallback & | operator= (const OnceCallback &)=delete |
OnceCallback (OnceCallback &&)=default | |
OnceCallback & | operator= (OnceCallback &&)=default |
R | operator() (Args...) const & |
R | operator() (Args... args) && |
bool | IsNull () const |
A callback which can be invoked at most once.
IsNull is guaranteed to return true once the callback has been invoked.
Example usage: OnceCallback<int(int)> square([](int x) { return x * x; }); std::move(square)(5); // Returns 25. std::move(square)(6); // Crashes since square
has already run. square(7); // Compiling error.
Inspired by Chromium base::OnceCallback (https://chromium.googlesource.com/chromium/src.git/+/refs/heads/main/base/callback.h).