#include <list>
const size_t fixedListSize(5);
std::list<int> mylist(fixedListSize);
If you want it to always have exactly 5 elements, you would have to wrap it in the facade class to prevent insertion and erasure.
If this is really what you want, you better use a different container instead list, as, as noted in other answers, you will hide the most beneficial features list.
source
share