-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpass_copy_reference.cpp
More file actions
39 lines (31 loc) · 1.08 KB
/
pass_copy_reference.cpp
File metadata and controls
39 lines (31 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <functional>
#include <memory>
#include <print>
#include <ranges>
#include <scl/safe_thread.h>
using namespace std::literals;
void entry_point (int tid)
{
std::println ("{}", tid);
}
static_assert(std::is_function_v<decltype(entry_point)>);
static_assert(! std::is_object_v<decltype(entry_point)>);
static_assert(! std::is_member_function_pointer_v<decltype(entry_point)>);
static_assert(! std::is_pointer_v<decltype(entry_point)>);
static_assert(scl::is_function_pointer_v<std::decay_t<decltype(entry_point)>>
&& ! std::is_member_function_pointer_v<decltype(entry_point)>);
static_assert(scl::is_function_pointer_v<std::decay_t<decltype(entry_point)>>
&& ! std::is_member_function_pointer_v<decltype(entry_point)>);
int main()
{
std::vector<scl::thread> threads { };
{
// Launch all threads.
const int num_threads = 15;
for (int i : std::views::iota (0, num_threads))
threads.push_back (scl::thread (entry_point, auto (i)));
}
// Join all threads.
for (scl::thread& t : threads)
t.join();
}