Skip to content

Simple header-only wrapper for converting std::bind result to function pointer

License

Notifications You must be signed in to change notification settings

Stivius/callable-wrapper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bind to function pointer

It's quite simple header-only wrapper around std::bind result object. The wrapper is generated that allows you to use it with C-style function pointer.

Usage

Supposing you have C library with some some functions which should receive function pointer as one of their parameters.

void c_lib_function(void (*funct_ptr)(int, int)); // function signature from C lib

And you have your function from class Test which you want to pass to the lib function.

void Example::mem_function(int a, int b); // your function from class Example

You can std::bind this function to make it independent from your class object and here comes the wrapper which allows to pass the bind result to C library function:

#include <functional>

#include "BindWrapper.hpp"

class Example
{
public:
    void mem_function(int a, int b) { }
};

int main()
{
    using namespace std::placeholders;
    
    Example obj;
    auto result = std::bind(&Example::mem_function, &obj, _1, _2);
    
    c_lib_function(get_wrapper<0, void, int, int>(result));
    
}

About

Simple header-only wrapper for converting std::bind result to function pointer

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published