-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpass_move_reference.cpp
More file actions
45 lines (36 loc) · 1.28 KB
/
pass_move_reference.cpp
File metadata and controls
45 lines (36 loc) · 1.28 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
40
41
42
43
44
45
#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);
}
using T = decltype(entry_point);
static_assert (std::is_pointer_v<std::remove_extent_t<std::decay_t<T>>>);
static_assert (scl::is_function_pointer_v<std::decay_t<T>>);
static_assert (! (std::is_pointer_v<std::remove_extent_t<std::decay_t<T>>>
&& ! scl::is_function_pointer_v<std::decay_t<T>>));
static_assert (! std::is_member_function_pointer_v<T>);
static_assert (! std::is_move_constructible_v<T>);
static_assert (scl::is_function_pointer_v<std::decay_t<T>>
&& ! std::is_member_function_pointer_v<std::decay_t<T>>);
static_assert (! scl::is_sync_v<T>);
static_assert(std::is_function_v<void (int)>);
static_assert(std::is_function_v<std::remove_cvref_t<void (&)(int)>>);
//======================================================
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, std::move (i)));
}
// Join all threads.
for (scl::thread& t : threads)
t.join();
}