From: Yedidya Feldblum Date: Sun, 29 Oct 2017 10:33:10 +0000 (-0700) Subject: Move folly/Array.h X-Git-Tag: v2017.10.30.00~4 X-Git-Url: http://plrg.eecs.uci.edu/git/?p=folly.git;a=commitdiff_plain;h=f9b6d0123962082a70041d86f46c84cab007af9b Move folly/Array.h Summary: [Folly] Move `folly/Array.h` to `folly/container/`. Reviewed By: luciang Differential Revision: D6182858 fbshipit-source-id: 59340b96058cc6d0c7a0289e316bbde98c15d724 --- diff --git a/folly/Array.h b/folly/Array.h deleted file mode 100644 index 8b2e7c05..00000000 --- a/folly/Array.h +++ /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 -#include -#include -#include - -namespace folly { - -namespace array_detail { -template -struct is_ref_wrapper : std::false_type {}; -template -struct is_ref_wrapper> : std::true_type {}; - -template -using not_ref_wrapper = - folly::Negation::type>>; - -template -struct return_type_helper { - using type = D; -}; -template -struct return_type_helper { - static_assert( - folly::Conjunction...>::value, - "TList cannot contain reference_wrappers when D is void"); - using type = typename std::common_type::type; -}; - -template -using return_type = std:: - array::type, sizeof...(TList)>; -} // namespace array_detail - -template -constexpr array_detail::return_type make_array(TList&&... t) { - using value_type = - typename array_detail::return_type_helper::type; - return {{static_cast(std::forward(t))...}}; -} - -} // namespace folly diff --git a/folly/Makefile.am b/folly/Makefile.am index dafdd730..a35a4a94 100644 --- a/folly/Makefile.am +++ b/folly/Makefile.am @@ -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 index 00000000..8b2e7c05 --- /dev/null +++ b/folly/container/Array.h @@ -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 +#include +#include +#include + +namespace folly { + +namespace array_detail { +template +struct is_ref_wrapper : std::false_type {}; +template +struct is_ref_wrapper> : std::true_type {}; + +template +using not_ref_wrapper = + folly::Negation::type>>; + +template +struct return_type_helper { + using type = D; +}; +template +struct return_type_helper { + static_assert( + folly::Conjunction...>::value, + "TList cannot contain reference_wrappers when D is void"); + using type = typename std::common_type::type; +}; + +template +using return_type = std:: + array::type, sizeof...(TList)>; +} // namespace array_detail + +template +constexpr array_detail::return_type make_array(TList&&... t) { + using value_type = + typename array_detail::return_type_helper::type; + return {{static_cast(std::forward(t))...}}; +} + +} // namespace folly diff --git a/folly/container/test/ArrayTest.cpp b/folly/container/test/ArrayTest.cpp new file mode 100644 index 00000000..04b877e2 --- /dev/null +++ b/folly/container/test/ArrayTest.cpp @@ -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 +#include +#include + +using namespace std; +using folly::make_array; + +TEST(make_array, base_case) { + auto arr = make_array(); + static_assert( + is_same::value, + "Wrong array type"); + EXPECT_EQ(arr.size(), 0); +} + +TEST(make_array, deduce_size_primitive) { + auto arr = make_array(1, 2, 3, 4, 5); + static_assert( + is_same::value, + "Wrong array type"); + EXPECT_EQ(arr.size(), 5); +} + +TEST(make_array, deduce_size_class) { + auto arr = make_array(string{"foo"}, string{"bar"}); + static_assert( + is_same::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::value, + "Wrong array type"); + EXPECT_EQ(arr.size(), 2); + EXPECT_EQ(arr[1], "bar"); +} + +TEST(make_array, fixed_common_type) { + auto arr = make_array(1.0, 2.5f, 3, 4, 5); + static_assert( + is_same::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::value, + "Wrong array type"); + EXPECT_EQ(arr.size(), 5); +} diff --git a/folly/gen/test/FileTest.cpp b/folly/gen/test/FileTest.cpp index 5e9edbbc..300459dd 100644 --- a/folly/gen/test/FileTest.cpp +++ b/folly/gen/test/FileTest.cpp @@ -16,9 +16,9 @@ #include #include -#include #include #include +#include #include #include #include diff --git a/folly/io/async/SSLOptions.h b/folly/io/async/SSLOptions.h index a808d557..45ffd58c 100644 --- a/folly/io/async/SSLOptions.h +++ b/folly/io/async/SSLOptions.h @@ -16,7 +16,7 @@ #pragma once -#include +#include #include namespace folly { diff --git a/folly/test/ArrayTest.cpp b/folly/test/ArrayTest.cpp deleted file mode 100644 index 29e32574..00000000 --- a/folly/test/ArrayTest.cpp +++ /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 -#include -#include - -using namespace std; -using folly::make_array; - -TEST(make_array, base_case) { - auto arr = make_array(); - static_assert( - is_same::value, - "Wrong array type"); - EXPECT_EQ(arr.size(), 0); -} - -TEST(make_array, deduce_size_primitive) { - auto arr = make_array(1, 2, 3, 4, 5); - static_assert( - is_same::value, - "Wrong array type"); - EXPECT_EQ(arr.size(), 5); -} - -TEST(make_array, deduce_size_class) { - auto arr = make_array(string{"foo"}, string{"bar"}); - static_assert( - is_same::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::value, - "Wrong array type"); - EXPECT_EQ(arr.size(), 2); - EXPECT_EQ(arr[1], "bar"); -} - -TEST(make_array, fixed_common_type) { - auto arr = make_array(1.0, 2.5f, 3, 4, 5); - static_assert( - is_same::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::value, - "Wrong array type"); - EXPECT_EQ(arr.size(), 5); -} diff --git a/folly/test/Makefile.am b/folly/test/Makefile.am index 2199f890..0a566930 100644 --- a/folly/test/Makefile.am +++ b/folly/test/Makefile.am @@ -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 diff --git a/folly/test/SocketAddressTest.cpp b/folly/test/SocketAddressTest.cpp index e9e706b4..de654ac1 100644 --- a/folly/test/SocketAddressTest.cpp +++ b/folly/test/SocketAddressTest.cpp @@ -20,8 +20,8 @@ #include #include -#include #include +#include #include #include #include diff --git a/folly/test/StringTest.cpp b/folly/test/StringTest.cpp index 56383430..4140d7d2 100644 --- a/folly/test/StringTest.cpp +++ b/folly/test/StringTest.cpp @@ -24,7 +24,7 @@ #include -#include +#include #include using namespace folly;