STLdeque的clear方法(9)


STLdeque的clear方法(9)

原文地址:http://www.cplusplus.com/reference/deque/deque/clear/
public member function
<deque>

std::deque::clear

void clear() noexcept;
Clear content

Removes all elements from the deque (which are destroyed), leaving
the container with a size of 0.

移除deque的所有元素(并且销毁),使容器大小为0.

例子:

#include <iostream>
#include <deque>
#include <vector>
using namespace std;
int main()
{
	deque<int> di{1,2,3,4,5};
	for(int i:di)
		cout<<i<<" ";
	cout<<endl;

	di.clear();
	cout<<"after di.clear()"<<endl;
	for(int i:di)
		cout<<i<<" ";
	cout<<endl;

}

运行截图:


Parameters

none


Return value

none


Example

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
// clearing deques
#include <iostream>
#include <deque>

int main ()
{
  unsigned int i;
  std::deque<int> mydeque;
  mydeque.push_back (100);
  mydeque.push_back (200);
  mydeque.push_back (300);

  std::cout << "mydeque contains:";
  for (std::deque<int>::iterator it = mydeque.begin(); it!=mydeque.end(); ++it)
    std::cout << ' ' << *it;
  std::cout << '\n';

  mydeque.clear();
  mydeque.push_back (1101);
  mydeque.push_back (2202);

  std::cout << "mydeque contains:";
  for (std::deque<int>::iterator it = mydeque.begin(); it!=mydeque.end(); ++it)
    std::cout << ' ' << *it;
  std::cout << '\n';

  return 0;
}

Output:

mydeque contains: 100 200 300
mydeque contains: 1101 2202



Complexity

Linear in size (destructions).

与大小线性相关。


Iterator validity

All iterators, pointers and references related to this container are invalidated.

所有的迭代器,引用以及值朕都将失效。


Data races

The container is modified.
All contained elements are modified.

容器将被修改。

容器所有元素都将被修改。


Exception safety

No-throw guarantee: this member function never throws exceptions.

该方法不会抛出异常。



——————————————————————————————————————————————————————————————————

//翻译的不好的地方请多多指导,可以在下面留言或者点击左上方邮件地址给我发邮件,指出我的错误以及不足,以便我修改,更好的分享给大家,谢谢。

转载请注明出处:http://blog.csdn.net/qq844352155
author:天下无双

Email:coderguang@gmail.com

2014-9-1

于GDUT

——————————————————————————————————————————————————————————————————



发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注