久久久久久久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?(取消引用已刪除的指針總是會導致訪問沖突?)
主站蜘蛛池模板: 成人特级毛片 | 成人在线播放 | 中文字幕在线观看一区二区 | 91精品国产综合久久福利软件 | 亚洲日韩中文字幕一区 | 欧美一级视频免费看 | 国产成人综合久久 | 99精品视频免费观看 | 91视频.com| 亚洲福利网站 | 亚洲在线视频 | 久久精品国产99国产 | 九色91视频| 99久久精品一区二区成人 | 国产精品一区二区久久精品爱微奶 | av网站免费在线观看 | 懂色一区二区三区免费观看 | 天天射色综合 | 激情一区 | 日本三级全黄三级三级三级口周 | 91精品国产日韩91久久久久久 | 色视频免费 | 欧美日韩在线免费 | 亚洲精品欧洲 | 国产高清无av久久 | 天堂资源 | 蜜臀网| 国产精品揄拍一区二区 | 毛片毛片毛片毛片 | 97超碰免费 | 久久久精| 国产精品成人久久久久 | 成人免费大片黄在线播放 | 91精品国产综合久久精品图片 | 国产一区高清 | 中文字幕在线免费观看 | 午夜激情小视频 | 久久性av | 99精品99 | 精品一二区 | 中文字幕精品视频 |