Revert "[folly::gen] Prevent accidental moves in filter()"
authorKristen Parton <kparton@fb.com>
Wed, 19 Aug 2015 04:53:36 +0000 (21:53 -0700)
committerfacebook-github-bot-9 <folly-bot@fb.com>
Wed, 19 Aug 2015 05:20:19 +0000 (22:20 -0700)
Summary: This reverts commit aee49bc8a945db9ad6c0ef6a9598ca5c44a4dc8c.

Temporarily reverting the previous diff to investigate possible downstream regression.

Reviewed By: @yfeldblum

Differential Revision: D2359864

folly/gen/Base-inl.h
folly/gen/test/BaseTest.cpp

index 23b919735a52ec5c8547aff4c979a12376315bed..0c4e92f4556959aff2f6a17d994eb595e86c9ae3 100644 (file)
@@ -559,8 +559,7 @@ class Filter : public Operator<Filter<Predicate>> {
     template <class Body>
     void foreach(Body&& body) const {
       source_.foreach([&](Value value) {
-        // NB: Argument not forwarded to avoid accidental move-construction
-        if (pred_(value)) {
+        if (pred_(std::forward<Value>(value))) {
           body(std::forward<Value>(value));
         }
       });
@@ -569,8 +568,7 @@ class Filter : public Operator<Filter<Predicate>> {
     template <class Handler>
     bool apply(Handler&& handler) const {
       return source_.apply([&](Value value) -> bool {
-        // NB: Argument not forwarded to avoid accidental move-construction
-        if (pred_(value)) {
+        if (pred_(std::forward<Value>(value))) {
           return handler(std::forward<Value>(value));
         }
         return true;
index e97cf6c39db9f482f87e64965a03907162aabb38..7741b053fb52695f72ccdae8d67e1269eac7122d 100644 (file)
@@ -289,15 +289,6 @@ TEST(Gen, FilterDefault) {
   }
 }
 
-TEST(Gen, FilterSink) {
-  auto actual
-    = seq(1, 2)
-    | map([](int x) { return vector<int>{x}; })
-    | filter([](vector<int> v) { return !v.empty(); })
-    | as<vector>();
-  EXPECT_FALSE(from(actual) | rconcat | isEmpty);
-}
-
 TEST(Gen, Contains) {
   {
     auto gen =