STL dequeのback方法(5)

3602 ワード

原文の住所:http://www.cplusplus.com/reference/deque/deque/back/
public member function
<deque>
std:deque:back
      reference back();
const_reference back() const;
Access last element
Returns a reference to the last element in the container.
コンテナの最後の要素の参照を返します.
ユニケメン deque:end,which returns an iterator just past this element,this function returns a direct reference.
endとは異なり、endは、参照を返すために、1つのローズマリーを返します.
Calling this function on an empty container causes undefined behavior.
空の容器にこの方法を呼び出すと定義された挙動になります.
例:
#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;
	cout<<"di.back()="<<di.back()<<endl;
	
	deque<double> dd;
	cout<<"dd.back()="<<dd.back()<<endl;
	


}
はスクリーンショットを実行します.
STL deque的back方法(5)_第1张图片
パラメータ
none
Return value
A reference to the last element in the deque container.
dequeの最後の要素の参照を返します.
If the deque object is const-qualifed,the function returns a constreference.Otherwise,it returns a reference.Member types reference and constreference are the reference types to the elemens of the container(see) deque member types)
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 
// deque::back #include <iostream> #include <deque> int main () { std::deque<int> mydeque; mydeque.push_back(10); while (mydeque.back() != 0) mydeque.push_back ( mydeque.back() -1 ); std::cout << "mydeque contains:"; for (std::deque<int>::iterator it = mydeque.begin(); it!=mydeque.end(); ++it) std::cout << ' ' << *it; std::cout << '
'; return 0; }
Edit&Run
Output:
mydeque contains: 10 9 8 7 6 5 4 3 2 1 0 
Coplexity
コンサート
Iterator validity
No changes.
Data races
The container is accessed(neither the const nor the non-const versions modify the container).The last element is potenttially accessed or modified by the caller.Concerentlyaccessing or modiscine accessing or modity modischer.ef the Enther.ement ements.ements.emens.ement.emens.ement.
Exception safety
If the container is not empty,the function never throws exceptions.
Otherwise,it causes undefined behavior.
————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
//翻訳のよくないところをご指導ください.下のメッセージを残したり、左上のメールアドレスをクリックしてメールしてください.私の間違いと不足を指摘してください.修正して、もっと良いのを皆さんに共有できます.ありがとうございます.
//今後の翻訳は簡潔を主とし、主な意味を翻訳します.
転載は出典を明記してください.http://blog.csdn.net/qq844352155 author:天下無双
メール:[email protected]
2014-9-1
GDUTで
————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————