#include <functional> #include <future> #include <iostream> #include <thread> template<class Func, class... Args> void submit(Func&& f, Args&&... args) { using returnType = typename std::result_of<Func(Args...)>::type; auto task1 = std::packaged_task<returnType()>(std::bind(std::forward<Func>(f), std::forward<Args>(args)...)); std::cout << std::is_const<decltype(task1)>::value << " task1 const or not" << std::endl; auto tmp = [task2=std::move(task1)]() { std::cout << std::is_const<decltype(task2)>::value << " const or not" << std::endl; // print 0, which means non-const // task2(); // uncomment this line, compilation will fail }; tmp(); } int main() { submit([&] { std::cout << "fooooooooo" << std::endl; }); return 0; } I know the meaning of error; I know making lambda mutable will help and I test it, but I want to know where does the const come from. Note that std::is_const returns false, which makes me really confused.
EDIT: Sorry forgot to mention the compiler. I was using clang-1000.10.44.2. The command is clang++ -std=c++14 test.cpp -o test