Skip to content

Commit 75b46df

Browse files
committed
align try_push default forwarding and add coverage
1 parent 9e9e518 commit 75b46df

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

src/babylon/concurrent/bounded_queue.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -465,14 +465,14 @@ template <typename U, typename ::std::enable_if<
465465
::std::is_assignable<T&, U>::value, int>::type>
466466
inline bool ABSL_ATTRIBUTE_ALWAYS_INLINE
467467
ConcurrentBoundedQueue<T, S>::try_push(U&& value) noexcept {
468-
return try_push<true, true, true>(::std::forward<U>(value));
468+
return try_push<true, true>(::std::forward<U>(value));
469469
}
470470

471471
template <typename T, typename S>
472472
template <typename C, typename>
473473
inline bool ABSL_ATTRIBUTE_ALWAYS_INLINE
474474
ConcurrentBoundedQueue<T, S>::try_push(C&& callback) noexcept {
475-
return try_push<true, true, true>(::std::forward<C>(callback));
475+
return try_push<true, true>(::std::forward<C>(callback));
476476
}
477477

478478
template <typename T, typename S>

test/concurrent/test_bounded_queue.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,22 @@ TEST(concurrent_bounded_queue, try_pop_fail_on_empty) {
8585
ASSERT_EQ("10010", s);
8686
}
8787

88+
TEST(concurrent_bounded_queue, try_push_default_overload) {
89+
ConcurrentBoundedQueue<::std::string> queue(1);
90+
ASSERT_TRUE(queue.try_push("10086"));
91+
ASSERT_FALSE(queue.try_push("10010"));
92+
::std::string s;
93+
ASSERT_TRUE(queue.try_pop(s));
94+
ASSERT_EQ("10086", s);
95+
bool called = false;
96+
ASSERT_TRUE(queue.try_push([&](::std::string& value) {
97+
called = true;
98+
value = "10010";
99+
}));
100+
ASSERT_TRUE(called);
101+
ASSERT_TRUE(queue.try_pop(s));
102+
}
103+
88104
TEST(concurrent_bounded_queue, try_pop_wakeup_blocking_push) {
89105
ConcurrentBoundedQueue<::std::string> queue;
90106
queue.push("10086");

0 commit comments

Comments
 (0)