1 /* 2 * Copyright 2014 Google Inc. All rights reserved. 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 #ifndef FRUIT_META_WRAPPERS_H 18 #define FRUIT_META_WRAPPERS_H 19 20 #include <fruit/impl/fruit-config.h> 21 22 #include <memory> 23 24 namespace fruit { 25 namespace impl { 26 namespace meta { 27 28 struct ConsSignature { 29 template <typename ReturnType, typename... Args> 30 struct apply; 31 32 template <typename ReturnType, typename... Args> 33 struct apply<Type<ReturnType>, Type<Args>...> { 34 using type = Type<ReturnType(Args...)>; 35 }; 36 }; 37 38 struct ConsStdFunction { 39 template <typename Signature> 40 struct apply; 41 42 template <typename Signature> 43 struct apply<Type<Signature>> { 44 using type = Type<std::function<Signature>>; 45 }; 46 }; 47 48 struct ConsUniquePtr { 49 template <typename T> 50 struct apply; 51 52 template <typename T> 53 struct apply<Type<T>> { 54 using type = Type<std::unique_ptr<T>>; 55 }; 56 }; 57 58 struct RemoveUniquePtr { 59 template <typename T> 60 struct apply { 61 using type = T; 62 }; 63 64 template <typename T> 65 struct apply<Type<std::unique_ptr<T>>> { 66 using type = Type<T>; 67 }; 68 }; 69 70 struct RemovePointer { 71 template <typename T> 72 struct apply { 73 using type = T; 74 }; 75 76 template <typename T> 77 struct apply<Type<T*>> { 78 using type = Type<T>; 79 }; 80 }; 81 82 struct ConsReference { 83 template <typename T> 84 struct apply; 85 86 template <typename T> 87 struct apply<Type<T>> { 88 using type = Type<T&>; 89 }; 90 }; 91 92 struct ConsConstReference { 93 template <typename T> 94 struct apply; 95 96 template <typename T> 97 struct apply<Type<T>> { 98 using type = Type<const T&>; 99 }; 100 }; 101 102 struct IsEmpty { 103 template <typename T> 104 struct apply; 105 106 template <typename T> 107 struct apply<Type<T>> { 108 using type = Bool<std::is_empty<T>::value>; 109 }; 110 }; 111 112 struct IsTriviallyCopyable { 113 template <typename T> 114 struct apply; 115 116 template <typename T> 117 struct apply<Type<T>> { 118 using type = Bool<FRUIT_IS_TRIVIALLY_COPYABLE(T)>; 119 }; 120 }; 121 122 struct IsPointer { 123 template <typename T> 124 struct apply; 125 126 template <typename T> 127 struct apply<Type<T>> { 128 using type = Bool<std::is_pointer<T>::value>; 129 }; 130 }; 131 132 struct IsUniquePtr { 133 template <typename T> 134 struct apply { 135 using type = Bool<false>; 136 }; 137 138 template <typename T> 139 struct apply<Type<std::unique_ptr<T>>> { 140 using type = Bool<true>; 141 }; 142 }; 143 144 struct IsAbstract { 145 template <typename T> 146 struct apply; 147 148 template <typename T> 149 struct apply<Type<T>> { 150 using type = Bool<std::is_abstract<T>::value>; 151 }; 152 }; 153 154 struct IsBaseOf { 155 template <typename I, typename C> 156 struct apply; 157 158 template <typename I, typename C> 159 struct apply<Type<I>, Type<C>> { 160 using type = Bool<std::is_base_of<I, C>::value>; 161 }; 162 }; 163 164 struct HasVirtualDestructor { 165 template <typename T> 166 struct apply; 167 168 template <typename T> 169 struct apply<Type<T>> { 170 using type = Bool<std::has_virtual_destructor<T>::value>; 171 }; 172 }; 173 174 } // namespace meta 175 } // namespace impl 176 } // namespace fruit 177 178 #endif // FRUIT_META_WRAPPERS_H 179