I am trying to bind a member function to an object while keeping the arguments open. I know I can do it by wrapping it in a lambda expression (like this) but I want to use std::bind and std::placeholders to do it.
So far this is what I've got:
template <size_t _Num>
struct place_holder {};
namespace std {
template <size_t _Num>
struct is_placeholder<::place_holder<_Num>> : integral_constant<size_t, _Num> {};
}
namespace _binding_helper_ {
template <size_t ... _Indices>
std::tuple<place_holder<_Indices>...> get_placeholders(std::index_sequence<_Indices...>) {
return std::make_tuple(place_holder<_Indices>()...);
}
}
template <typename _Obj, typename _Func, typename ... _Args>
std::function<_Func(_Args...)> bind_function_to_object
(_Func (_Obj::*func)(_Args...), _Obj & obj) {
return std::bind(func, obj,
_binding_helper_::get_placeholders(std::make_index_sequence<sizeof...(_Args)>{}));
}
Creating the tuple of place_holders works fine but when I call std::is_placeholder<>::value on the elements of the tuple they are all 0. How can I initialise the place_holder<_Num> struct for all required values of _Num as std::placeholders? Hope there's an easy fix. Any help appreciated. Thanks!