File tree Expand file tree Collapse file tree 2 files changed +11
-11
lines changed
Expand file tree Collapse file tree 2 files changed +11
-11
lines changed Original file line number Diff line number Diff line change 1010 for (int i=0; i < 100; i++) inc();
1111 };
1212 int main() {
13- std::thread t1( inc100) ;
14- std::thread t2( inc100) ;
13+ std::thread t1{ inc100} ;
14+ std::thread t2{ inc100} ;
1515 for (auto t: {&t1,&t2}) t->join();
16- std::cout << a << std::endl ;
16+ std::cout << a << "\n" ;
1717 }
1818 \end {cppcode* }
1919 \end {exampleblock }
Original file line number Diff line number Diff line change 1616 void foo() {...}
1717 void bar() {...}
1818 int main() {
19- std::thread t1( foo) ;
20- std::thread t2( bar) ;
19+ std::thread t1{ foo} ;
20+ std::thread t2{ bar} ;
2121 for (auto t: {&t1,&t2}) t->join();
2222 }
2323 \end {cppcode* }
2929 \begin {exampleblock }{Can take a function and its arguments}
3030 \begin {cppcode* }{}
3131 void function(int j, double j) {...};
32- std::thread t1( function, 1, 2.0) ;
32+ std::thread t1{ function, 1, 2.0} ;
3333 \end {cppcode* }
3434 \end {exampleblock }
3535 \pause
4040 int operator() (int j) const { return i+j; };
4141 int m_i;
4242 };
43- std::thread t2( AdderFunctor(2) , 5) ;
43+ std::thread t2{ AdderFunctor{2} , 5} ;
4444 int a;
45- std::thread t3( [](int i) { return i+2; }, a) ;
46- std::thread t4( [a] { return a+2; }) ;
45+ std::thread t3{ [](int i) { return i+2; }, a} ;
46+ std::thread t4{ [a] { return a+2; }} ;
4747 \end {cppcode* }
4848 \end {exampleblock }
4949\end {frame }
6868 \begin {cppcode* }{}
6969 int f() {...}
7070 std::future<int> res = std::async(f);
71- std::cout << res-> get();
71+ std::cout << res. get() << "\n" ;
7272 \end {cppcode* }
7373 \end {exampleblock }
7474\end {frame }
116116 \begin {exampleblock }{Usage}
117117 \begin {cppcode* }{}
118118 int f() { return 42; }
119- std::packaged_task<int()> task(f) ;
119+ std::packaged_task<int()> task{f} ;
120120 auto future = task.get_future();
121121 task();
122122 std::cout << future.get() << std::endl;
You can’t perform that action at this time.
0 commit comments