When looking for documentation on std::function, I found several pages, that list two implementations of std::function for C++11:
template< class > class function; /* undefined */ template< class R, class... Args > class function<R(Args...)>;
template <class T> function; // undefined template <class Ret, class... Args> class function<Ret(Args...)>;
template<class > class function;and
template< class R, class... Args > class function<R(Args...)>
I tried to use the multi-parameter version of the function<>-template, but my code does not compile, neither with visual c++ 2017, nor with XCode or g++. Here is my sample code:
#include <functional> int main(int argc, char*argv[]) { std::function<void, int> cb; } All compilers complain on std::function taking only a single template parameter.
Can anybody explain this?
void, intdoesn't look compatible withR(Args...).R- return type.Args...- pack of arguments. Specify it asvoid(int)ReturnType(Arg1Type, Arg2Type...). E.g.: godbolt.org/z/s4xoveqsEstd::function<void(int)> cb;