aboutsummaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
Diffstat (limited to 'libs')
-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