openthread-br  0.3.0-72c0388
Public Member Functions | List of all members
otbr::OnceCallback< R(Args...)> Class Template Reference

#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
 
OnceCallbackoperator= (const OnceCallback &)=delete
 
 OnceCallback (OnceCallback &&)=default
 
OnceCallbackoperator= (OnceCallback &&)=default
 
operator() (Args...) const &
 
operator() (Args... args) &&
 
bool IsNull () const
 

Detailed Description

template<typename R, typename... Args>
class otbr::OnceCallback< R(Args...)>

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).


The documentation for this class was generated from the following file: