single_view.h 532 B

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