Lucien

std::for_each、std::mem_fn 备忘
#include <iostream> #include <thread> #includ...
扫描右侧二维码阅读全文
15
2019/03

std::for_each、std::mem_fn 备忘

#include <iostream>
#include <thread>
#include <vector>
#include <algorithm>
#include <functional>

int main() {
    std::vector<std::thread> threads;
    for (int i = 0; i < 10; i++) {
        threads.emplace_back([i] {
            for (int j = 0; j < 3; j++) printf("%d\n", i);
        });
    }
    std::for_each(threads.begin(), threads.end(), std::mem_fn(&std::thread::join));
    return 0;
}
Last modification:March 15th, 2019 at 10:37 am
谢谢老板!

Leave a Comment