#include <utility>
#include "pw_function/internal/static_invoker.h"
Go to the source code of this file.
Namespaces | |
namespace | pw |
Provides basic helpers for reading and writing UTF-8 encoded strings. | |
Functions | |
template<typename FunctionType > | |
constexpr auto | pw::function::GetFunctionPointer () |
template<typename FunctionType > | |
constexpr auto | pw::function::GetFunctionPointer (const FunctionType &) |
template<typename FunctionType > | |
constexpr auto | pw::function::GetFunctionPointerContextFirst () |
template<typename FunctionType > | |
constexpr auto | pw::function::GetFunctionPointerContextFirst (const FunctionType &) |
Traditional callback APIs often use a function pointer and void*
context argument. The context argument makes it possible to use the callback function with non-global data. For example, the qsort_s
and bsearch_s
functions take a pointer to a comparison function that has void*
context as its last parameter.
embed:rst:inline :cpp:type:`pw::Function`
does not naturally work with these kinds of APIs.
The functions below make it simple to adapt a
embed:rst:inline :cpp:type:`pw::Function`
for use with APIs that accept a function pointer and void*
context argument.
|
constexpr |
Returns a function pointer that invokes a pw::Function
, lambda, or other callable object from a void*
context argument. This makes it possible to use C++ callables with C-style APIs that take a function pointer and void*
context.
The returned function pointer has the same return type and arguments as the pw::Function
or pw::Callback
, except that the last parameter is a void*
. GetFunctionPointerContextFirst
places the void*
context parameter first.
The following example adapts a C++ lambda function for use with C-style API that takes an int (*)(int, void*)
function and a void*
context.
The function returned from this must ONLY be used with the exact type for which it was created! Function pointer / context APIs are not type safe.
|
constexpr |
GetFunctionPointer
overload that uses the type of the function passed to this call.
|
constexpr |
Same as GetFunctionPointer
, but the context argument is passed first. Returns a void(void*, int)
function for a pw::Function<void(int)>
.
|
constexpr |
GetFunctionPointerContextFirst
overload that uses the type of the function passed to this call.