c++11 - C++, match custom placeholders with function arguments -


i trying write piece of code following: let's assume have call of custom bind function

auto bind_obj = bind(some_func, _1, "test")   

and after have

auto res = bind_obj(42)  

where function some_func:

int some_func(int val, string test) 

how can possible match placeholders arguments provided in actual function call, i.e. bind_obj(...)??

in other words, possible iterate on std::tuple (arguments , placeholders here) , variadic pack (function arguments) to:

  1. deduce return type of function some_func;
  2. make correct std::tuple further use in some_func() call ?

i trying not using boost , std::functional. think, main problem don't understand how build tuple @ runtime arguments (where placeholders replaced correctly) , deduce return type.

i saw _mu template structure in stl "functional.h" looks complex , overloaded.

since argument list of call , list of captured arguments differently sized, won't iterate on them. instead, you'd function evaluated behaves according how arguments captured:

  • if bound element value returns value
  • if bound element placeholder returns argument @ given index
  • if bound element bind function returns result of evaluating function

assume bound object contains std::tuple<b...> of bound arguments called b construct std::tuple<...> of call arguments this:

template <typename... a, std::size_t... i> ... bound::call(std::tuple<a...>&& aux, index_list<i...>) {     auto args = std::make_tuple(get_argument<i>(this->b, a));     // ... } template <typename... a> ... bound::operator()(a&&... args) {     return this->call(std::tie(std::forward<a>(args)..., make_index_list<sizeof...a>()); } 

this code snippet shows how arguments sort of matched up. real work happens in get_argument<i>(b, a) functions woild return element of a indicated placeholder's value if element @ index i in b happens placeholder.

the code doesn't include details on how create index list, how determine rhe return type once call sorted out, or how deal rvalue arguments...


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -