proxygen
TypeListTest.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2017-present Facebook, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <folly/detail/TypeList.h>
19 
20 using namespace folly;
21 using namespace detail;
22 
23 namespace {
24 template <class T, class Ts, class = void>
25 struct IsApplicable_ : std::false_type {};
26 template <class T, class... Ts>
27 struct IsApplicable_<T, TypeList<Ts...>, void_t<MetaApply<T, Ts...>>>
28  : std::true_type {};
29 template <class T, class... Ts>
30 using IsApplicable = IsApplicable_<T, TypeList<Ts...>>;
31 } // namespace
32 
33 TEST(TypeList, Basic) {
34  static_assert(TypeList<>::size() == 0, "");
35  static_assert(TypeList<int>::size() == 1, "");
36  static_assert(TypeList<int, short, float>::size() == 3, "");
37 }
38 
39 template <class T>
40 using AddPointer = T*;
41 
42 TEST(TypeList, Defer) {
43  static_assert(
44  std::is_same<MetaApply<MetaDefer<AddPointer, int>>, int*>::value, "");
45  static_assert(!IsApplicable<MetaDefer<AddPointer, int, short>>::value, "");
46  static_assert(!IsApplicable<MetaDefer<AddPointer, int&>>::value, "");
47 }
48 
49 TEST(TypeList, Transform) {
50  using Fn = MetaQuote<AddPointer>;
51  using T1 = TypeTransform<TypeList<>, Fn>;
52  static_assert(std::is_same<T1, TypeList<>>::value, "");
53  using T2 = TypeTransform<TypeList<int>, Fn>;
54  static_assert(std::is_same<T2, TypeList<int*>>::value, "");
56  static_assert(std::is_same<T3, TypeList<int*, short*, void*>>::value, "");
57 }
58 
59 using Nil = Empty;
60 template <class Car, class Cdr = Nil>
61 struct Cons {};
62 
63 TEST(TypeList, Fold) {
64  using Fn = MetaQuote<Cons>;
67  static_assert(std::is_same<T1, E1>::value, "");
68 
70  using E2 = Cons<
71  int,
73  static_assert(std::is_same<T2, E2>::value, "");
74 
77  static_assert(std::is_same<T3, E3>::value, "");
78 
79  using T4 = TypeReverseFold<
81  Nil,
82  MetaFlip<Fn>>;
83  using E4 = Cons<
84  void*,
86  static_assert(std::is_same<T4, E4>::value, "");
87 }
88 
89 TEST(TypeList, Unique) {
91  static_assert(std::is_same<T1, TypeList<int, short>>::value, "");
92 
94  static_assert(std::is_same<T2, TypeList<short, int>>::value, "");
95 }
96 
98  using T1 = TypePushFront<TypeList<>, int, short>;
99  static_assert(std::is_same<T1, TypeList<int, short>>::value, "");
100 
102  static_assert(
104  "");
105 }
106 
107 TEST(TypeList, PushBack) {
108  using T1 = TypePushBack<TypeList<>, int, short>;
109  static_assert(std::is_same<T1, TypeList<int, short>>::value, "");
110 
112  static_assert(
114  "");
115 }
116 
117 TEST(TypeList, Join) {
118  using T1 = TypeJoin<
120  static_assert(
121  std::is_same<T1, TypeList<int, short, float, void*>>::value, "");
122 }
folly::std T
—— Concurrent Priority Queue Implementation ——
Definition: AtomicBitSet.h:29
MetaApply< MetaApply< List, impl::FoldR_< Fn >>, State > TypeFold
Definition: TypeList.h:380
bool_constant< true > true_type
Definition: gtest-port.h:2210
Empty Nil
MetaApply< List, MetaBindBack< MetaQuote< TypeList >, Ts... >> TypePushBack
Definition: TypeList.h:290
MetaApply< List, MetaBindFront< MetaQuote< TypeList >, Ts... >> TypePushFront
Definition: TypeList.h:301
MetaApply< List, impl::TypeTransform_< Fn >> TypeTransform
Definition: TypeList.h:327
type_t< void, Ts... > void_t
Definition: Traits.h:302
typename Fn::template apply< Ts... > MetaApply
Definition: TypeList.h:90
MetaApply< MetaApply< List, impl::FoldL_< Fn >>, State > TypeReverseFold
Definition: TypeList.h:419
static const char *const value
Definition: Conv.cpp:50
TypeReverseFold< List, TypeList<>, MetaFlip< impl::Unique_ >> TypeReverseUnique
Definition: TypeList.h:488
uint64_t value(const typename LockFreeRingBuffer< T, Atom >::Cursor &rbcursor)
bool_constant< false > false_type
Definition: gtest-port.h:2209
def PushFront(a_list, elem)
Definition: pump.py:449
T * AddPointer
TypeFold< List, TypeList<>, impl::Unique_ > TypeUnique
Definition: TypeList.h:475
MetaApply< TypeFold< List, MetaQuote< TypeList >, impl::Join_ >> TypeJoin
Definition: TypeList.h:538
TEST(SequencedExecutor, CPUThreadPoolExecutor)