single.h 561 B

12345678910111213141516171819202122232425262728293031
  1. //
  2. // single.h
  3. // stream
  4. //
  5. // Created by Sam Jaffe on 3/29/23.
  6. //
  7. #pragma once
  8. #include <stream/forward.h>
  9. namespace stream::ranges {
  10. template <typename T> class single_view {
  11. private:
  12. T value_;
  13. public:
  14. single_view(T const & value) : value_(value) {}
  15. T const * begin() const { return &value_; }
  16. T const * end() const { return 1 + &value_; }
  17. static bool empty() { return false; }
  18. static size_t size() { return 1; }
  19. };
  20. }
  21. namespace stream::ranges::views {
  22. template <typename T> auto single(T const & value) {
  23. return single_view(value);
  24. }
  25. }