aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ring.h11
-rw-r--r--test/ring.cc4
2 files changed, 11 insertions, 4 deletions
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<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 ---------------------------------------------------------------
diff --git a/test/ring.cc b/test/ring.cc
index a42efaa..657fdfa 100644
--- a/test/ring.cc
+++ b/test/ring.cc
@@ -56,14 +56,14 @@ int main() {
assert(!r.is_empty());
assert(r.is_full());
-#if __cplusplus >= 201703L
auto v = r.take();
+#if __cplusplus >= 201703L
assert(v.has_value());
+#endif
assert(r.size() == 7);
assert(!r.is_empty());
assert(!r.is_full());
-#endif
assert(m::cnt == 8);
}