aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@ost.ch>2026-09-30 15:27:43 +0200
committerFelix Morgner <felix.morgner@ost.ch>2026-09-30 15:29:01 +0200
commit712ac5310b6f3d064219bf4db2a4af3a98362c12 (patch)
treef3104526c88bc3bfea7ae40ad8e113d34dd596c2
parentb2a39c22a86196128a8b67472b67b320c3e01c04 (diff)
downloadkernel-712ac5310b6f3d064219bf4db2a4af3a98362c12.tar.xz
kernel-712ac5310b6f3d064219bf4db2a4af3a98362c12.zip
kstd: ring_buffer: implement max_size()
-rw-r--r--libs/kstd/kstd/ring_buffer.hpp11
-rw-r--r--libs/kstd/kstd/ring_buffer.tests.cpp5
2 files changed, 16 insertions, 0 deletions
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