From b2a39c22a86196128a8b67472b67b320c3e01c04 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Wed, 30 Sep 2026 15:23:15 +0200 Subject: kstd: ring_buffer: implement capacity() --- libs/kstd/kstd/ring_buffer.hpp | 10 ++++++++++ libs/kstd/kstd/ring_buffer.tests.cpp | 10 ++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) (limited to 'libs/kstd') diff --git a/libs/kstd/kstd/ring_buffer.hpp b/libs/kstd/kstd/ring_buffer.hpp index 0ceb634d..63ca94a1 100644 --- a/libs/kstd/kstd/ring_buffer.hpp +++ b/libs/kstd/kstd/ring_buffer.hpp @@ -13,6 +13,16 @@ namespace kstd template struct ring_buffer { + using size_type = std::size_t; + + //! Get the maximum number of elements this ring buffer can hold. + //! + //! @return The number of elements that can fit in this ring buffer. + [[nodiscard]] constexpr auto capacity() const noexcept -> size_type + { + return Capacity; + } + }; } // namespace kstd diff --git a/libs/kstd/kstd/ring_buffer.tests.cpp b/libs/kstd/kstd/ring_buffer.tests.cpp index 3608d5ce..f661b50e 100644 --- a/libs/kstd/kstd/ring_buffer.tests.cpp +++ b/libs/kstd/kstd/ring_buffer.tests.cpp @@ -2,16 +2,18 @@ #include -#include - SCENARIO("Ring Buffer initialization and construction", "[ring_buffer]") { GIVEN("An empty context") { - WHEN("constructing by default") + WHEN("constructing by default using a capacity of 5") { auto buffer = kstd::ring_buffer{}; - std::ignore = buffer; + + THEN("the capacity is 5") + { + REQUIRE(buffer.capacity() == 5); + } } } } \ No newline at end of file -- cgit v1.2.3