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

確定 Type 是否是模板函數中的指針

Determine if Type is a pointer in a template function(確定 Type 是否是模板函數中的指針)
本文介紹了確定 Type 是否是模板函數中的指針的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

如果我有一個模板函數,例如這樣:

If I have a template function, for example like this:

template<typename T>
void func(const std::vector<T>& v)

有什么方法可以在函數內確定 T 是否是指針,或者我必須為此使用另一個模板函數,即:

Is there any way I can determine within the function whether T is a pointer, or would I have to use another template function for this, ie:

template<typename T>
void func(const std::vector<T*>& v)

謝謝

推薦答案

確實,模板可以做到這一點,部分模板特化:

Indeed, templates can do that, with partial template specialization:

template<typename T>
struct is_pointer { static const bool value = false; };

template<typename T>
struct is_pointer<T*> { static const bool value = true; };

template<typename T>
void func(const std::vector<T>& v) {
    std::cout << "is it a pointer? " << is_pointer<T>::value << std::endl;
}

如果在函數中你做的事情只對指針有效,你最好使用單獨函數的方法,因為編譯器對整個函數進行類型檢查.

If in the function you do things only valid to pointers, you better use the method of a separate function though, since the compiler type-checks the function as a whole.

但是,您應該為此使用 boost,它也包括:http://www.boost.org/doc/libs/1_37_0/libs/type_traits/doc/html/boost_typetraits/reference/is_pointer.html

You should, however, use boost for this, it includes that too: http://www.boost.org/doc/libs/1_37_0/libs/type_traits/doc/html/boost_typetraits/reference/is_pointer.html

這篇關于確定 Type 是否是模板函數中的指針的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 | www国产成人免费观看视频,深夜成人网 | 国产一级淫片a直接免费看 免费a网站 | 天天久久 | 欧美极品视频在线观看 | 久久婷婷av | 天天综合日日夜夜 | 国产农村妇女精品一二区 | 人人性人人性碰国产 | 超碰520| 亚洲精品一 | 91欧美精品 | 亚洲1区| 亚洲一区二区三区在线播放 | 毛片a级 | 久久99视频这里只有精品 | 亚洲乱码一区二区三区在线观看 | 久久综合狠狠综合久久 | 91在线影院 | 国产91九色 | 91精品午夜窝窝看片 | 日韩精品一区二区在线 | 粉嫩粉嫩芽的虎白女18在线视频 | 精品视频999| 国产中文一区二区三区 | 成年网站在线观看 | 精品久久久久久国产 | www.久久久.com | 欧美一级毛片在线播放 | 网络毛片 | 操操网站 | 色999视频 | 久久网站免费视频 | 国产偷久久一级精品60部 | av资源中文在线天堂 | 国内久久| 日韩欧美国产精品一区二区 | 中文字幕一区二区三区四区五区 | 免费视频二区 | 久久久久国产一区二区 |