Is there a way to check if a sequence container is contiguous in memory? Something like:
#include
#include
#include
No. The C++ Standard guarantees there are no false negatives. (i.e., std::vector
, std::string
, std::array
, and basic arrays are promised to be stored contiguously).
However, the C++ Standard doesn't guarantee there are no false positives.
int main() {
std::unique_ptr n1(new Node);
std::unique_ptr n2(new Node);
n1->next = n2; // n1 and n2 might be contiguous, but might not be
}
Thus, your type trait could be wrong some of the time. If it's wrong some of the time, it's not a type trait; rather, it's an instance trait.