久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

帶有包擴(kuò)展的可變函數(shù)模板不在最后一個(gè)參數(shù)中

Variadic function template with pack expansion not in last parameter(帶有包擴(kuò)展的可變函數(shù)模板不在最后一個(gè)參數(shù)中)
本文介紹了帶有包擴(kuò)展的可變函數(shù)模板不在最后一個(gè)參數(shù)中的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

限時(shí)送ChatGPT賬號(hào)..

我想知道為什么下面的代碼不能編譯:

I am wondering why the following code doesn't compile:

struct S
{
    template <typename... T>
    S(T..., int);
};

S c{0, 0};

此代碼無(wú)法同時(shí)使用 clang 和 GCC 4.8 進(jìn)行編譯.這是 clang 的錯(cuò)誤:

This code fails to compile with both clang and GCC 4.8. Here is the error with clang:

test.cpp:7:3: error: no matching constructor for initialization of 'S'
S c{0, 0};
  ^~~~~~~
test.cpp:4:5: note: candidate constructor not viable: requires 1 argument, but 2 were provided
    S(T..., int);
    ^

在我看來(lái)這應(yīng)該可行,并且 T 應(yīng)該被推導(dǎo)出為長(zhǎng)度為 1 的包.

It seems to me that this should work, and T should be deduced to be a pack of length 1.

如果標(biāo)準(zhǔn)禁止做這樣的事情,有誰(shuí)知道為什么?

If the standards forbids doing things like this, does anyone know why?

推薦答案

因?yàn)楫?dāng)一個(gè)函數(shù)形參包不是最后一個(gè)形參時(shí),那么模板形參包就不能從中推導(dǎo)出來(lái),模板實(shí)參推導(dǎo)會(huì)忽略它.

Because when a function parameter pack is not the last parameter, then the template parameter pack cannot be deduced from it and it will be ignored by template argument deduction.

因此將兩個(gè)參數(shù) 0, 0, int 進(jìn)行比較,結(jié)果不匹配.

So the two arguments 0, 0 are compared against , int, yielding a mismatch.

這樣的推導(dǎo)規(guī)則需要涵蓋很多特殊情況(比如兩個(gè)參數(shù)包并排出現(xiàn)時(shí)會(huì)發(fā)生什么).由于參數(shù)包是 C++11 中的一個(gè)新特性,相應(yīng)提案的作者在起草規(guī)則時(shí)比較保守.

Deduction rules like this need to cover many special cases (like what happens when two parameter packs appear next to each other). Since parameter packs are a new feature in C++11, the authors of the respective proposal drafted the rules conservatively.

請(qǐng)注意,如果沒(méi)有以其他方式推導(dǎo)出,尾隨模板參數(shù)包將為空.所以當(dāng)你用一個(gè)參數(shù)調(diào)用構(gòu)造函數(shù)時(shí),事情就會(huì)起作用(注意這里模板參數(shù)包和函數(shù)參數(shù)包的區(qū)別.前者是拖尾的,后者不是).

Note that a trailing template parameter pack will be empty if it is not otherwise deduced. So when you call the constructor with one argument, things will work (notice the difference of template parameter pack and function parameter pack here. The former is trailing, the latter is not).

這篇關(guān)于帶有包擴(kuò)展的可變函數(shù)模板不在最后一個(gè)參數(shù)中的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Difference between std::reference_wrapper and simple pointer?(std::reference_wrapper 和簡(jiǎn)單指針的區(qū)別?)
Difference between const. pointer and reference?(常量之間的區(qū)別.指針和引用?)
How to access the contents of a vector from a pointer to the vector in C++?(c++ - 如何從指向向量的指針訪問(wèn)向量的內(nèi)容?)
Meaning of *amp; and **amp; in C++(*amp; 的含義和**amp;在 C++ 中)
Why can#39;t I do polymorphism with normal variables?(為什么我不能對(duì)普通變量進(jìn)行多態(tài)?)
Dereferencing deleted pointers always result in an Access Violation?(取消引用已刪除的指針總是會(huì)導(dǎo)致訪問(wèn)沖突?)
主站蜘蛛池模板: 日韩中文字幕免费 | 国产 日韩 欧美 在线 | av网站免费在线观看 | 黄色一级大片在线免费看产 | 国产精品免费高清 | 久久噜噜噜精品国产亚洲综合 | 成人免费在线观看视频 | 国产精品精品久久久 | 久久久高清 | 情侣酒店偷拍一区二区在线播放 | 色婷婷久久久久swag精品 | 久久久福利| 久久精品免费观看 | 日本黄色免费大片 | 久久精品国产一区二区电影 | 亚洲精品一区国语对白 | 操到爽 | 亚洲 欧美 激情 另类 校园 | 蜜桃日韩 | 91精品久久久久久久久久小网站 | 在线观看av免费 | 久久成人免费视频 | 亚洲区一 | 国产精品久久九九 | 国产一区二区三区四区在线观看 | 亚洲精选久久 | 本道综合精品 | 羞羞视频免费在线观看 | 精品国产99 | 在线欧美亚洲 | 免费性视频 | 国产精品久久久久久久久久免费看 | 日韩一区二区在线播放 | 精品一二区 | 成年人在线观看 | 国产网站在线播放 | av国产精品毛片一区二区小说 | 一区二区免费在线观看 | 91人人澡人人爽 | 91亚洲一区 | 中文字幕在线一区二区三区 |