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

g++ 不采用可變參數推導指南,clang++ 采用-誰是正

Variadic deduction guide not taken by g++, taken by clang++ - who is correct?(g++ 不采用可變參數推導指南,clang++ 采用-誰是正確的?)
本文介紹了g++ 不采用可變參數推導指南,clang++ 采用-誰是正確的?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

考慮以下代碼:

template <typename... Types>
struct list
{
    template <typename... Args>
    list(Args...) 
    {
        static_assert(sizeof...(Types) > 0);
    }
};

template <typename... Args>
list(Args...) -> list<Args...>;

int main()
{
    list l{0, 0.1, 'a'};
}

我希望 decltype(l)list.不幸的是,g++ 7.2g++ trunk 未能通過靜態斷言.clang++ 5.0.0clang++ trunk 編譯并按預期工作.

I would expect decltype(l) to be list<int, double, char>. Unfortunately, g++ 7.2 and g++ trunk fail the static assertion. clang++ 5.0.0 and clang++ trunk compile and work as expected.

godbolt.org 一致性視圖

這是一個 g++ 錯誤嗎?或者有什么理由不應該在這里遵循演繹指南?

Is this a g++ bug? Or Is there a reason why the deduction guide should not be followed here?

在構造函數上添加 SFINAE 約束似乎提供了所需的行為:

Adding a SFINAE constraint on the constructor seems to provide the desired behavior:

template <typename... Args, 
          typename = std::enable_if_t<sizeof...(Args) == sizeof...(Types)>>
list(Args...) 
{
    static_assert(sizeof...(Types) > 0);
}

godbolt.org 一致性視圖

推薦答案

這是 gcc 錯誤 80871.問題是,我們最終得到了這組推演的候選對象:

This is gcc bug 80871. The issue is, we end up with this set of candidates for deduction:

template <class... Types, class... Args>
list<Types...> __f(Args... ); // constructor

template <class... Args>
list<Args...>  __f(Args... ); // deduction-guide

兩者都是有效的(Types... 在第一種情況下可以推斷為空),但是這里的調用應該是模棱兩可的 - 兩者都不比另一個更專業.Types... 不參與這里的排序(類似于 [temp.deduct.partial]/12).所以正確的行為是繼續下一個決勝局,它贊成演繹指南.因此,這應該是一個 list.

Both are valid (Types... can deduce as empty in the first case), but the call here should be ambiguous - neither is more specialized than the other. Types... does not participate in ordering here (similar to the example in [temp.deduct.partial]/12). So the correct behavior is to proceed to the next tiebreaker, which favors deduction-guides. Hence, this should be a list<int, double, char>.

然而,gcc 的行為是有利于構造函數,因此 static_assert 觸發器因為 Types... 在這種情況下確實是空的.

However, gcc's behavior is to favor the constructor, hence the static_assert triggers becuase Types... would indeed be empty in that situation.

這篇關于g++ 不采用可變參數推導指南,clang++ 采用-誰是正確的?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

Difference between std::reference_wrapper and simple pointer?(std::reference_wrapper 和簡單指針的區別?)
Difference between const. pointer and reference?(常量之間的區別.指針和引用?)
How to access the contents of a vector from a pointer to the vector in C++?(c++ - 如何從指向向量的指針訪問向量的內容?)
Meaning of *amp; and **amp; in C++(*amp; 的含義和**amp;在 C++ 中)
Why can#39;t I do polymorphism with normal variables?(為什么我不能對普通變量進行多態?)
Dereferencing deleted pointers always result in an Access Violation?(取消引用已刪除的指針總是會導致訪問沖突?)
主站蜘蛛池模板: 日韩一区二区三区在线视频 | 中文福利视频 | 国产精品久久久久久久久久久免费看 | 国产亚洲一级 | 色久影院| 一区二区三区网站 | 一区二区三区免费在线观看 | 99国内精品久久久久久久 | 成人在线观看免费 | 欧美激情在线播放 | 亚洲国产第一页 | 免费av电影网站 | 99精品视频免费观看 | 嫩草视频网 | 免费xxxx大片国产在线 | 日本福利在线 | 久久精品亚洲精品国产欧美 | 四虎最新视频 | 日本精品久久久久久久 | 成人精品一区二区 | 亚洲精品乱码久久久久久黑人 | 在线日韩 | 97日日碰人人模人人澡分享吧 | 美女视频h | 久亚州在线播放 | 免费在线观看成人 | 日本三级网站在线观看 | 欧美一区二区三区视频在线播放 | 午夜视频一区 | 天天艹 | 91精品国产乱码久久久久久久久 | 欧美在线视频一区二区 | 国产精品欧美日韩 | 国产一区二区在线免费观看 | 精品一区在线看 | 欧美国产一区二区 | 精品亚洲一区二区三区 | 久久久噜噜噜久久中文字幕色伊伊 | 一区二区三区日韩精品 | 中文字幕精品视频 | 国产精品视频入口 |