diff --git a/lib/pls/include/pls/internal/helpers/member_function.h b/lib/pls/include/pls/internal/helpers/member_function.h new file mode 100644 index 0000000..d78e142 --- /dev/null +++ b/lib/pls/include/pls/internal/helpers/member_function.h @@ -0,0 +1,35 @@ + +#ifndef PLS_INTERNAL_HELPERS_MEMBER_FUNCTION_H_ +#define PLS_INTERNAL_HELPERS_MEMBER_FUNCTION_H_ + +namespace pls { +namespace internal { +namespace helpers { + +template +class member_function { + public: + using type = member_function; + + member_function(C *object, R (C::*function_pointer)(ARGS...)) : object_{object}, + function_pointer_{function_pointer} {} + + R operator()(ARGS... args) { + ((*object_).*function_pointer_)(args...); + } + + private: + C *object_; + R (C::*function_pointer_)(ARGS...); +}; + +template +static constexpr member_function bind(C *object, R (C::*function_pointer)(ARGS...)) { + return {object, function_pointer}; +} + +} +} +} + +#endif //PLS_INTERNAL_HELPERS_MEMBER_FUNCTION_H_