array_iterator.h 897 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #pragma once
  2. #include <iterator>
  3. #include <string>
  4. #include <jvalidate/detail/deref_proxy.h>
  5. namespace jvalidate::adapter::detail {
  6. template <typename It, typename Adapter> class JsonObjectIterator : public It {
  7. public:
  8. using value_type = std::pair<std::string, Adapter>;
  9. using reference = std::pair<std::string, Adapter>;
  10. using pointer = ::jvalidate::detail::DerefProxy<reference>;
  11. using difference_type = std::ptrdiff_t;
  12. using iterator_category = std::forward_iterator_tag;
  13. JsonObjectIterator() = default;
  14. JsonObjectIterator(It it) : It(it) {}
  15. reference operator*() const { return {Adapter::key(*this), Adapter(It::operator->())}; }
  16. pointer operator->() const { return {operator*()}; }
  17. JsonObjectIterator operator++(int) {
  18. auto tmp = *this;
  19. ++*this;
  20. return tmp;
  21. }
  22. JsonObjectIterator & operator++() {
  23. It::operator++();
  24. return *this;
  25. }
  26. };
  27. }