You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

105 lines
2.9 KiB

  1. #pragma once
  2. #include <type_traits>
  3. #include "stream.pre.h"
  4. #include "../result.h"
  5. namespace asyncpp
  6. {
  7. template<
  8. typename T_value,
  9. typename T_derived>
  10. struct base_stream
  11. : public tag_stream
  12. {
  13. public:
  14. using value_type = T_value;
  15. using result_type = stream_result<value_type>;
  16. using derived_type = T_derived;
  17. using this_type = base_stream<value_type, derived_type>;
  18. public:
  19. /**
  20. * @brief Execute the given lambda for each element in the stream.
  21. *
  22. * @return Returns a future that completes once the stream is finished.
  23. */
  24. template<
  25. chaining_mode X_mode = copy,
  26. typename X_lambda>
  27. inline auto for_each(X_lambda&& p_lambda) &;
  28. /**
  29. * @brief Execute the given lambda for each element in the stream.
  30. *
  31. * @return Returns a future that completes once the stream is finished.
  32. */
  33. template<
  34. chaining_mode X_mode = move,
  35. typename X_lambda>
  36. inline auto for_each(X_lambda&& p_lambda) &&;
  37. public:
  38. /**
  39. * @brief Transforms the stream from one type to another type
  40. * by executing the passed lambda for each value.
  41. */
  42. template<
  43. chaining_mode X_mode = copy,
  44. typename X_lambda>
  45. inline auto map(X_lambda&& p_lambda) &;
  46. /**
  47. * @brief Transforms the stream from one type to another type
  48. * by executing the passed lambda for each value.
  49. */
  50. template<
  51. chaining_mode X_mode = move,
  52. typename X_lambda>
  53. inline auto map(X_lambda&& p_lambda) &&;
  54. public:
  55. /**
  56. * @brief Flatten the stream of streams to a single stream.
  57. */
  58. template<
  59. chaining_mode X_mode = copy>
  60. inline auto flatten() &;
  61. /**
  62. * @brief Flatten the stream of streams to a single stream.
  63. */
  64. template<
  65. chaining_mode X_mode = move>
  66. inline auto flatten() &&;
  67. #ifdef ASYNCPP_ENABLE_FEATURE_TIMING
  68. public:
  69. /**
  70. * @brief Throw an execption if the timeout has passed.
  71. *
  72. * This method is only enabled if timer.h is included before.
  73. */
  74. template<
  75. chaining_mode X_mode = copy,
  76. typename X_base,
  77. typename X_ratio>
  78. inline auto timeout(const duration<X_base, X_ratio>& p_timeout) &;
  79. /**
  80. * @brief Throw an execption if the timeout has passed.
  81. *
  82. * This method is only enabled if timer.h is included before.
  83. */
  84. template<
  85. chaining_mode X_mode = move,
  86. typename X_base,
  87. typename X_ratio>
  88. inline auto timeout(const duration<X_base, X_ratio>& p_timeout) &&;
  89. #endif
  90. };
  91. }