sentinel_iterator.h 783 B

1234567891011121314151617181920212223242526272829303132
  1. //
  2. // sentinel_iterator.h
  3. // iterator
  4. //
  5. // Created by Sam Jaffe on 3/30/23.
  6. // Copyright © 2023 Sam Jaffe. All rights reserved.
  7. //
  8. #pragma once
  9. #include <iterator/forwards.h>
  10. #include <iterator/proxy.h>
  11. namespace iterator {
  12. template <typename It, typename S>
  13. class sentinel_iterator : public proxy<It, sentinel_iterator<It, S>> {
  14. public:
  15. using super_t = proxy<It, sentinel_iterator<It, S>>;
  16. using sentinel_type = sentinel_iterator;
  17. public:
  18. using super_t::super_t;
  19. sentinel_iterator(S) : super_t() {}
  20. bool equal_to(sentinel_iterator const & other) const {
  21. return (at_end() && other.at_end()) || super_t::impl() == other.impl();
  22. }
  23. bool at_end() const { return super_t::impl() == S(); }
  24. };
  25. }
  26. MAKE_ITERATOR_FACADE_TYPEDEFS_T(::iterator::sentinel_iterator);