Turn MC*RegIterator into fully qualified iterators by deriving them from
iterator_adaptor_base. This makes mc_*_reg iterators redundant.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
This is an NFC to make D152098 simpler.
There is a bit of boilerplate in the form of overridden operator++ because forward iterators
require operator* to return by reference ( C++ <= 17 AFAIK). concat_range relies on this.
operator++ caches the value so that operator* can return a reference.
llvm/include/llvm/MC/MCRegisterInfo.h | ||
---|---|---|
542 | You could still expose isValid through MCSubRegIterator & avoid needing to add the second iterator here? No big deal either way, I guess. |
llvm/include/llvm/MC/MCRegisterInfo.h | ||
---|---|---|
542 | I tried to make them look like the usual iterators, that don't usually provide such kind of methods. But I guess having this method here won't hurt, will add. It would be nice if we had an adaptation of default_sentinel_t from C++20, then this method could be rutned into operator==. |
llvm/include/llvm/MC/MCRegisterInfo.h | ||
---|---|---|
513 | @dblaikie Could you comment on this? |
llvm/include/llvm/MC/MCRegisterInfo.h | ||
---|---|---|
513 | Ah I guess this won't change a thing, I would still need to be able to construct the proxy from some value, which I don't have in case of the end iterator. |
llvm/include/llvm/MC/MCRegisterInfo.h | ||
---|---|---|
513 | If you need something that isn't default constructible/can't just have an instance hanging around as a member like this, the next best thing would be std::optional<T> so it can be non-constructed. If the overhead of the extra bool/padding in std::optional is significant, you could maybe use a raw aligned buffer and /maybe/ conditionalize on the validity of the underlying iterator to decide whether there's an object in that buffer or not. But ensuring the code doesn't leak/fail to construct/destroy properly would be subtle. |
@dblaikie Could you comment on this?
This requires type type to be default constructible. In D152098 I add MCRegUnit that does not have a good default value. Maybe I should instead return a proxy object from operator* that will hold the value? Would that be correct w.r.t. iterator requirements? Probably factor the proxy out into a common (templated) base class, too.