C_and_CPP 板


LINE

看到一篇文章 https://www.fluentcpp.com/2018/07/13/the-incredible-const-reference-that-isnt- const/ 我覺得蠻有趣的 其中一段提到 The get() method returns a const T&, with T coming from template T. In our sec ond case, T is int&, so const T& is const (int&) & 這邊。const (int&) & 為什麼他可以直接看出這const 是修飾reference (int&) & const 然後就是這邊感覺多了一個& 也許他這段有解釋 So being氲onst氽oesn’t say much for a reference, since they always乸re氲onst, since they cannot rebind. This implies that氲onst (int&)湶s effectively the s ame type as湶nt&. 但實在看不是很懂 這邊能不能套用forwarding reference的規則 int& & collapse成 int&, 所以變成 int & const ,我不確定,而且覺得不能這樣想 而且正常試圖寫 https://ideone.com/95tBGJ 無法寫得出這個語意. 請問各位有什麼規則需要釐清的嗎 謝謝 --



※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 39.8.199.223
※ 文章網址: https://webptt.com/m.aspx?n=bbs/C_and_CPP/M.1531477341.A.D50.html ※ 編輯: lovejomi (39.8.199.223), 07/13/2018 18:26:31 ※ 編輯: lovejomi (39.8.199.223), 07/13/2018 18:35:48
1F:→ Sidney0503: So being氲onst氽oesn’t say much for a reference, 07/13 18:58
2F:→ Sidney0503: since they always乸re氲onst, since they cannot reb 07/13 18:59
3F:→ Sidney0503: 這種語言我也看不懂 07/13 18:59
4F:→ Lipraxde: So being const doesn’t say much for a reference, s 07/13 19:23
5F:→ Lipraxde: ince they always are const, since they cannot rebin 07/13 19:23
6F:→ Lipraxde: d. This implies that const (int&) is effectively th 07/13 19:23
7F:→ Lipraxde: e same type as int&. 07/13 19:23
8F:→ Lipraxde: 大概是這樣? 07/13 19:23
9F:推 shadow0326: 亂碼那段是說這件事 https://tinyurl.com/y8gkkcng 07/13 21:42
10F:→ shadow0326: 他是一層一層把語意消掉,T& const 等價於 T& 07/13 21:44
11F:→ shadow0326: 而 (T&)& 等價於 T&,所以得到 (T&) const & 等價於T& 07/13 21:45
12F:→ lovejomi: 我也不知道為什麼手機貼上都正確 送出就變亂碼...moptt 07/13 23:41
13F:→ lovejomi: 所以簡單講就是int&& collapse 成int&, 然後int&const沒 07/13 23:44
14F:→ lovejomi: 意義,所以const直接忽略? 07/13 23:44
15F:→ sarafciel: const (int&) & =>const 修飾 (int &) =>reference自帶 07/14 00:17
16F:→ sarafciel: const語意,去掉const =>int & & =>做collapse=>int &( 07/14 00:17
17F:→ sarafciel: 相當於 int const *) 我感覺是這樣 07/14 00:17







like.gif 您可能會有興趣的文章
icon.png[問題/行為] 貓晚上進房間會不會有憋尿問題
icon.pngRe: [閒聊] 選了錯誤的女孩成為魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一張
icon.png[心得] EMS高領長版毛衣.墨小樓MC1002
icon.png[分享] 丹龍隔熱紙GE55+33+22
icon.png[問題] 清洗洗衣機
icon.png[尋物] 窗台下的空間
icon.png[閒聊] 双極の女神1 木魔爵
icon.png[售車] 新竹 1997 march 1297cc 白色 四門
icon.png[討論] 能從照片感受到攝影者心情嗎
icon.png[狂賀] 賀賀賀賀 賀!島村卯月!總選舉NO.1
icon.png[難過] 羨慕白皮膚的女生
icon.png閱讀文章
icon.png[黑特]
icon.png[問題] SBK S1安裝於安全帽位置
icon.png[分享] 舊woo100絕版開箱!!
icon.pngRe: [無言] 關於小包衛生紙
icon.png[開箱] E5-2683V3 RX480Strix 快睿C1 簡單測試
icon.png[心得] 蒼の海賊龍 地獄 執行者16PT
icon.png[售車] 1999年Virage iO 1.8EXi
icon.png[心得] 挑戰33 LV10 獅子座pt solo
icon.png[閒聊] 手把手教你不被桶之新手主購教學
icon.png[分享] Civic Type R 量產版官方照無預警流出
icon.png[售車] Golf 4 2.0 銀色 自排
icon.png[出售] Graco提籃汽座(有底座)2000元誠可議
icon.png[問題] 請問補牙材質掉了還能再補嗎?(台中半年內
icon.png[問題] 44th 單曲 生寫竟然都給重複的啊啊!
icon.png[心得] 華南紅卡/icash 核卡
icon.png[問題] 拔牙矯正這樣正常嗎
icon.png[贈送] 老莫高業 初業 102年版
icon.png[情報] 三大行動支付 本季掀戰火
icon.png[寶寶] 博客來Amos水蠟筆5/1特價五折
icon.pngRe: [心得] 新鮮人一些面試分享
icon.png[心得] 蒼の海賊龍 地獄 麒麟25PT
icon.pngRe: [閒聊] (君の名は。雷慎入) 君名二創漫畫翻譯
icon.pngRe: [閒聊] OGN中場影片:失蹤人口局 (英文字幕)
icon.png[問題] 台灣大哥大4G訊號差
icon.png[出售] [全國]全新千尋侘草LED燈, 水草

請輸入看板名稱,例如:Gossiping站內搜尋

TOP