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

如何編寫`is_complete`模板?

How to write `is_complete` template?(如何編寫`is_complete`模板?)
本文介紹了如何編寫`is_complete`模板?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

在回答這個問題后,我試圖找到is_complete Boost 庫中的模板,我意識到 Boost.TypeTraits 中沒有這樣的模板.為什么Boost庫中沒有這樣的模板?它應該是什么樣子?

After answering this question I was trying to find is_complete template in Boost library and I realized that there is no such template in Boost.TypeTraits. Why there is no such template in Boost library? How it should look like?

//! Check whether type complete
template<typename T>
struct is_complete
{   
  static const bool value = ( sizeof(T) > 0 );
};

...

// so I could use it in such a way
BOOST_STATIC_ASSERT( boost::is_complete<T>::value );

上面的代碼是不正確的,因為將 sizeof 應用于不完整的類型是非法的.什么是好的解決方案?在這種情況下是否可以以某種方式應用 SFINAE?

The code above is not correct, because it is illegal to apply sizeof to an incomplete type. What will be a good solution? Is it possible to apply SFINAE in this case somehow?

好吧,如果不違反ODR 規則,一般無法解決這個問題,但是有一個特定于平臺的解決方案對我有用.

Well, this problem couldn't be solved in general without violating the ODR rule, but there is there a platform specific solution which works for me.

推薦答案

Alexey Malistov 給出的答案稍加修改即可用于 MSVC:

The answer given by Alexey Malistov can be used on MSVC with a minor modification:

namespace 
{
    template<class T, int discriminator>
    struct is_complete {  
      static T & getT();   
      static char (& pass(T))[2]; 
      static char pass(...);   
      static const bool value = sizeof(pass(getT()))==2;
    };
}
#define IS_COMPLETE(X) is_complete<X,__COUNTER__>::value

不幸的是,__COUNTER__ 預定義宏不是標準的一部分,因此它不適用于每個編譯器.

Unfortunately, the __COUNTER__ predefined macro is not part of the standard, so it would not work on every compiler.

這篇關于如何編寫`is_complete`模板?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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?(取消引用已刪除的指針總是會導致訪問沖突?)
主站蜘蛛池模板: 成人在线不卡 | 97caoporn国产免费人人 | 久久久久国产一区二区三区四区 | 成人亚洲精品久久久久软件 | 男女下面一进一出网站 | 日韩一区二区在线观看视频 | 国产精品久久久99 | 欧美成人精品在线观看 | 久久精品视频免费观看 | 日韩一区二区三区在线视频 | 日本一区二区三区在线观看 | 国产一区二区久久 | 国内精品久久久久久影视8 最新黄色在线观看 | 欧美激情在线精品一区二区三区 | 亚洲欧美日韩国产综合 | 久久久精品影院 | 九色 在线| 国产色婷婷久久99精品91 | 久久久久国产精品一区二区 | 福利片一区二区 | 色综合久久天天综合网 | 日韩在线观看视频一区 | 欧美一页 | www.婷婷| 欧美视频成人 | 精品久久久久久久久久久久久久 | 在线免费观看欧美 | 精品国产青草久久久久96 | 久久网一区二区三区 | 久久一级免费视频 | 久久狠狠 | 亚洲精品3 | 国产一区二区三区免费 | 亚洲精品在线91 | 久久精品国产一区二区电影 | 一区二区三区播放 | 91av导航| 精品视频在线观看 | 国产精品久久久久久妇女6080 | 国产精品免费视频一区 | 亚洲精品乱码久久久久久久久久 |