Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/147.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 什么';在C+中,std::mem#u fun和lambda之间的区别是什么+;11?_C++_C++11_Lambda - Fatal编程技术网

C++ 什么';在C+中,std::mem#u fun和lambda之间的区别是什么+;11?

C++ 什么';在C+中,std::mem#u fun和lambda之间的区别是什么+;11?,c++,c++11,lambda,C++,C++11,Lambda,对于此小代码: #include <thread> #include <iostream> #include <memory> #include <vector> #include <algorithm> using namespace std; void do_work(int id) { cout<<this_thread::get_id()<<" "<<id<<endl; }

对于此小代码:

#include <thread>
#include <iostream>
#include <memory>
#include <vector>
#include <algorithm>
using namespace std;
void do_work(int id)
{
    cout<<this_thread::get_id()<<" "<<id<<endl;
}

int main()
{
    vector<thread> threads;
    for(int i = 0; i < 20; i++)
        threads.push_back(thread(do_work, i));

    for_each(begin(threads), end(threads), [](thread & t){
        t.join();
    });
}
备选案文2:

for_each(begin(threads), end(threads), mem_fn(&thread::join));
问题: 1.哪种用法更好? 2.
mem\u fn
的用法是什么?你能简单地解释一下吗?

你不明白的部分是什么?既然您已经演示了如何使用
mem_-fun
,那么您在使用方面需要什么帮助?更好的标准是什么?你不明白哪一部分?既然您已经演示了如何使用
mem_-fun
,那么您在使用方面需要什么帮助?更好的标准是什么?
for_each(begin(threads), end(threads), mem_fn(&thread::join));