diff options
author | Johannes Stoelp <johannes.stoelp@gmail.com> | 2024-03-19 21:51:30 +0100 |
---|---|---|
committer | Johannes Stoelp <johannes.stoelp@gmail.com> | 2024-03-19 21:51:30 +0100 |
commit | 3544d9c12fcb66ff8d4dd947137a769eb99f26c2 (patch) | |
tree | e870d52f7189141283840de348b9ded770a6cc4e /ring.h | |
parent | 9f051299964628452a10b80fff7b372e42b4fa32 (diff) | |
download | cpp-utils-3544d9c12fcb66ff8d4dd947137a769eb99f26c2.tar.gz cpp-utils-3544d9c12fcb66ff8d4dd947137a769eb99f26c2.zip |
ring: add pre cpp17 take() fn
Diffstat (limited to 'ring.h')
-rw-r--r-- | ring.h | 11 |
1 files changed, 9 insertions, 2 deletions
@@ -99,12 +99,19 @@ class ring { #if __cplusplus >= 201703L constexpr std::optional<T> take() { if (!is_empty()) { - const std::optional<T> kRet = std::move(vals[m_rc & kMASK]); + std::optional<T> ret = std::move(vals[m_rc & kMASK]); pop(); - return kRet; + return ret; } return std::nullopt; } +#else + constexpr T take() { + assert(!is_empty()); + T ret = std::move(vals[m_rc & kMASK]); + pop(); + return ret; + } #endif // -- INTERNAL --------------------------------------------------------------- |