I want something that provide:
std::list head;
std::list::node node;
while (node = head->next) {
do something with this node
};
It is rather weird to me that a list does not have a next pointer.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The actual implementation of the list is hidden. Since the standard dictates the the insertion and erasion of an element at a given position should be possible in constant time we can assume that something like a node is going to be used:
However, the important thing about C++ container is that they all provide the same interface to actually traverse the content: iterators:
If you think about the list as a C-style object with
the loop above is somewhat equivalent to
However, things like
it = it->nextare hidden in the actual implementation of thestd::list::iterator. Since they provide an almost* unified interface for all classes you should learn to use them.* Some do actually provide a little bit more functionality than others, for example
RandomAccessIteratorsvs.BidirectionalIterators, but this is something you will learn later.