is std::vector same as array[number]? [duplicate]



Possible Duplicate:
Are std::vector elements guaranteed to be contiguous?

does std::vector always contain the data in sequential memory addresses as array[number]?





For all types except bool, the standard requires the elements are contiguous in memory:

23.2.4/1 … The elements of a vector are stored contiguously, meaning that if v is a vector where T is some type other than bool, then it obeys the identity &v[n] == &v[0] + n for all 0 <= n < v.size()

Do keep in mind that std::vector<bool> has special requirements and is not the same as an array of bool.


[], [], []

Facebook Comments

Post a comment