fork download
#include <iostream>
#include <functional>
#include <string>

namespace fx {
    template<int I> struct placeholder{};
}

namespace std{
    template<int I>
    struct is_placeholder< ::fx::placeholder<I>> : std::integral_constant<int, I>{};
}

namespace fx {
    template <size_t... Is>
    struct indices {};

    template <size_t N, std::size_t... Is>
    struct build_indices : build_indices<N-1, N-1, Is...> {};

    template <size_t... Is>
    struct build_indices<0, Is...> : indices<Is...> {};

    template<std::size_t... Is, class F, class... Args>
    auto easy_bind(indices<Is...>, F const& f, Args&&... args)
    -> decltype(std::bind(f, std::forward<Args>(args)..., placeholder<Is + 1>{}...))
    {
        return std::bind(f, std::forward<Args>(args)..., placeholder<Is + 1>{}...);
    }
    
    template<class R, class... FArgs, class... Args>
    auto easy_bind(std::function<R(FArgs...)> f, Args&&... args)
    -> decltype(fx::easy_bind(build_indices<sizeof...(FArgs) - sizeof...(Args)>{}, f, std::forward<Args>(args)...)) {
    return fx::easy_bind(build_indices<sizeof...(FArgs) - sizeof...(Args)>{}, f, std::forward<Args>(args)...);
    }
    
    template<class R, class... FArgs, class... Args>
    auto easy_bind(R (*f)(FArgs...), Args&&... args)
    -> decltype(fx::easy_bind(build_indices<sizeof...(FArgs) - sizeof...(Args)>{}, f, std::forward<Args>(args)...)) {
    	return fx::easy_bind(build_indices<sizeof...(FArgs) - sizeof...(Args)>{}, f, std::forward<Args>(args)...);
    }
    
    template <typename R, typename T, typename... FArgs, typename... Args>
	auto easy_bind(R (T::*mf)(FArgs...), Args&&... args)
	-> decltype(fx::easy_bind(std::function<R(T*,FArgs...)>(mf), args...))
	{
	    return fx::easy_bind(std::function<R(T*,FArgs...)>(mf), args...);
	}

}

//Test Case:
struct SomeStruct {
    void function(int x, float y, std::string str) {
        std::cout << x << " " << y << " " << str << std::endl;    
    }
};


int main() {
	auto f = fx::easy_bind(&SomeStruct::function, new SomeStruct);
	f(5,2.5,"test");
    
    return 0;
}
Success #stdin #stdout 0s 3432KB
stdin
Standard input is empty
stdout
5 2.5 test