summaryrefslogtreecommitdiff
path: root/plugingui/tester.cc
blob: a6dfb6d25f64ceb8e3aa382b26a988876b7dbb65 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <functional>
#include <type_traits>
#include <utility>

template <std::size_t... Is>
struct indices {};

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

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

template<int I> struct placeholder{};

namespace std{
template<int I>
struct is_placeholder< ::placeholder<I>> : std::integral_constant<int, I>{};
} // std::
namespace detail{
    template<std::size_t... Is, class Ret, class Fn, class... MArgs, class... Args>
    auto my_bind(indices<Is...>, Ret (Fn::*f)(MArgs...), Fn *i, Args&&... args) 
        -> decltype(std::bind(f, i, std::forward<Args>(args)..., placeholder<1 + Is>{}...)){
        return std::bind(f, i, std::forward<Args>(args)..., placeholder<1 + Is>{}...);
    }
}

template<class Ret, class... FArgs, class Fn, class... MArgs, class... Args>
auto my_bind(std::function<Ret(FArgs...)>, Ret (Fn::*f)(MArgs...), Fn *i, Args&&... args) 
        -> decltype(detail::my_bind(build_indices<sizeof...(FArgs) - sizeof...(Args)>{}, f, i, std::forward<Args>(args)...)){

    return detail::my_bind(build_indices<sizeof...(FArgs) - sizeof...(Args)>{}, f, i, std::forward<Args>(args)...);
}


#include <iostream>
struct tmp{
    void testt(int var1, int var2){
        std::cout << var1 << " " << var2 << std::endl;
    }
};

int main(){

    tmp TMP;
    auto f3 = my_bind(std::function<void(int, int)>(), &tmp::testt, &TMP);
    f3(22, 23);

}