zenoh-c closure is a structure with 3 fields: context pointer context
, callback call
and finalizer drop
. Context is a pointer to closure data, callback is a function pointer and finalizer is a function pointer which is called when closure is destroyed. Example of zenoh-c closure:
zenoh-cpp closures are wrappers around zenoh-c closures. These wrappers allows to construct closures from any callable C++ object, like lambda or function pointer.
All zenoh-cpp closures are based on the one of the following templates: :cppzenohcxx::ClosureConstPtrParam
and :cppzenohcxx::ClosureMoveParam
. First one accepts const ZCPP_PARAM&
, second one accepts ZCPP_PARAM&&
.
These templates allows to construct closures from any callable C++ object:
function pointer of type
void (func*)(const ZCPP_PARAM&)
orvoid (func*)(ZCPP_PARAM&&)
Example:
any object which can be called with corresponding parameter, e.g. lambda or custom object. If object is passed by move, closure will take ownership of it, otherwise it will store reference to it.
Example:
or
zenohcxx::ClosureConstRefParam
zenohcxx::ClosureMoveParam