erase
语法:
1 2 |
iterator erase( iterator pos ); iterator erase( iterator start, iterator end ); |
erase()函数删除以pos指示位置的元素, 或者删除start和end之间的元素。 返回值是一个迭代器,指向最后一个被删除元素的下一个元素。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
源代码 /** * @brief Remove element at given position. * @param position Iterator pointing to element to be erased. * @return An iterator pointing to the next element (or end()). * * This function will erase the element at the given position and thus * shorten the %list by one. * * Due to the nature of a %list this operation can be done in * constant time, and only invalidates iterators/references to * the element being removed. The user is also cautioned that * this function only erases the element, and that if the element * is itself a pointer, the pointed-to memory is not touched in * any way. Managing the pointer is the user's responsibilty. */ iterator erase(iterator __position); /** * @brief Remove a range of elements. * @param first Iterator pointing to the first element to be erased. * @param last Iterator pointing to one past the last element to be * erased. * @return An iterator pointing to the element pointed to by @a last * prior to erasing (or end()). * * This function will erase the elements in the range @a * [first,last) and shorten the %list accordingly. * * Due to the nature of a %list this operation can be done in * constant time, and only invalidates iterators/references to * the element being removed. The user is also cautioned that * this function only erases the elements, and that if the * elements themselves are pointers, the pointed-to memory is not * touched in any way. Managing the pointer is the user's * responsibilty. */ iterator erase(iterator __first, iterator __last) { while (__first != __last) __first = erase(__first); return __last; } |
测试代码
测试结果
9 8 7 6 5 4 3 2 1 0
9 7 6 5 4 3 2 1 0
0
You suggested that exceptionally well. she gives him viagra
You said it nicely.. atarax
Fantastic data. Cheers. metformin xr
Really lots of wonderful advice! canadian pharmacies-24h
With thanks! Awesome stuff! provigil
Superb forum posts. Kudos! online pharmacies canada
Thanks, Useful information. canada pharmacy
Nicely put, Many thanks. lovegra
Very good forum posts. Cheers! top rated canadian pharmacies online
You said it very well.. hemp oil for pets