FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
wait-queue/example/wait_queue_example.cpp at main · connectivecpp/wait-queue · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
connectivecpp
/
wait-queue
Public
Notifications
You must be signed in to change notification settings
Fork
1
Star
1
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
wait-queue
/
example
/
wait_queue_example.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
76 lines (64 loc) · 2.17 KB
Breadcrumbs
wait-queue
/
example
/
wait_queue_example.cpp
Copy path
File metadata and controls
76 lines (64 loc) · 2.17 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
* @file
*
* @brief Example code demonstrating use of @c chops::wait_queue.
* See @c threaded_wait_shared_demo.cpp for multithreaded example.
*
* @author Thurman Gillespy
*
* @copyright (c) 2019 by Thurman Gillespy
* 3/22/19
*
* Minor changes May 2024 by Cliff Green to match new @c wait_queue API.
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
*
* Sample make file:
* g++ -std=c++17 -I ~/Projects/utility-rack/include/ wait_queue_demo.cpp
*
* This also builds under CMake, with C++ 20 specified.
*/
#
include
<
iostream
>
#
include
<
ios
>
//
std::boolalpha
#
include
<
cstdlib
>
//
EXIT_SUCCESS
#
include
<
string
>
#
include
<
optional
>
//
std::optional
#
include
"
queue/wait_queue.hpp
"
//
print queue stats
void
queueState
(
const
chops::wait_queue<
int
>& wq) {
std::cout << std::boolalpha;
std::cout <<
"
wait queue contains
"
<< wq.
size
() <<
"
elements
"
<< std::endl;
std::cout <<
"
wait queue is empty:
"
<< wq.
empty
() << std::endl;
std::cout <<
"
wait queue stop requested:
"
<< wq.
stop_requested
() << std::endl;
std::cout << std::endl;
}
//
tasty lambda utilities
constexpr
auto
printStr = [] (
const
std::string& s) { std::cout << s << std::endl; };
constexpr
auto
printLn = [] () { std::cout << std::endl; };
int
main
() {
//
create a new (empty) queue
printStr
(
"
create new wait queue
"
);
printLn
();
chops::wait_queue<
int
> wq;
queueState
(wq);
//
put some values in the queue
printStr
(
"
pushing elements onto the queue...
"
);
wq.
push
(
42
); wq.
push
(
22
); wq.
push
(
102
); wq.
push
(-
12
); wq.
push
(
17
);
queueState
(wq);
//
print all the values
printStr
(
"
print all the values in queue
"
);
wq.
apply
([] (
int
elem) { std::cout << elem <<
"
"
; });
printLn
();
//
remove the elements
printStr
(
"
pop (and remove) each element from the queue
"
);
auto
num_elements = wq.
size
();
while
(num_elements-- >
0
) {
auto
result = wq.
try_pop
();
//
std::optional<int>
if
(result) {
std::cout << result.
value
() <<
"
"
;
}
}
printLn
();
queueState
(wq);
return
EXIT_SUCCESS
;
}
Back
|
FazBrowse Home
|
New Git URL