diff options
| author | Felix Morgner <felix.morgner@ost.ch> | 2026-09-30 15:23:15 +0200 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@ost.ch> | 2026-09-30 15:27:07 +0200 |
| commit | b2a39c22a86196128a8b67472b67b320c3e01c04 (patch) | |
| tree | ae5c95248b820e51b2eb375c87bf73069234fd02 /libs/kstd | |
| parent | 6959a83b7d7e6a272cfd626fa3799a875460f5ea (diff) | |
| download | kernel-b2a39c22a86196128a8b67472b67b320c3e01c04.tar.xz kernel-b2a39c22a86196128a8b67472b67b320c3e01c04.zip | |
kstd: ring_buffer: implement capacity()
Diffstat (limited to 'libs/kstd')
| -rw-r--r-- | libs/kstd/kstd/ring_buffer.hpp | 10 | ||||
| -rw-r--r-- | libs/kstd/kstd/ring_buffer.tests.cpp | 10 |
2 files changed, 16 insertions, 4 deletions
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<typename ValueType, std::size_t Capacity> 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 <catch2/catch_test_macros.hpp> -#include <tuple> - 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<int, 5>{}; - std::ignore = buffer; + + THEN("the capacity is 5") + { + REQUIRE(buffer.capacity() == 5); + } } } }
\ No newline at end of file |
