Advertisement
Jakowlew

Untitled

Mar 4th, 2021
1,203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.89 KB | None | 0 0
  1. template<typename T>
  2. struct function_traits;  
  3.  
  4. template<typename R, typename ...Args>
  5. struct function_traits<std::function<R(Args...)>>
  6. {
  7.     static const size_t nargs = sizeof...(Args);
  8.  
  9.     typedef R result_type;
  10.  
  11.     template <size_t i>
  12.     struct arg
  13.     {
  14.         typedef typename std::tuple_element<i, std::tuple<Args...>>::type type;
  15.     };
  16. };
  17.  
  18. template <Filter T, Filter U>
  19. auto addToPipe(T&& left, U&& right)
  20. {
  21.     return [left = std::move(left), right = std::move(right)](typename T::resource_t& frame) {
  22.         return right(left(frame));
  23.     };
  24. }
  25.  
  26. template <typename Pipe, Filter U>
  27. auto addToPipe(Pipe&& left, U&& right)
  28. {
  29.     using input_t = typename function_traits<Pipe>::arg<0>::type;
  30.     using pipe_return_t = typename function_traits<Pipe>::result_type;
  31.     using middle_t = typename U::resource_t;
  32.  
  33.     static_assert(std::is_same_v<pipe_return_t, middle_t>);
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement