From 4ae89dde442b84eb4501365f7cb0cfe8ffb0ed2d Mon Sep 17 00:00:00 2001 From: Tom Jackson Date: Thu, 1 Jun 2017 08:44:32 -0700 Subject: [PATCH] Rephrase Optional usage to quite warnings Reviewed By: yfeldblum Differential Revision: D5105818 fbshipit-source-id: e3926a0c70a68855e0180bdd44cb0ec76e66bb94 --- folly/gen/Base-inl.h | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/folly/gen/Base-inl.h b/folly/gen/Base-inl.h index 2245bf08..66d2b92c 100644 --- a/folly/gen/Base-inl.h +++ b/folly/gen/Base-inl.h @@ -1866,8 +1866,8 @@ class Reduce : public Operator> { static_assert(!Source::infinite, "Cannot reduce infinite source"); Optional accum; source | [&](Value v) { - if (accum.hasValue()) { - accum = reducer_(std::move(accum.value()), std::forward(v)); + if (auto target = accum.get_pointer()) { + *target = reducer_(std::move(*target), std::forward(v)); } else { accum = std::forward(v); } @@ -1990,10 +1990,13 @@ class Min : public Operator> { Optional minKey; source | [&](Value v) { Key key = selector_(asConst(v)); // so that selector_ cannot mutate v - if (!minKey.hasValue() || comparer_(key, minKey.value())) { - minKey = std::move(key); - min = std::forward(v); + if (auto lastKey = minKey.get_pointer()) { + if (!comparer_(key, *lastKey)) { + return; + } } + minKey = std::move(key); + min = std::forward(v); }; return min; } -- 2.34.1