Extract Unit to top-level
authorYedidya Feldblum <yfeldblum@fb.com>
Wed, 18 May 2016 03:38:11 +0000 (20:38 -0700)
committerFacebook Github Bot 9 <facebook-github-bot-9-bot@fb.com>
Wed, 18 May 2016 03:53:39 +0000 (20:53 -0700)
Summary:
[Folly] Extract `Unit` to top-level.

It was in `folly/futures/`, but this diff moves it to `folly/`. It is needed for futures, but it is more general than futures and can be used separately.

Users must replace `folly/futures/Unit.h` with `folly/Unit.h`.

Also codemods existing usage sites:

```
hg grep -lw folly/futures/Unit.h | xargs perl -pi -e 's,\bfolly/futures/Unit\.h\b,folly/Unit.h,g'
```

Reviewed By: igorsugak

Differential Revision: D3314280

fbshipit-source-id: 16279b76b1d24529bec49077ccb36cd7d39f23b8

folly/Makefile.am
folly/Unit.h [new file with mode: 0644]
folly/futures/Timekeeper.h
folly/futures/Try.h
folly/futures/Unit.h [deleted file]
folly/futures/test/FutureTest.cpp
folly/futures/test/UnitTest.cpp [deleted file]
folly/test/Makefile.am
folly/test/UnitTest.cpp [new file with mode: 0644]

index 050588071b777ef6a20a83994f986fc3a5ea1bf8..bc7e42d4d38138a938ac2b005dc93c283d22addf 100644 (file)
@@ -175,7 +175,6 @@ nobase_follyinclude_HEADERS = \
        futures/Timekeeper.h \
        futures/Try-inl.h \
        futures/Try.h \
-       futures/Unit.h \
        futures/detail/Core.h \
        futures/detail/FSM.h \
        futures/detail/Types.h \
@@ -348,6 +347,7 @@ nobase_follyinclude_HEADERS = \
        Traits.h \
        Unicode.h \
        Function.h \
+       Unit.h \
        Uri.h \
        Uri-inl.h \
        Varint.h \
diff --git a/folly/Unit.h b/folly/Unit.h
new file mode 100644 (file)
index 0000000..cb6a656
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2016 Facebook, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <type_traits>
+
+namespace folly {
+
+/// In functional programming, the degenerate case is often called "unit". In
+/// C++, "void" is often the best analogue, however because of the syntactic
+/// special-casing required for void it is a liability for template
+/// metaprogramming. So, instead of e.g. Future<void>, we have Future<Unit>.
+/// You can ignore the actual value, and we port some of the syntactic
+/// niceties like setValue() instead of setValue(Unit{}).
+struct Unit {
+  template <typename T>
+  using Lift = std::conditional<std::is_same<T, void>::value, Unit, T>;
+  template <typename T>
+  using Drop = std::conditional<std::is_same<T, Unit>::value, void, T>;
+
+  bool operator==(const Unit& /*other*/) const { return true; }
+  bool operator!=(const Unit& /*other*/) const { return false; }
+};
+
+constexpr Unit unit {};
+
+}
index f8dc51c21790168798480c3c3662fbf36b3ea983..bdf978a8941d8bc0624c86c53fbc7483edfec8d1 100644 (file)
@@ -17,7 +17,7 @@
 #pragma once
 
 #include <folly/futures/detail/Types.h>
