From 3544d9c12fcb66ff8d4dd947137a769eb99f26c2 Mon Sep 17 00:00:00 2001 From: Johannes Stoelp Date: Tue, 19 Mar 2024 21:51:30 +0100 Subject: ring: add pre cpp17 take() fn --- ring.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'ring.h') diff --git a/ring.h b/ring.h index 3658ec4..43c3fca 100644 --- a/ring.h +++ b/ring.h @@ -99,12 +99,19 @@ class ring { #if __cplusplus >= 201703L constexpr std::optional take() { if (!is_empty()) { - const std::optional kRet = std::move(vals[m_rc & kMASK]); + std::optional 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 --------------------------------------------------------------- -- cgit v1.2.3