From: Chip Turner Date: Sat, 31 Jan 2015 03:51:20 +0000 (-0800) Subject: Revert "[folly::gen] Making 'just()' reference arguments like 'from()'" X-Git-Tag: v0.23.0~3 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=ba7fdc792ce8168962af15ba20a1eef00c1ea7ce;p=folly.git Revert "[folly::gen] Making 'just()' reference arguments like 'from()'" Summary: This reverts commit 90da92b05762f8032560d0d6a66237ab2772d7f2. Test Plan: compiles Reviewed By: tjackson@fb.com Subscribers: lins, anca, folly-diffs@, yfeldblum FB internal diff: D1817376 Tasks: 6118752 --- diff --git a/folly/gen/Base-inl.h b/folly/gen/Base-inl.h index e04c246c..083cf979 100644 --- a/folly/gen/Base-inl.h +++ b/folly/gen/Base-inl.h @@ -328,32 +328,13 @@ class Empty : public GenImpl> { void foreach(Body&&) const {} }; -template -class SingleReference : public GenImpl> { - static_assert(!std::is_reference::value, - "SingleReference requires non-ref types"); - Value* ptr_; - public: - explicit SingleReference(Value* ptr) : ptr_(ptr){} - - template - bool apply(Handler&& handler) const { - return handler(*ptr_); - } - - template - void foreach(Body&& body) const { - body(*ptr_); - } -}; - -template -class SingleCopy : public GenImpl> { +template +class Just : public GenImpl> { static_assert(!std::is_reference::value, - "SingleCopy requires non-ref types"); - Value value_; + "Just requires non-ref types"); + const Value value_; public: - explicit SingleCopy(Value value) : value_(std::forward(value)) {} + explicit Just(Value value) : value_(std::forward(value)) {} template bool apply(Handler&& handler) const { diff --git a/folly/gen/Base.h b/folly/gen/Base.h index bf9b4b53..12d917ed 100644 --- a/folly/gen/Base.h +++ b/folly/gen/Base.h @@ -297,10 +297,7 @@ template class Empty; template -class SingleReference; - -template -class SingleCopy; +class Just; /* * Operators @@ -485,25 +482,14 @@ Yield generator(Source&& source) { /* * empty() - for producing empty sequences. */ -template +template detail::Empty empty() { return {}; } -template > -Just just(Value& value) { - return Just(&value); -} - -template > -Just just(const Value& value) { - return Just(&value); -} - -template ::type>> -Just just(Value&& value) { - return Just(std::move(value)); +template +detail::Just just(Value value) { + return detail::Just(std::move(value)); } /* diff --git a/folly/gen/Parallel-inl.h b/folly/gen/Parallel-inl.h index 06f1af01..666acb16 100644 --- a/folly/gen/Parallel-inl.h +++ b/folly/gen/Parallel-inl.h @@ -136,7 +136,7 @@ class Sub : public Operator> { class Source, class Result = decltype(std::declval().compose(std::declval())), - class Just = SingleCopy::type>> + class Just = Just::type>> Just compose(const GenImpl& source) const { return Just(source | sink_); } diff --git a/folly/gen/test/BaseTest.cpp b/folly/gen/test/BaseTest.cpp index d403d99d..2b99f157 100644 --- a/folly/gen/test/BaseTest.cpp +++ b/folly/gen/test/BaseTest.cpp @@ -1073,31 +1073,6 @@ TEST(Gen, BatchMove) { EXPECT_EQ(expected, actual); } -TEST(Gen, Just) { - { - int x = 3; - auto j = just(x); - EXPECT_EQ(&x, j | mapped([](const int& v) { return &v; }) | first); - x = 4; - EXPECT_EQ(4, j | first); - } - { - int x = 3; - const int& cx = x; - auto j = just(cx); - EXPECT_EQ(&x, j | mapped([](const int& v) { return &v; }) | first); - x = 5; - EXPECT_EQ(5, j | first); - } - { - int x = 3; - auto j = just(std::move(x)); - EXPECT_NE(&x, j | mapped([](const int& v) { return &v; }) | first); - x = 5; - EXPECT_EQ(3, j | first); - } -} - int main(int argc, char *argv[]) { testing::InitGoogleTest(&argc, argv); gflags::ParseCommandLineFlags(&argc, &argv, true);