fork download
  1. #include <utility>
  2. using namespace std;
  3.  
  4. template<class Func, class... Args>
  5. auto test_lambda(Func&& func, Args&&... args) {
  6. return [=]() mutable { func(std::move(args)...); };
  7. }
  8.  
  9. void test_int(int*){}
  10.  
  11. int main() {
  12. int arr[5];
  13. test_lambda(test_int, arr);
  14. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In instantiation of 'test_lambda(Func&&, Args&& ...)::<lambda()> mutable [with Func = void (&)(int*); Args = {int (&)[5]}]':
prog.cpp:6:43:   required from 'struct test_lambda(Func&&, Args&& ...) [with Func = void (&)(int*); Args = {int (&)[5]}]::<lambda()>'
prog.cpp:6:54:   required from 'auto test_lambda(Func&&, Args&& ...) [with Func = void (&)(int*); Args = {int (&)[5]}]'
prog.cpp:13:30:   required from here
prog.cpp:6:28: error: variable 'func' has function type
     return [=]() mutable { func(std::move(args)...); };
                            ^
prog.cpp:6:28: error: variable 'func' has function type
prog.cpp: In instantiation of 'struct test_lambda(Func&&, Args&& ...) [with Func = void (&)(int*); Args = {int (&)[5]}]::<lambda()>':
prog.cpp:6:54:   required from 'auto test_lambda(Func&&, Args&& ...) [with Func = void (&)(int*); Args = {int (&)[5]}]'
prog.cpp:13:30:   required from here
prog.cpp:6:28: error: field 'test_lambda(Func&&, Args&& ...) [with Func = void (&)(int*); Args = {int (&)[5]}]::<lambda()>::<func capture>' invalidly declared function type
stdout
Standard output is empty