list<int> Object;
int someobject = Object[2];
It seems so trivial, I must be missing something.
Thanks,
list<int> Object;
int someobject = Object[2];
It seems so trivial, I must be missing something.
Thanks,
/* Create copy of list (so we can destroy it)*/list<int> ObjectList = Object;int size = (int)Object.size(); /* Cycle through values by popping front */ for(int s = 0; s < size; s++) { int o = ObjectList.front(); DoSomethingToObject(o); ObjectList.pop_front(); }
for(list<int>::iterator I = Object.begin(); I != Object.end(); ++I){ int o = *I;}
#include<iostream>#include<list>#include<algorithm>void DoSomething(int i){ std::cout << i;}int main(){ std::list<int> Object; Object.push_back(1); Object.push_back(2); Object.push_back(3); std::for_each(Object.begin(), Object.end(), DoSomething);}
Quote:Original post by Endurion
Even if it's not optimal it would be very convenient. But in this regard the STL is failing spectacularely.
Quote:Original post by Captain PYes, but random access isn't needed at all in this example.
A std::vector or std::deque is probably a better choice for this case. Those do allow random access.
Quote:Original post by Haptic
Hey all,
This seems like a really dumb question but I can't figure it out.
I have a list:
*** Source Snippet Removed ***
Is there a way to access values in the middle of the list like you can with an array (by index), and without removing it from the list? For example:
It seems so trivial, I must be missing something.int someobject = Object[2];
Thanks,