I guess you've already checked the iterator requirements, but just in case; it's basically implementing everything on this page (and the "named requirements" pages linked from it): https://en.cppreference.com/w/cpp/named_req/RandomAccessIterator
The various
iterator_traitstypedefs are usually defined directly in the iterator class. The unspecialized version ofiterator_traitsjust redirects to typedefs defined in the class.These types should then be used for the return values of the various iterator functions, e.g.
difference_type operator-(const RecordIterator& it) const noexcept { return m_component_it - it.m_component_it; }Note: this originally returned
std::size_t. However, thedifference_typemust be signed (std::ptrdiff_tis correct). The other mathematical operations have the same issue.Unfortunately, we actually need
pointerandreferencetypedefs, notpointer_typeandreference_type.I don't think it's actually possible to fulfill the exact requirements for the reference type (ForwardIterator requires it to be
T&orT const&where T isvalue_type). Defining it asRecord<T>should work correctly in most cases though.For
pointer, you might simply define it asvoid, leave the arrow operator undefined, and see if anything breaks. This answer on stackoverflow implies thatreferenceandpointeraren't used inside the algorithms themselves, so you should be ok. Perhaps someone else with more knowledge can weigh in on this.
- Maybe the
Recordclass should be lighter weight - handling swap and move only, and providing a means to access the underlying component. At the momentRecordrather assumes that the components will be able to overload the relevant comparison operator, and that the algorithms using them will only need comparison operators. I could see, e.g. aLightingComponentneeding to sort lights by distance, or partition them with frustum culling, and might require custom comparators. Being able to access the underlying component fromRecordwould allow this, as well as use with a wider range of algorithms.
- Is it really necessary to allow an "invalid" Entity to exist?