STL deque的at方法(4)
std::deque::at
reference at (size_type n);
const_reference at (size_type n) const;
Access element
Returns a reference to the element at position n in the deque container object.返回在特定位置元素的引用。
The function automatically checks whether n
該方法將自動檢測n的合法性,如果n超出了範圍,將丟擲out_of_range異常。另一個相似的是operator[]方法,但是不會檢測合法性。
例子:
#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.at(0)="<<di.at(0)<<endl; cout<<"di.at(2)="<<di.at(2)<<endl; cout<<"di.at(3)="<<di.at(3)<<endl; cout<<"di.at(4)="<<di.at(4)<<endl; cout<<"di.at(5)="<<di.at(5)<<endl; cout<<"di.at(-1)="<<di.at(-1)<<endl; }
Returns a reference to the element at position n in the deque container object.
返回deque容器特定位置的元素的引用。
The difference between this member function and member operator function operator[] is that deque::at signals if the requested position is out of range by throwing an out_of_range exception.
和operator[]方法不同的是at在n不合法的時候會跑出out_of_range方法。
Parameters
- n
- Position of an element in the container.
If this is greater than the deque size, an exception of type out_of_range is thrown.
Notice that the first element has a position of 0 (not 1).
Member type size_type is an unsigned integral type.
容器內元素的位置。
需要注意第一個元素的位置為0.
Return value
The element at the specified position in the container.返回特定位置元素的引用。
If the deque object is const-qualified, the function returns a const_reference. Otherwise, it returns a reference.Member types reference and const_reference are the reference types to the elements of the container (see deque member types).
Example
|
|
Output:
mydeque contains: 0 1 2 3 4 5 6 7 8 9
|
Complexity
Constant.Iterator validity
No changes.Data races
The container is accessed (neither the const nor the non-const versions modify the container).Element n is potentially accessed or modified by the caller. Concurrently accessing or modifying other elements is safe.
Exception safety
Strong guarantee: if an exception is thrown, there are no changes in the container.It throws out_of_range if n is out of bounds.
如果n不再範圍內將丟擲out_of_range異常。
——————————————————————————————————————————————————————————————————
//翻譯的不好的地方請多多指導,可以在下面留言或者點選左上方郵件地址給我發郵件,指出我的錯誤以及不足,以便我修改,更好的分享給大家,謝謝。
//今後的翻譯將以簡潔為主,翻譯其主要意思,不再每句翻譯。
轉載請註明出處:http://blog.csdn.net/qq844352155
author:天下無雙
Email:[email protected]
2014-9-1
於GDUT
——————————————————————————————————————————————————————————————————
相關推薦
STL deque的at方法(4)
原文地址:http://www.cplusplus.com/reference/deque/deque/at/ public member function <deque> std::deque::at reference at (size
深度學習模型壓縮方法(4)-----模型蒸餾(Distilling)與精細模型網路
前言 在前兩章,我們介紹了一些在已有的深度學習模型的基礎上,直接對其進行壓縮的方法,包括核的稀疏化,和模型的裁剪兩個方面的內容,其中核的稀疏化可能需要一些稀疏計算庫的支援,其加速的效果可能受到頻寬、稀疏度等很多因素的制約;而模型的裁剪方法則比較簡單明瞭,直接在原有的模型上剔
JavaScript基礎函式和詞法分析以及常用的內建物件和使用方法(4)
day52 參考:https://www.cnblogs.com/liwenzhou/p/8004649.html 函式 函式定義 JavaScript中的函式和Python中的非常類似,只是定義方式有點區別。 function foo(a, b) { console.log("a:"
ES5新增陣列方法(4):every
檢查陣列元素的每個元素是否符合條件。 // 陣列中的元素全部滿足指定條件返回true let arr = [1, 3, 5, 7, 9]; console.log(arr.every((value, index, array) => value > 10));// false
selenium頁面元素定位方法(4)——jQuery定位
jQuery介紹 jQuery是一個相容多瀏覽器的JavaScript庫,核心是write less,do more。jQuery定位方式實際上是呼叫jQuery庫的查詢功能,主要用於不能良好支援CSS定位方式的瀏覽器。如果頁面本身就引入了jQuery庫操作頁面
JQuery系列(4) - AJAX方法
type 一般來說 其他 don light spa none rouge 狀態信息 jQuery對象上面還定義了Ajax方法($.ajax()),用來處理Ajax操作。調用該方法後,瀏覽器就會向服務器發出一個HTTP請求。 $.ajax方法 $.ajax()的用法主要
C#中的方法傳參與switch、if結構(4)
判斷 1.2 菱形 條件表達式 執行 代碼 輸出 分類 簡易 一、方法傳參的2種方式 1、按值傳遞 傳遞的是值的副本,值會更改但未保留,值最終並未更改 2、按引用傳遞(形參用ref關鍵字修飾)【P86頁】 傳遞的是地址,值會更改且保留,值最終更改
設計模式解密(4)- 模板方法模式
編程人員 自己 ack 層次 check target hub 提取 images 1、簡介 定義:一個操作中算法的框架,而將一些步驟延遲到子類中,使得子類可以不改變算法的結構即可重定義該算法中的某些特定步驟。 模板方法模式,一般是為了統一子類的算法實現步驟,所使用
python手記(4)------列表(操作方法)
set += style then 字符 tro ttr scrip fault 1.增加——append、extend、insert list.append(item)————————給列表末尾增加條目 list.extend(可叠代對象)——————擴容列表,可增加列表
Vue深度學習(4)-方法與事件處理器
() 一個 span 修飾 語句 特殊變量 方法 left stop 方法處理器 可以用 v-on 指令監聽 DOM 事件: <div id="app"> <button v-on:click = "greet">Greet<
更改Mysql 密碼的4種方法(轉)
user p12 flush 忘記root密碼 localhost 提示 clas word root密碼 原文:http://www.jb51.net/article/39454.htm 方法1: 用SET PASSWORD命令 首先登錄MySQL。 格式:mysql&g
Appium 定位方法例子(4)
res imp fail bili https ora uia activit str 有朋友留言反應定位不到元素,沒錯,船長也為這個一直在頭疼,我用的App是原生安卓+webService+h5類型的,定位雖然沒問題,但是在進行操作的時候各種不通過……真的很頭疼啊……
java保留兩位小數4種方法(轉載)
cal AI maximum 保留兩位小數 tps 控制 .text int .html 喵喵最近經常遇到小數點保留的問題,轉載一篇Java裏面的幾種小數點位數控制方法。 這是轉載的原地址:https://www.cnblogs.com/chenrenshui/p/6128
python學習(4)--字符串格式化之format()方法
light 網站 pytho com date 其中 格式化字符串 ont python 一、格式化字符串的函數 str.format()增強了字符串格式化的功能。通過 {} 和 : 來代替以前的 % 。 其中format 函數可以接受不限個參數,位置可以不按順序。 st
4.4 類的方法(Methods)- 摘自 《SAP ABAP面向對象程序設計:原則、模式及實踐》
讀寫 圖片 solid ESS ng- tin 結果 必須 factor 《SAP ABAP面向對象程序設計:原則、模式及實踐》 https://book.douban.com/subject/30317853/ http://www.duokan.com/s
框架綜合實踐(4)-data資料讀取方法封裝
目的: 在實際的測試專案中,例如測試登陸的場景,可能需要多次輸入賬號和密碼進行登陸,此時需要將這些測試資料封裝在一個檔案中(檔案型別可以是csv、txt、excel等)。那麼我們就可以封裝一些方法來讀取檔案中的資料來實現資料驅動測試。 使用到的方法:enumerate() enumera
python3面向物件(4)之__new__方法和__init__方法
1.簡單來說__new__方法和__init__方法都是類中的內建方法;這兩個方法再例項化物件的時候會被自動呼叫; 2.__new__方法的呼叫在 __init__方法之前; 3.__new__方法中有個引數:cls ; __init__方法中有個引數是self&nbs
tensorflow學習(4):損失函式+優化方法
一、損失函式 提起損失函式,大概最常用的就是交叉熵和均方誤差了。 1.交叉熵損失函式:針對分類問題 假設某個樣例的正確答案是(1,0,0),預測值是[0.5,0.4,0.1] 那麼其交叉熵為H((1,0,0),(0.5,0.4,0.1))=-(1log0.5+0log0.4+0*log
多執行緒學習(4):三種實現Java多執行緒的方法:Thread、Callable和Runable 的比較與區別
2018年10月03日 目錄 前言 前言 JVM允許應用程式併發執行多執行緒:最常用的是兩個方法:(1)基礎Thread類,重寫run()方法;(2)或實現Runnable 介面,實現介面的run()方法;(3)另外一種方法是:實現callable 介面
《C語言程式設計:現代方法(第2版)(K.N.King 著)》學習筆記五:C語言基本概念(4)
2.7 識別符號 在編寫程式時,需要對變數、函式、巨集和其他實體進行命名。這些名字稱為識別符號(identifier)。在C語言中,識別符號可以含有字母、數字和下劃線,但是必須以字母或者下劃線開頭。