-#include <folly/futures/Unit.h>
+#include <folly/Unit.h>
 
 namespace folly {
 
index 5fae57f57295e24e4abf9f15bffea094620bf512..8d112a6087ab35755c42998d1d84b11243b24d5e 100644 (file)
@@ -24,7 +24,7 @@
 #include <folly/Memory.h>
 #include <folly/Portability.h>
 #include <folly/futures/FutureException.h>
-#include <folly/futures/Unit.h>
+#include <folly/Unit.h>
 
 namespace folly {
 
diff --git a/folly/futures/Unit.h b/folly/futures/Unit.h
deleted file mode 100644 (file)
index cb6a656..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright 2016 Facebook, Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-#include <type_traits>
-
-namespace folly {
-
-/// In functional programming, the degenerate case is often called "unit". In
-/// C++, "void" is often the best analogue, however because of the syntactic
-/// special-casing required for void it is a liability for template
-/// metaprogramming. So, instead of e.g. Future<void>, we have Future<Unit>.
-/// You can ignore the actual value, and we port some of the syntactic
-/// niceties like setValue() instead of setValue(Unit{}).
-struct Unit {
-  template <typename T>
-  using Lift = std::conditional<std::is_same<T, void>::value, Unit, T>;
-  template <typename T>
-  using Drop = std::conditional<std::is_same<T, Unit>::value, void, T>;
-
-  bool operator==(const Unit& /*other*/) const { return true; }
-  bool operator!=(const Unit& /*other*/) const { return false; }
-};
-
-constexpr Unit unit {};
-
-}
index 2f1eaf129796c302720b4cc07fad56fb34ec9759..8414370ca22fa7f1f69ba5701220afb5193def63 100644 (file)
@@ -17,7 +17,7 @@
 #include <gtest/gtest.h>
 
 #include <folly/futures/Future.h>
-#include <folly/futures/Unit.h>
+#include <folly/Unit.h>
 #include <folly/Memory.h>
 #include <folly/Executor.h>
 #include <folly/dynamic.h>
diff --git a/folly/futures/test/UnitTest.cpp b/folly/futures/test/UnitTest.cpp
deleted file mode 100644 (file)
index ba372fb..0000000
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Copyright 2016 Facebook, Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <gtest/gtest.h>
-
-#include <folly/futures/Unit.h>
-
-using namespace folly;
-
-TEST(Unit, operatorEq) {
-  EXPECT_TRUE(Unit{} == Unit{});
-}
-
-TEST(Unit, operatorNe) {
-  EXPECT_FALSE(Unit{} != Unit{});
-}
-
-TEST(Unit, liftInt) {
-  using lifted = Unit::Lift<int>;
-  using actual = std::is_same<int, lifted::type>;
-  EXPECT_TRUE(actual::value);
-}
-
-TEST(Unit, liftUnit) {
-  using lifted = Unit::Lift<Unit>;
-  using actual = std::is_same<Unit, lifted::type>;
-  EXPECT_TRUE(actual::value);
-}
-
-TEST(Unit, liftVoid) {
-  using lifted = Unit::Lift<void>;
-  using actual = std::is_same<Unit, lifted::type>;
-  EXPECT_TRUE(actual::value);
-}
-
-TEST(Unit, dropInt) {
-  using dropped = Unit::Drop<int>;
-  using actual = std::is_same<int, dropped::type>;
-  EXPECT_TRUE(actual::value);
-}
-
-TEST(Unit, dropUnit) {
-  using dropped = Unit::Drop<Unit>;
-  using actual = std::is_same<void, dropped::type>;
-  EXPECT_TRUE(actual::value);
-}
-
-TEST(Unit, dropVoid) {
-  using dropped = Unit::Drop<void>;
-  using actual = std::is_same<void, dropped::type>;
-  EXPECT_TRUE(actual::value);
-}
index 229efaf54be8273f8a9507880b77dfe8ce1e71b3..9932fe6150281b2a3c80286c8329d3ede03f4081 100644 (file)
@@ -215,6 +215,9 @@ indestructible_test_SOURCES = IndestructibleTest.cpp
 indestructible_test_LDADD = libfollytestmain.la
 TESTS += indestructible_test
 
+unit_test_SOURCES = UnitTest.cpp
+unit_test_LDADD = libfollytestmain.la
+TESTS += unit_test
 
 futures_test_SOURCES = \
     ../futures/test/CollectTest.cpp \
@@ -242,7 +245,6 @@ futures_test_SOURCES = \
     ../futures/test/TimekeeperTest.cpp \
     ../futures/test/TimesTest.cpp \
     ../futures/test/TryTest.cpp \
-    ../futures/test/UnitTest.cpp \
     ../futures/test/UnwrapTest.cpp \
     ../futures/test/ViaTest.cpp \
     ../futures/test/WaitTest.cpp \
diff --git a/folly/test/UnitTest.cpp b/folly/test/UnitTest.cpp
new file mode 100644 (file)
index 0000000..18ff4ab
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2016 Facebook, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <gtest/gtest.h>
+
+#include <folly/Unit.h>
+
+using namespace folly;
+
+TEST(Unit, operatorEq) {
+  EXPECT_TRUE(Unit{} == Unit{});
+}
+
+TEST(Unit, operatorNe) {
+  EXPECT_FALSE(Unit{} != Unit{});
+}
+
+TEST(Unit, liftInt) {
+  using lifted = Unit::Lift<int>;
+  using actual = std::is_same<int, lifted::type>;
+  EXPECT_TRUE(actual::value);
+}
+
+TEST(Unit, liftUnit) {
+  using lifted = Unit::Lift<Unit>;
+  using actual = std::is_same<Unit, lifted::type>;
+  EXPECT_TRUE(actual::value);
+}
+
+TEST(Unit, liftVoid) {
+  using lifted = Unit::Lift<void>;
+  using actual = std::is_same<Unit, lifted::type>;
+  EXPECT_TRUE(actual::value);
+}
+
+TEST(Unit, dropInt) {
+  using dropped = Unit::Drop<int>;
+  using actual = std::is_same<int, dropped::type>;
+  EXPECT_TRUE(actual::value);
+}
+
+TEST(Unit, dropUnit) {
+  using dropped = Unit::Drop<Unit>;
+  using actual = std::is_same<void, dropped::type>;
+  EXPECT_TRUE(actual::value);
+}
+
+TEST(Unit, dropVoid) {
+  using dropped = Unit::Drop<void>;
+  using actual = std::is_same<void, dropped::type>;
+  EXPECT_TRUE(actual::value);
+}