@@ -309,11 +309,14 @@ class wait_queue {
309
309
* external @c std::stop_token was passed in.
310
310
*
311
311
*/
312
- bool request_stop () noexcept {
312
+ auto request_stop () noexcept
313
+ -> bool {
314
+
313
315
if (m_stop_src) {
314
316
return (*m_stop_src).request_stop ();
315
317
}
316
318
return false ;
319
+
317
320
}
318
321
319
322
/* *
@@ -327,14 +330,17 @@ class wait_queue {
327
330
* @return @c true if successful, @c false if the @c wait_queue has been
328
331
* requested to stop.
329
332
*/
330
- bool push (const T& val) /* noexcept(std::is_nothrow_copy_constructible<T>::value) */ {
333
+ auto push (const T& val) /* noexcept(std::is_nothrow_copy_constructible<T>::value) */
334
+ -> bool {
335
+
331
336
if (m_stop_tok.stop_requested ()) {
332
337
return false ;
333
338
}
334
339
lock_guard lk{m_mut};
335
340
m_data_queue.push_back (val);
336
341
m_data_cond.notify_one ();
337
342
return true ;
343
+
338
344
}
339
345
340
346
/* *
@@ -343,14 +349,17 @@ class wait_queue {
343
349
* This method has the same semantics as the other @c push, except that the value will
344
350
* be moved (if possible) instead of copied.
345
351
*/
346
- bool push (T&& val) /* noexcept(std::is_nothrow_move_constructible<T>::value) */ {
352
+ auto push (T&& val) /* noexcept(std::is_nothrow_move_constructible<T>::value) */
353
+ -> bool {
354
+
347
355
if (m_stop_tok.stop_requested ()) {
348
356
return false ;
349
357
}
350
358
lock_guard lk{m_mut};
351
359
m_data_queue.push_back (std::move (val));
352
360
m_data_cond.notify_one ();
353
361
return true ;
362
+
354
363
}
355
364
356
365
/* *
@@ -367,14 +376,17 @@ class wait_queue {
367
376
* to stop.
368
377
*/
369
378
template <typename ... Args>
370
- bool emplace_push (Args &&... args) /* noexcept(std::is_nothrow_constructible<T, Args...>::value)*/ {
379
+ auto emplace_push (Args &&... args) /* noexcept(std::is_nothrow_constructible<T, Args...>::value)*/
380
+ -> bool {
381
+
371
382
if (m_stop_tok.stop_requested ()) {
372
383
return false ;
373
384
}
374
385
lock_guard lk{m_mut};
375
386
m_data_queue.emplace_back (std::forward<Args>(args)...);
376
387
m_data_cond.notify_one ();
377
388
return true ;
389
+
378
390
}
379
391
380
392
/* *
@@ -388,14 +400,17 @@ class wait_queue {
388
400
* @return A value from the @c wait_queue (if non-empty). If the @c std::optional is empty,
389
401
* the @c wait_queue has been requested to be stopped.
390
402
*/
391
- std::optional<T> wait_and_pop () /* noexcept(std::is_nothrow_constructible<T>::value) */ {
403
+ auto wait_and_pop () /* noexcept(std::is_nothrow_constructible<T>::value) */
404
+ -> std::optional<T> {
405
+
392
406
std::unique_lock<std::mutex> lk{m_mut};
393
407
if (!m_data_cond.wait ( lk, m_stop_tok, [this ] { return !m_data_queue.empty (); } )) {
394
408
return std::optional<T> {}; // queue was request to stop, no data available
395
409
}
396
410
std::optional<T> val {std::move_if_noexcept (m_data_queue.front ())}; // move construct if possible
397
411
m_data_queue.pop_front ();
398
412
return val;
413
+
399
414
}
400
415
401
416
/* *
@@ -406,7 +421,9 @@ class wait_queue {
406
421
* available in the @c wait_queue or if the @c wait_queue has been requested to be
407
422
* stopped .
408
423
*/
409
- std::optional<T> try_pop () /* noexcept(std::is_nothrow_constructible<T>::value) */ {
424
+ auto try_pop () /* noexcept(std::is_nothrow_constructible<T>::value) */
425
+ -> std::optional<T> {
426
+
410
427
if (m_stop_tok.stop_requested ()) {
411
428
return std::optional<T> {};
412
429
}
@@ -417,6 +434,7 @@ class wait_queue {
417
434
std::optional<T> val {std::move_if_noexcept (m_data_queue.front ())}; // move construct if possible
418
435
m_data_queue.pop_front ();
419
436
return val;
437
+
420
438
}
421
439
422
440
// non-modifying methods
@@ -447,11 +465,14 @@ class wait_queue {
447
465
* same @c wait_queue since it results in recursive mutex locks.
448
466
*/
449
467
template <typename F>
450
- void apply (F&& func) const /* noexcept(std::is_nothrow_invocable<F&&, const T&>::value) */ {
468
+ auto apply (F&& func) const /* noexcept(std::is_nothrow_invocable<F&&, const T&>::value) */
469
+ -> void {
470
+
451
471
lock_guard lk{m_mut};
452
472
for (const T& elem : m_data_queue) {
453
473
func (elem);
454
474
}
475
+
455
476
}
456
477
457
478
/* *
@@ -460,28 +481,37 @@ class wait_queue {
460
481
*
461
482
* @return @c true if the @c stop_requested has been called.
462
483
*/
463
- bool stop_requested () const noexcept {
484
+ auto stop_requested () const noexcept
485
+ -> bool {
486
+
464
487
return m_stop_tok.stop_requested ();
488
+
465
489
}
466
490
467
491
/* *
468
492
* Query whether the @c wait_queue is empty or not.
469
493
*
470
494
* @return @c true if the @c wait_queue is empty.
471
495
*/
472
- bool empty () const /* noexcept */ {
496
+ auto empty () const /* noexcept */
497
+ -> bool {
498
+
473
499
lock_guard lk{m_mut};
474
500
return m_data_queue.empty ();
501
+
475
502
}
476
503
477
504
/* *
478
505
* Get the number of elements in the @c wait_queue.
479
506
*
480
507
* @return Number of elements in the @c wait_queue.
481
508
*/
482
- size_type size () const /* noexcept */ {
509
+ auto size () const /* noexcept */
510
+ -> size_type {
511
+
483
512
lock_guard lk{m_mut};
484
513
return m_data_queue.size ();
514
+
485
515
}
486
516
487
517
};
0 commit comments