MCPcopy Create free account
hub / github.com/fmtlib/fmt / iterator

Class iterator

test/scan.h:62–112  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

60 class sentinel {};
61
62 class iterator {
63 private:
64 const char** ptr_;
65 scan_buffer* buf_; // This could be merged with ptr_.
66 char value_;
67
68 static auto get_sentinel() -> const char** {
69 static const char* ptr = nullptr;
70 return &ptr;
71 }
72
73 friend class scan_buffer;
74
75 friend auto operator==(iterator lhs, sentinel) -> bool {
76 return *lhs.ptr_ == nullptr;
77 }
78 friend auto operator!=(iterator lhs, sentinel) -> bool {
79 return *lhs.ptr_ != nullptr;
80 }
81
82 iterator(scan_buffer* buf) : buf_(buf) {
83 if (buf->ptr_ == buf->end_) {
84 ptr_ = get_sentinel();
85 return;
86 }
87 ptr_ = &buf->ptr_;
88 value_ = *buf->ptr_;
89 }
90
91 friend scan_buffer& get_buffer(iterator it) { return *it.buf_; }
92
93 public:
94 iterator() : ptr_(get_sentinel()), buf_(nullptr) {}
95
96 auto operator++() -> iterator& {
97 if (!buf_->try_consume()) ptr_ = get_sentinel();
98 value_ = *buf_->ptr_;
99 return *this;
100 }
101 auto operator++(int) -> iterator {
102 iterator copy = *this;
103 ++*this;
104 return copy;
105 }
106 auto operator*() const -> char { return value_; }
107
108 auto base() const -> const char* { return buf_->ptr_; }
109
110 friend auto to_contiguous(iterator it) -> maybe_contiguous_range;
111 friend auto advance(iterator it, size_t n) -> iterator;
112 };
113
114 friend auto to_contiguous(iterator it) -> maybe_contiguous_range {
115 if (it.buf_->is_contiguous()) return {it.buf_->ptr_, it.buf_->end_};

Callers 3

beginMethod · 0.50
endMethod · 0.50
vprintfFunction · 0.50

Calls

no outgoing calls

Tested by 2

beginMethod · 0.40
endMethod · 0.40