Rephrase Optional usage to quite warnings
authorTom Jackson <tjackson@fb.com>
Thu, 1 Jun 2017 15:44:32 +0000 (08:44 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Thu, 1 Jun 2017 15:51:42 +0000 (08:51 -0700)
Reviewed By: yfeldblum

Differential Revision: D5105818

fbshipit-source-id: e3926a0c70a68855e0180bdd44cb0ec76e66bb94

folly/gen/Base-inl.h

index 2245bf0..66d2b92 100644 (file)
@@ -1866,8 +1866,8 @@ class Reduce : public Operator<Reduce<Reducer>> {
     static_assert(!Source::infinite, "Cannot reduce infinite source");
     Optional<StorageType> accum;
     source | [&](Value v) {
-      if (accum.hasValue()) {
-        accum = reducer_(std::move(accum.value()), std::forward<Value>(v));
+      if (auto target = accum.get_pointer()) {
+        *target = reducer_(std::move(*target), std::forward<Value>(v));
       } else {
         accum = std::forward<Value>(v);
       }
@@ -1990,10 +1990,13 @@ class Min : public Operator<Min<Selector, Comparer>> {
     Optional<Key> 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<Value>(v);
+      if (auto lastKey = minKey.get_pointer()) {
+        if (!comparer_(key, *lastKey)) {
+          return;
+        }
       }
+      minKey = std::move(key);
+      min = std::forward<Value>(v);
     };
     return min;
   }