c++ - How can I detect parameter types of a function passed as a parameter? -


problem

i have write function used as:

obj.transform([](x& a, y& b) { ... }); obj.transform([](x& a) { ... }); obj.transform([](y const& a, x& b, z const& c) { ... }); obj.transform([a, b](z const& c) { ... }); ... 

and inside function declaration, need figure out type of arguments passed in.

the body of function in form (assuming x member object , argfn function passed in):

if (x.mfn1<std::remove_reference_t<args>...>())     argfn(x.mfn2<std::remove_reference_t<args>>()...); 

context

if asking yourself, why , have no idea how useful, or if think xy problem, can find the context right here.

my attempts

attempt #1

template<typename... args> void fn(std::function<void(args...)>) { ... } 

this doesn't work because there's apparently no way have conversion between std::function , lambda.

attempt #2

template<typename... args> void fn(void(*)(args...)) { ... } 

this works first, second , third example above (prepending + on each lambda force conversion pointer function), fails on fourth.

it's impossible. example, if argument functor containing templated (especially variadic) operator()? or 1 overloaded? "arguments" then?

the core problem here you're re-implementing ranges worse. offer plain iterators on entities , use std::transform. or find range library of choice.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -