Move folly/Array.h
authorYedidya Feldblum <yfeldblum@fb.com>
Sun, 29 Oct 2017 10:33:10 +0000 (03:33 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Sun, 29 Oct 2017 10:40:32 +0000 (03:40 -0700)
Summary: [Folly] Move `folly/Array.h` to `folly/container/`.

Reviewed By: luciang

Differential Revision: D6182858

fbshipit-source-id: 59340b96058cc6d0c7a0289e316bbde98c15d724

folly/Array.h [deleted file]
folly/Makefile.am
folly/container/Array.h [new file with mode: 0644]
folly/container/test/ArrayTest.cpp [new file with mode: 0644]
folly/gen/test/FileTest.cpp
folly/io/async/SSLOptions.h
folly/test/ArrayTest.cpp [deleted file]
folly/test/Makefile.am
folly/test/SocketAddressTest.cpp
folly/test/StringTest.cpp

diff --git a/folly/Array.h b/folly/Array.h
deleted file mode 100644 (file)
index 8b2e7c0..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Copyright 2017 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 <folly/Traits.h>
-#include <array>
-#include <type_traits>
-#include <utility>
-
-namespace folly {
-
-namespace array_detail {
-template <typename>
-struct is_ref_wrapper : std::false_type {};
-template <typename T>
-struct is_ref_wrapper<std::reference_wrapper<T>> : std::true_type {};
-
-template <typename T>
-using not_ref_wrapper =
-    folly::Negation<is_ref_wrapper<typename std::decay<T>::type>>;
-
-template <typename D, typename...>
-struct return_type_helper {
-  using type = D;
-};
-template <typename... TList>
-struct return_type_helper<void, TList...> {
-  static_assert(
-      folly::Conjunction<not_ref_wrapper<TList>...>::value,
-      "TList cannot contain reference_wrappers when D is void");
-  using type = typename std::common_type<TList...>::type;
-};
-
-template <typename D, typename... TList>
-using return_type = std::
-    array<typename return_type_helper<D, TList...>::type, sizeof...(TList)>;
-} // namespace array_detail
-
-template <typename D = void, typename... TList>
-constexpr array_detail::return_type<D, TList...> make_array(TList&&... t) {
-  using value_type =
-      typename array_detail::return_type_helper<D, TList...>::type;
-  return {{static_cast<value_type>(std::forward<TList>(t))...}};
-}
-
-} // namespace folly
index dafdd730431ec21d6abd08dd6d17d7c6941b0612..a35a4a946e5424b5d3b534a565e550add7b9c82c 100644 (file)
@@ -27,7 +27,6 @@ lib_LTLIBRARIES = \
 follyincludedir = $(includedir)/folly
 
 nobase_follyinclude_HEADERS = \
-       Array.h \
        Assume.h \
        AtomicBitSet.h \
        AtomicHashArray.h \
@@ -58,6 +57,7 @@ nobase_follyinclude_HEADERS = \
        concurrency/ConcurrentHashMap.h \
        concurrency/CoreCachedSharedPtr.h \
        concurrency/detail/ConcurrentHashMap-detail.h \
+       container/Array.h \
        container/Iterator.h \
        container/Enumerate.h \
        container/EvictingCacheMap.h \
diff --git a/folly/container/Array.h b/folly/container/Array.h
new file mode 100644 (file)
index 0000000..8b2e7c0
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2017 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 <folly/Traits.h>
+#include <array>
+#include <type_traits>
+#include <utility>
+
+namespace folly {
+
+namespace array_detail {
+template <typename>
+struct is_ref_wrapper : std::false_type {};
+template <typename T>
+struct is_ref_wrapper<std::reference_wrapper<T>> : std::true_type {};
+
+template <typename T>
+using not_ref_wrapper =
+    folly::Negation<is_ref_wrapper<typename std::decay<T>::type>>;
+
+template <typename D, typename...>
+struct return_type_helper {
+  using type = D;
+};
+template <typename... TList>
+struct return_type_helper<void, TList...> {
+  static_assert(
+      folly::Conjunction<not_ref_wrapper<TList>...>::value,
+      "TList cannot contain reference_wrappers when D is void");
+  using type = typename std::common_type<TList...>::type;
+};
+
+template <typename D, typename... TList>
+using return_type = std::
+    array<typename return_type_helper<D, TList...>::type, sizeof...(TList)>;
+} // namespace array_detail
+
+template <typename D = void, typename... TList>
+constexpr array_detail::return_type<D, TList...> make_array(TList&&... t) {
+  using value_type =
+      typename array_detail::return_type_helper<D, TList...>::type;
+  return {{static_cast<value_type>(std::forward<TList>(t))...}};
+}
+
+} // namespace folly
diff --git a/folly/container/test/ArrayTest.cpp b/folly/container/test/ArrayTest.cpp
new file mode 100644 (file)
index 0000000..04b877e
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+ * Copyright 2017 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 <folly/container/Array.h>
+#include <folly/portability/GTest.h>
+#include <string>
+
+using namespace std;
+using folly::make_array;
+
+TEST(make_array, base_case) {
+  auto arr = make_array<int>();
+  static_assert(
+      is_same<typename decltype(arr)::value_type, int>::value,
+      "Wrong array type");
+  EXPECT_EQ(arr.size(), 0);
+}
+
+TEST(make_array, deduce_size_primitive) {
+  auto arr = make_array<int>(1, 2, 3, 4, 5);
+  static_assert(
+      is_same<typename decltype(arr)::value_type, int>::value,
+      "Wrong array type");
+  EXPECT_EQ(arr.size(), 5);
+}
+
+TEST(make_array, deduce_size_class) {
+  auto arr = make_array<string>(string{"foo"}, string{"bar"});
+  static_assert(
+      is_same<typename decltype(arr)::value_type, std::string>::value,
+      "Wrong array type");
+  EXPECT_EQ(arr.size(), 2);
+  EXPECT_EQ(arr[1], "bar");
+}
+
+TEST(make_array, deduce_everything) {
+  auto arr = make_array(string{"foo"}, string{"bar"});
+  static_assert(
+      is_same<typename decltype(arr)::value_type, std::string>::value,
+      "Wrong array type");
+  EXPECT_EQ(arr.size(), 2);
+  EXPECT_EQ(arr[1], "bar");
+}
+
+TEST(make_array, fixed_common_type) {
+  auto arr = make_array<double>(1.0, 2.5f, 3, 4, 5);
+  static_assert(
+      is_same<typename decltype(arr)::value_type, double>::value,
+      "Wrong array type");
+  EXPECT_EQ(arr.size(), 5);
+}
+
+TEST(make_array, deduced_common_type) {
+  auto arr = make_array(1.0, 2.5f, 3, 4, 5);
+  static_assert(
+      is_same<typename decltype(arr)::value_type, double>::value,
+      "Wrong array type");
+  EXPECT_EQ(arr.size(), 5);
+}
index 5e9edbbc45a805332dcce11fd3fb1cc0264d5aa5..300459dde03d8251a275db2e143b25c55aa5f561 100644 (file)
@@ -16,9 +16,9 @@
 #include <string>
 #include <vector>
 
-#include <folly/Array.h>
 #include <folly/File.h>
 #include <folly/Range.h>
+#include <folly/container/Array.h>
 #include <folly/experimental/TestUtil.h>
 #include <folly/gen/Base.h>
 #include <folly/gen/File.h>
index a808d55771d14603d630890bab222308f2639425..45ffd58c876ae99d9d60524a9695972fcc6f0805 100644 (file)
@@ -16,7 +16,7 @@
 
 #pragma once
 
-#include <folly/Array.h>
+#include <folly/container/Array.h>
 #include <folly/io/async/SSLContext.h>
 
 namespace folly {
diff --git a/folly/test/ArrayTest.cpp b/folly/test/ArrayTest.cpp
deleted file mode 100644 (file)
index 29e3257..0000000
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Copyright 2017 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 <folly/Array.h>
-#include <folly/portability/GTest.h>
-#include <string>
-
-using namespace std;
-using folly::make_array;
-
-TEST(make_array, base_case) {
-  auto arr = make_array<int>();
-  static_assert(
-      is_same<typename decltype(arr)::value_type, int>::value,
-      "Wrong array type");
-  EXPECT_EQ(arr.size(), 0);
-}
-
-TEST(make_array, deduce_size_primitive) {
-  auto arr = make_array<int>(1, 2, 3, 4, 5);
-  static_assert(
-      is_same<typename decltype(arr)::value_type, int>::value,
-      "Wrong array type");
-  EXPECT_EQ(arr.size(), 5);
-}
-
-TEST(make_array, deduce_size_class) {
-  auto arr = make_array<string>(string{"foo"}, string{"bar"});
-  static_assert(
-      is_same<typename decltype(arr)::value_type, std::string>::value,
-      "Wrong array type");
-  EXPECT_EQ(arr.size(), 2);
-  EXPECT_EQ(arr[1], "bar");
-}
-
-TEST(make_array, deduce_everything) {
-  auto arr = make_array(string{"foo"}, string{"bar"});
-  static_assert(
-      is_same<typename decltype(arr)::value_type, std::string>::value,
-      "Wrong array type");
-  EXPECT_EQ(arr.size(), 2);
-  EXPECT_EQ(arr[1], "bar");
-}
-
-TEST(make_array, fixed_common_type) {
-  auto arr = make_array<double>(1.0, 2.5f, 3, 4, 5);
-  static_assert(
-      is_same<typename decltype(arr)::value_type, double>::value,
-      "Wrong array type");
-  EXPECT_EQ(arr.size(), 5);
-}
-
-TEST(make_array, deduced_common_type) {
-  auto arr = make_array(1.0, 2.5f, 3, 4, 5);
-  static_assert(
-      is_same<typename decltype(arr)::value_type, double>::value,
-      "Wrong array type");
-  EXPECT_EQ(arr.size(), 5);
-}
index 2199f8906d1194163f022cefaab015c3986f2496..0a5669308c1c3500bb1c302edd45209d9805f104 100644 (file)
@@ -45,7 +45,7 @@ spin_lock_test_SOURCES = SpinLockTest.cpp
 spin_lock_test_LDADD = libfollytestmain.la
 TESTS += spin_lock_test
 
-array_test_SOURCES = ArrayTest.cpp
+array_test_SOURCES = ../container/test/ArrayTest.cpp
 array_test_LDADD = libfollytestmain.la
 TESTS += array_test
 
index e9e706b4c34ca2da670d32902111a117a42c5c29..de654ac1658411138483b791129743e090abab38 100644 (file)
@@ -20,8 +20,8 @@
 #include <sstream>
 #include <system_error>
 
-#include <folly/Array.h>
 #include <folly/String.h>
+#include <folly/container/Array.h>
 #include <folly/experimental/TestUtil.h>
 #include <folly/portability/GTest.h>
 #include <folly/portability/Sockets.h>
index 5638343056129d0021e7bb918ad41d0c46f32982..4140d7d2904429fe80691e7b8374e4e169e2de6b 100644 (file)
@@ -24,7 +24,7 @@
 
 #include <boost/regex.hpp>
 
-#include <folly/Array.h>
+#include <folly/container/Array.h>
 #include <folly/portability/GTest.h>
 
 using namespace folly;