As the title says, I was wondering if constant-time/O(1) access to a container does imply that memory is necessarily contiguous at some point. When I say contiguous I mean if pointers can be compared with relational operators at some point without invoking undefined behavior.
Take eg std::deque: it does not guarantee that all its elements are stored contiguously (i.e in the same memory array), but is it correct to say that as std::deque satisfy the requirements of a Random Access Iterator, memory will be contiguous at some point independently of the implementation?
I am new to C++ so in case what I said above does not make sense: suppose I was going to implement random access iterators in C. Can
typedef struct random_access_iterator {
void *pointer; /*pointer to element */
void *block; /* pointer to the memory array
* so in case of comparing iterators
* where pointer does not point to addresses in the same array
* it can be used to comparisons instead*/
/* implement other stuff */
} RandomIter;
be used to generically express a similar mechanism to that of C++ random access iterators (considering that even if pointer do not, block will always point to addresses in the same memory array in iterators of the same container)?
EDIT: just to clarify, constant-time here is used to denote constant-time random access