|
4 | 4 | #include <type_traits> // ::std::invoke_result_t, ::std::decay_t, ::std::enable_if_t, ::std::is_same, ::std::is_base_of |
5 | 5 | #include <iterator> // ::std::iterator_traits, ::std::forward_iterator_tag, ::std::input_iterator_tag |
6 | 6 | #include <utility> // ::std::declval |
| 7 | +#include <optional> // ::std::optional |
7 | 8 |
|
8 | 9 | namespace stream |
9 | 10 | { |
@@ -202,74 +203,50 @@ namespace stream |
202 | 203 | // ============================================================================================================ |
203 | 204 |
|
204 | 205 | // ============================================================================================================ |
205 | | - template<typename C, typename S, typename = void> |
206 | | - struct ContinuationInvokeResult |
| 206 | + template<typename T> |
| 207 | + struct IsOptional : ::std::false_type |
207 | 208 | {}; |
208 | 209 |
|
209 | | - template<typename C, typename S> |
210 | | - struct ContinuationInvokeResult<Continuation<C, false>, S, |
211 | | - VoidT<InvokeResultT<Continuation<C, false>, |
212 | | - typename StreamTraits<S>::RealType&&, |
213 | | - const S&>>> |
214 | | - { |
215 | | - using Type = InvokeResultT<Continuation<C, false>, |
216 | | - typename StreamTraits<S>::RealType&&, |
217 | | - const S&>; |
218 | | - }; |
219 | | - |
220 | | - template<typename C, typename S> |
221 | | - struct ContinuationInvokeResult<Continuation<C, true>, S, |
222 | | - VoidT<InvokeResultT<Continuation<C, true>, |
223 | | - typename StreamTraits<S>::RealType&&, |
224 | | - const S&, |
225 | | - bool&>>> |
226 | | - { |
227 | | - using Type = InvokeResultT<Continuation<C, true>, |
228 | | - typename StreamTraits<S>::RealType&&, |
229 | | - const S&, |
230 | | - bool&>; |
231 | | - }; |
232 | | - |
233 | | - template<typename C, typename S> |
234 | | - using ContinuationInvokeResultT = typename ContinuationInvokeResult<C, S>::Type; |
| 210 | + template<typename... Args> |
| 211 | + struct IsOptional<::std::optional<Args...>> : ::std::true_type |
| 212 | + {}; |
235 | 213 |
|
| 214 | + template<typename T> |
| 215 | + static constexpr bool IsOptionalV = IsOptional<T>::value; |
236 | 216 |
|
237 | 217 |
|
238 | 218 | template<typename C, typename S, typename = void> |
239 | | - struct ContinuationForTraitsImpl |
| 219 | + struct ContinutationForTraitsImpl |
240 | 220 | { |
241 | 221 | static constexpr bool IsContinuation = false; |
242 | 222 | }; |
243 | 223 |
|
244 | 224 | template<typename C, typename S> |
245 | | - struct ContinuationForTraitsImpl<Continuation<C, false>, S, |
246 | | - VoidT<InvokeResultT<Continuation<C, false>, |
247 | | - decltype(::std::declval<typename StreamTraits<S>::RealType>().get()), |
248 | | - const S&>>> |
| 225 | + struct ContinutationForTraitsImpl<Continuation<C, false>, S, |
| 226 | + VoidT<::std::enable_if_t<IsOptionalV<InvokeResultT<Continuation<C, false>, |
| 227 | + typename StreamTraits<S>::RealType&&, |
| 228 | + const S&>>>> |
| 229 | + > |
249 | 230 | { |
250 | 231 | static constexpr bool IsContinuation = true; |
251 | | - using ValueType = InvokeResultT<Continuation<C, false>, |
252 | | - decltype(::std::declval<typename StreamTraits<S>::RealType>().get()), |
253 | | - const S&>; |
| 232 | + using ValueType = typename InvokeResultT<Continuation<C, false>, |
| 233 | + typename StreamTraits<S>::RealType&&, |
| 234 | + const S&>::value_type; |
254 | 235 | }; |
255 | 236 |
|
256 | 237 | template<typename C, typename S> |
257 | | - struct ContinuationForTraitsImpl<Continuation<C, false>, S, |
258 | | - VoidT<::std::enable_if_t<::std::is_same<>::value>> |
259 | | - > |
260 | | - |
261 | | - template<typename C, typename S> |
262 | | - struct ContinuationForTraitsImpl<Continuation<C, true>, S, |
263 | | - VoidT<InvokeResultT<Continuation<C, true>, |
264 | | - decltype(::std::declval<typename StreamTraits<S>::RealType>().get()), |
265 | | - const S&, |
266 | | - bool&>>> |
| 238 | + struct ContinutationForTraitsImpl<Continuation<C, true>, S, |
| 239 | + VoidT<::std::enable_if_t<IsOptionalV<InvokeResultT<Continuation<C, true>, |
| 240 | + typename StreamTraits<S>::RealType&&, |
| 241 | + const S&, |
| 242 | + bool&>>>> |
| 243 | + > |
267 | 244 | { |
268 | 245 | static constexpr bool IsContinuation = true; |
269 | | - using ValueType = InvokeResultT<Continuation<C, true>, |
270 | | - decltype(::std::declval<typename StreamTraits<S>::RealType>().get()), |
271 | | - const S&, |
272 | | - bool&>; |
| 246 | + using ValueType = typename InvokeResultT<Continuation<C, true>, |
| 247 | + typename StreamTraits<S>::RealType&&, |
| 248 | + const S&, |
| 249 | + bool&>::value_type; |
273 | 250 | }; |
274 | 251 |
|
275 | 252 | template<typename C, typename Stream> |
|
0 commit comments