Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does std::list guarantee that items will never be moved to a different memory location? [duplicate]

Tags:

c++

list

stl

Is it guaranteed that once std::list or std::forward_list item is allocated, it will remain at the same memory location (address) until destroyed? Except, of course, for the list itself being copied.

like image 381
Violet Giraffe Avatar asked Mar 19 '23 09:03

Violet Giraffe


1 Answers

If you look at the documentation for all the functions which don't destroy elements, (insert, emplace, push_back, etc...), you will see that they have a note that "no references are invalidated", which is equivalent to what you are asking (objects staying at the same memory location). So, yes.

like image 112
Benjamin Lindley Avatar answered Apr 09 '23 01:04

Benjamin Lindley