fold.hpp 447 B

1234567891011121314151617181920212223
  1. //
  2. // fold.hpp
  3. // stream
  4. //
  5. // Created by Sam Jaffe on 8/14/16.
  6. //
  7. #pragma once
  8. #include <numeric>
  9. namespace stream {
  10. template <typename L, typename R>
  11. struct fold_left_t {
  12. L init;
  13. std::function<L(const L&, const R&)> fold;
  14. };
  15. }
  16. template <typename L, typename R, bool B>
  17. L operator >(stream::detail::stream_base<R, B> const &s, stream::fold_left_t<L, R> && f) {
  18. return std::accumulate(s.begin(), s.end(), f.fold, f.init);
  19. }