Skip to content

Commit 775afba

Browse files
committed
semaphore::max() is static
* Previously this function wasn't static and would need to be called with the templated max_value, which isn't very useful. * Users can now call as semaphore<64> s{32}; s.max(); to retreive the max value. Closes #383
1 parent fc5610c commit 775afba

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

include/coro/semaphore.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ class semaphore
141141
/**
142142
* @return The maximum number of resources the semaphore can contain.
143143
*/
144-
[[nodiscard]] constexpr auto max() const noexcept -> std::ptrdiff_t { return max_value; }
144+
[[nodiscard]] static constexpr auto max() noexcept -> std::ptrdiff_t { return max_value; }
145145

146146
/**
147147
* The current number of resources available in this semaphore.

test/test_semaphore.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,18 @@ TEST_CASE("semaphore 1 producers and many consumers", "[semaphore]")
275275
std::cerr << "END semaphore 1 producers and many consumers\n";
276276
}
277277

278+
TEST_CASE("semaphore max()", "[semaphore]")
279+
{
280+
std::cerr << "BEGIN semaphore max()\n";
281+
282+
coro::semaphore<64> s{32};
283+
284+
REQUIRE(s.max() == 64);
285+
REQUIRE(s.value() == 32);
286+
287+
std::cerr << "END semaphore max()\n";
288+
}
289+
278290
TEST_CASE("~semaphore", "[semaphore]")
279291
{
280292
std::cerr << "[~semaphore]\n\n";

0 commit comments

Comments
 (0)