From 712ac5310b6f3d064219bf4db2a4af3a98362c12 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Wed, 30 Sep 2026 15:27:43 +0200 Subject: kstd: ring_buffer: implement max_size() --- libs/kstd/kstd/ring_buffer.hpp | 11 +++++++++++ libs/kstd/kstd/ring_buffer.tests.cpp | 5 +++++ 2 files changed, 16 insertions(+) (limited to 'libs') diff --git a/libs/kstd/kstd/ring_buffer.hpp b/libs/kstd/kstd/ring_buffer.hpp index 63ca94a1..427b31df 100644 --- a/libs/kstd/kstd/ring_buffer.hpp +++ b/libs/kstd/kstd/ring_buffer.hpp @@ -23,6 +23,17 @@ namespace kstd return Capacity; } + //! Get the maximum number of elements this ring buffer can hold. + //! + //! Due to ring_buffer being a fixed-size container, this function will return the same value as capacity. This + //! function is provided for API compatibility with standard library functions. + //! + //! @return The theoretical maximum number of elements that can fit in this ring buffer. + [[nodiscard]] constexpr auto max_size() 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 f661b50e..f693b0a8 100644 --- a/libs/kstd/kstd/ring_buffer.tests.cpp +++ b/libs/kstd/kstd/ring_buffer.tests.cpp @@ -14,6 +14,11 @@ SCENARIO("Ring Buffer initialization and construction", "[ring_buffer]") { REQUIRE(buffer.capacity() == 5); } + + THEN("the maximum size is equal to the capacity") + { + REQUIRE(buffer.max_size() == buffer.capacity()); + } } } } \ No newline at end of file -- cgit v1.2.3