HowTo get the previous element from std::deque?
For example I have an array with about 10 elements in it.
std::deque<int> d;
front_inserter(d) = 100;
front_inserter(d) = 200;
front_inserter(d) = 300;
...
front_inserter(d) = 900;
front_inserter(d) = 1000;
Question: how to find 900
element, without using []
access? If the size of the massive will be changes, for example to 123, how to find 122 element?
PS: I don't want to use []
becaus开发者_如何学运维e this method does not perform d[-1]
check...
Thanks.
use deque::at.
d.at(121)
If you mean a runtime check throwing in case of out of bound access you can use ::at(pos). If you mean d[-1] being the last element, d[-2] the second-last and so on (a-la Python) then you've to code your own (possibly template) function for that.
精彩评论