folly: gen: remove static member
authorLucian Grijincu <lucian@fb.com>
Wed, 16 Sep 2015 18:37:49 +0000 (11:37 -0700)
committerfacebook-github-bot-1 <folly-bot@fb.com>
Wed, 16 Sep 2015 19:20:22 +0000 (12:20 -0700)
Summary: there's no need for this static member, but it does get
generated. We're only curious about it's type. Replace with Meyer's
singleton to get the same effect.

Reviewed By: @ddrcoder, @yfeldblum

Differential Revision: D2446131

folly/gen/Base.h
folly/gen/Combine-inl.h
folly/gen/test/CombineTest.cpp

index 6e661f16183d4019b38d6056b4dbb54c055859ae..38fba4f79c72207426feb01ea40799ce2af5f732 100644 (file)
@@ -272,13 +272,9 @@ struct FBounded;
  */
 template<class Container>
 struct ValueTypeOfRange {
- private:
-  static Container container_;
  public:
-  typedef decltype(*std::begin(container_))
-    RefType;
-  typedef typename std::decay<decltype(*std::begin(container_))>::type
-    StorageType;
+  using RefType = decltype(*std::begin(std::declval<Container&>()));
+  using StorageType = typename std::decay<RefType>::type;
 };
 
 
index b36c8c719efbbe2b07ab782550ab262f83f9a16b..46386bdd04308a9c8785f00605aea2fc6609f9b7 100644 (file)
@@ -203,8 +203,6 @@ class MergeTuples {
 
 }  // namespace detail
 
-static const detail::Map<detail::MergeTuples> tuple_flatten{};
-
 // TODO(mcurtiss): support zip() for N>1 operands. Because of variadic problems,
 // this might not be easily possible until gcc4.8 is available.
 template<class Source,
index 7877f7f6e96808230460355f62e1ff9a9ae47800..0df6c48b56a9934d305d1c3a634bc9ba6055f2f0 100644 (file)
@@ -30,6 +30,9 @@ using std::string;
 using std::vector;
 using std::tuple;
 
+const folly::gen::detail::Map<
+  folly::gen::detail::MergeTuples> gTupleFlatten{};
+
 auto even = [](int i) -> bool { return i % 2 == 0; };
 auto odd = [](int i) -> bool { return i % 2 == 1; };
 
@@ -118,7 +121,7 @@ TEST(CombineGen, TupleFlatten) {
   EXPECT_EQ(std::get<1>(zipped1[0]), std::make_tuple('A'));
 
   auto zipped2 = from(zipped1)
-    | tuple_flatten
+    | gTupleFlatten
     | assert_type<tuple<int, string, char>&&>()
     | as<vector>();
   ASSERT_EQ(zipped2.size(), 3);
@@ -126,7 +129,7 @@ TEST(CombineGen, TupleFlatten) {
 
   auto zipped3 = from(charTupleVec)
     | zip(intStringTupleVec)
-    | tuple_flatten
+    | gTupleFlatten
     | assert_type<tuple<char, int, string>&&>()
     | as<vector>();
   ASSERT_EQ(zipped3.size(), 3);
@@ -134,7 +137,7 @@ TEST(CombineGen, TupleFlatten) {
 
   auto zipped4 = from(intStringTupleVec)
     | zip(doubleVec)
-    | tuple_flatten
+    | gTupleFlatten
     | assert_type<tuple<int, string, double>&&>()
     | as<vector>();
   ASSERT_EQ(zipped4.size(), 3);
@@ -143,7 +146,7 @@ TEST(CombineGen, TupleFlatten) {
   auto zipped5 = from(doubleVec)
     | zip(doubleVec)
     | assert_type<tuple<double, double>>()
-    | tuple_flatten  // essentially a no-op
+    | gTupleFlatten  // essentially a no-op
     | assert_type<tuple<double, double>&&>()
     | as<vector>();
   ASSERT_EQ(zipped5.size(), 5);
@@ -151,9 +154,9 @@ TEST(CombineGen, TupleFlatten) {
 
   auto zipped6 = from(intStringTupleVec)
     | zip(charTupleVec)
-    | tuple_flatten
+    | gTupleFlatten
     | zip(doubleVec)
-    | tuple_flatten
+    | gTupleFlatten
     | assert_type<tuple<int, string, char, double>&&>()
     | as<vector>();
   ASSERT_EQ(zipped6.size(), 3);