简体   繁体   中英

Get lambda parameters type into template argument pack

I've been searching for an answer for hours, but I didn't find anything... So, Here is my problem:

template<typename Signature> struct wrapper; // (1)

template<typename Ret, typename... Args>
struct wrapper<Ret(Args...)> // (2)
{
  function static get(Ret(*fnc)(Args...), Args... args)
  {
    return function(/*some more stuff here that work*/);
  }
}

basically, this code extract the return type and the parameters of a function and return a generic function container. This code work with simple function. But then I tried to use lambdas. Without this wrapper (by handwriting the complete prototype) the code work, and I am able to call lambda. But when I use this wrapper with lambda functions, I get some

'./some-file.cpp:xy:z: error: incomplete type 'wrapper >' used in nested name specifier'

Is the error caused by the two points (1) and (2) because a lambda could not fit into a function pointer ? I am searching a way to get the arguments types of the lambda into a template argument pack (the return type is not important, all my lambdas does not return values (so it's void)) Thanks in advance for your help :)

It seems you only declare the wrapper structure, you don't actually define it.

Try to properly define the structure:

template<typename Signature> struct wrapper {};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM