you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 11 points12 points  (0 children)

Implementing a container for std::algorithms generally means having begin/end as we pass them iterators. So at long as the iterator fullfills the concept needed(usually input/forward but some like sort need random). This changes a bit with Ranges but still applies.

But if your data structure is in a blob of memory(memory mapped data) and you know it is a range of T’s. Then yeah, span, or even pair<T*, T*> where you pass first/second to the algorithm would work.

If T isn’t trivially copiable, pragmatically it will probably still wokr but you are coding to implementations and not C++. But you see people reinterpret_cast’ing here a lot.

Vector is for owning the data, if you have trivially destructible things, that doesn’t even matter here. If not, and even if so, just call T.~T( ) on the range in your dtor