| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 3b1b6bc commit 7b6009e
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -102,18 +102,29 @@ struct Identity | |||
| 102 | 102 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 103 | 103 | struct DontMove {}; | |
| 104 | 104 | ||
| 105 | + /////////////////////////////////////////////////////////////////////////////////////////////////// | ||
| 106 | + /// DisableIfSame | ||
| 107 | + /////////////////////////////////////////////////////////////////////////////////////////////////// | ||
| 108 | + template <typename T, typename U> | ||
| 109 | + struct DisableIfSame : | ||
| 110 | + std::enable_if<! std::is_same< | ||
| 111 | + typename std::decay<T>::type, | ||
| 112 | + typename std::decay<U>::type>::value> {}; | ||
| 113 | + | ||
| 105 | 114 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 106 | 115 | /// AddDummyArgWrapper | |
| 107 | 116 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 108 | 117 | template <typename TArg, typename F, typename TRet, typename ... TDepValues> | |
| 109 | 118 | struct AddDummyArgWrapper | |
| 110 | 119 | { | |
| 111 | - // Dummy int to make sure it calls the right ctor | ||
| 112 | - template <typename FIn> | ||
| 113 | - AddDummyArgWrapper(int, FIn&& func) : MyFunc( std::forward<FIn>(func) ) {} | ||
| 114 | - | ||
| 115 | 120 | AddDummyArgWrapper(const AddDummyArgWrapper& other) = default; | |
| 116 | - AddDummyArgWrapper(AddDummyArgWrapper&& other) : MyFunc( std::move(other.MyFunc) ) {} | ||
| 121 | + | ||
| 122 | + AddDummyArgWrapper(AddDummyArgWrapper&& other) : | ||
| 123 | + MyFunc( std::move(other.MyFunc) ) | ||
| 124 | + {} | ||
| 125 | + | ||
| 126 | + template <typename FIn, class = typename DisableIfSame<FIn,AddDummyArgWrapper>::type> | ||
| 127 | + explicit AddDummyArgWrapper(FIn&& func) : MyFunc( std::forward<FIn>(func) ) {} | ||
| 117 | 128 | ||
| 118 | 129 | TRet operator()(TArg, TDepValues& ... args) | |
| 119 | 130 | { | |
@@ -126,12 +137,15 @@ struct AddDummyArgWrapper | |||
| 126 | 137 | template <typename TArg, typename F, typename ... TDepValues> | |
| 127 | 138 | struct AddDummyArgWrapper<TArg,F,void,TDepValues...> | |
| 128 | 139 | { | |
| 129 | - // Dummy int to make sure it calls the right ctor | ||
| 130 | - template <typename FIn> | ||
| 131 | - AddDummyArgWrapper(int, FIn&& func) : MyFunc( std::forward<FIn>(func) ) {} | ||
| 132 | - | ||
| 140 | + public: | ||
| 133 | 141 | AddDummyArgWrapper(const AddDummyArgWrapper& other) = default; | |
| 134 | - AddDummyArgWrapper(AddDummyArgWrapper&& other) : MyFunc( std::move(other.MyFunc) ) {} | ||
| 142 | + | ||
| 143 | + AddDummyArgWrapper(AddDummyArgWrapper&& other) : | ||
| 144 | + MyFunc( std::move(other.MyFunc) ) | ||
| 145 | + {} | ||
| 146 | + | ||
| 147 | + template <typename FIn, class = typename DisableIfSame<FIn,AddDummyArgWrapper>::type> | ||
| 148 | + explicit AddDummyArgWrapper(FIn&& func) : MyFunc( std::forward<FIn>(func) ) {} | ||
| 135 | 149 | ||
| 136 | 150 | void operator()(TArg, TDepValues& ... args) | |
| 137 | 151 | { | |
@@ -152,8 +166,20 @@ template | |||
| 152 | 166 | > | |
| 153 | 167 | struct AddDefaultReturnValueWrapper | |
| 154 | 168 | { | |
| 155 | - template <typename FIn> | ||
| 156 | - AddDefaultReturnValueWrapper(FIn&& func) : MyFunc( std::forward<FIn>(func) ) {} | ||
| 169 | + AddDefaultReturnValueWrapper(const AddDefaultReturnValueWrapper&) = default; | ||
| 170 | + | ||
| 171 | + AddDefaultReturnValueWrapper(AddDefaultReturnValueWrapper&& other) : | ||
| 172 | + MyFunc( std::move(other.MyFunc) ) | ||
| 173 | + {} | ||
| 174 | + | ||
| 175 | + template | ||
| 176 | + < | ||
| 177 | + typename FIn, | ||
| 178 | + class = typename DisableIfSame<FIn,AddDefaultReturnValueWrapper>::type | ||
| 179 | + > | ||
| 180 | + explicit AddDefaultReturnValueWrapper(FIn&& func) : | ||
| 181 | + MyFunc( std::forward<FIn>(func) ) | ||
| 182 | + {} | ||
| 157 | 183 | ||
| 158 | 184 | template <typename ... TArgs> | |
| 159 | 185 | TRet operator()(TArgs&& ... args) | |
@@ -165,6 +191,33 @@ struct AddDefaultReturnValueWrapper | |||
| 165 | 191 | F MyFunc; | |
| 166 | 192 | }; | |
| 167 | 193 | ||
| 194 | + /////////////////////////////////////////////////////////////////////////////////////////////////// | ||
| 195 | + /// IsCallableWith | ||
| 196 | + /////////////////////////////////////////////////////////////////////////////////////////////////// | ||
| 197 | + template | ||
| 198 | + < | ||
| 199 | + typename F, | ||
| 200 | + typename TRet, | ||
| 201 | + typename ... TArgs | ||
| 202 | + > | ||
| 203 | + class IsCallableWith | ||
| 204 | + { | ||
| 205 | + private: | ||
| 206 | + using NoT = char[1]; | ||
| 207 | + using YesT = char[2]; | ||
| 208 | + | ||
| 209 | + template <typename U> | ||
| 210 | + static YesT& check( | ||
| 211 | + decltype( static_cast<TRet>( | ||
| 212 | + (std::declval<U>())(std::declval<TArgs>() ...))) *); | ||
| 213 | + | ||
| 214 | + template <typename U> | ||
| 215 | + static NoT& check(...); | ||
| 216 | + | ||
| 217 | + public: | ||
| 218 | + enum { value = sizeof(check<F>(nullptr)) == sizeof(YesT) }; | ||
| 219 | + }; | ||
| 220 | + | ||
| 168 | 221 | /****************************************/ REACT_IMPL_END /***************************************/ | |
| 169 | 222 | ||
| 170 | 223 | // Expand args by wrapping them in a dummy function | |
| Back | FazBrowse Home | New Git URL |
0 commit comments