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

推導出第一個模板參數,其他模板參數默認

Deducing first template argument with other template parameters defaulted(推導出第一個模板參數,其他模板參數默認)
本文介紹了推導出第一個模板參數,其他模板參數默認的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

Gcc 和 clang 似乎不同意這段代碼是否應該編譯:

Gcc and clang seem to disagree on whether this code should compile or not:

#include <type_traits>

template <typename Signature, int N = 0>
struct MyDelegate { };

template <typename D>
struct signature_traits;

template <template <typename> class Delegate, typename Signature>
struct signature_traits<Delegate<Signature>>
{
    using type = Signature;
};

static_assert(std::is_same_v<
    void(int, int),
    signature_traits<MyDelegate<void(int, int)>>::type
>);

在此處查看 godbolt 輸出并嘗試一下.我在這里支持 clang,但 C++ 標準對此有何評論?

See godbolt output here and try it. I'm siding with clang here, but what does the C++ standard say about this?

一個后續問題 - 這可以在 clang 中工作嗎?

A follow-up question - can this be made to work in clang?

推薦答案

這是完全有效的代碼,gcc 是正確的.功能"是 在 C++17 中引入.這并不是真正的功能,因為它是一份缺陷報告.MyDelegate 匹配 signature_traits 的部分特化,所以它應該像 gcc 一樣正確.請注意,它有效,因為第二個模板參數是默認的.

This is perfectly valid code, and gcc is right. The "feature" was introduced in C++17. It's not really a feature because it is a defect report. MyDelegate matches the partial specialization of signature_traits, and so it should be taken as gcc correctly does. Note that it works because the second template parameter is defaulted.

clang 不編譯它的原因是因為那個缺陷報告有一個缺陷:P.它沒有在偏序中引入適當的變化,這是不太好,使之前的有效代碼再次變得模棱兩可.

The reason why clang doesn't compile it is because that defect report has a defect :P. It doesn't introduce the appropriate change in partial ordering, which is not really nice and makes previousy valid code ambiguous again.

預計很快就會修復,但與此同時,clang 決定將功能隱藏"在一個標志后面,-frelaxed-template-template-args.

It is expected to be fixed soon, but in the meanwhile, clang decided to "hide" the feature behind a flag, -frelaxed-template-template-args.

所以,只要在啟用該標志的情況下編譯就可以了.

So, just compile with that flag enabled and you should be fine.

這篇關于推導出第一個模板參數,其他模板參數默認的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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?(取消引用已刪除的指針總是會導致訪問沖突?)
主站蜘蛛池模板: 天堂国产 | 91精品国产美女在线观看 | 亚洲精品久久久一区二区三区 | 日韩在线免费播放 | 高清视频一区二区三区 | 久久精品国产亚洲 | 亚洲一区二区在线播放 | 久久一区二区免费视频 | 日本在线播放 | 日韩在线视频网址 | 伊人成人免费视频 | 久久综合成人精品亚洲另类欧美 | 久久国产香蕉 | 91色视频在线观看 | 密色视频| h片免费在线观看 | 亚洲国产精品成人 | 国产九九精品 | 男女啪啪高潮无遮挡免费动态 | 亚洲天堂中文字幕 | 91av久久久 | 久久久国产一区二区三区 | 国产精品久久久久久久午夜 | 国产精品欧美一区二区 | 日韩一区二区三区在线 | 欧美 日韩 视频 | 国产精品国产三级国产aⅴ入口 | 91毛片在线观看 | 97av在线| 日韩高清国产一区在线 | 国产成人精品免费视频大全最热 | 欧美日韩在线观看视频 | 亚洲一区视频 | 在线午夜 | 国产亚洲一区二区三区在线观看 | 狠狠艹 | 91精品久久久久久久久久 | 午夜视频在线观看一区二区 | 亚洲一区二区三区免费在线观看 | 成人av电影免费在线观看 | 羞羞视频网|