[問題] C++11的type_traits如何實做?
看板C_and_CPP (C/C++)作者GameHeven (Mark Williams)時間12年前 (2013/10/20 09:58)推噓2(2推 0噓 4→)留言6則, 5人參與討論串1/1
查了一下英文網站,發覺C++11正式導入type_traits
標頭檔就是<type_traits>
看了一下內容,有一些還蠻豪洨的,例如說這幾個
is_enum
is_union
is_class
is_literal_type
我實在不曉得這幾個要怎麼實做。唯一的方法是編譯器自己做。
那就等於實做方法各平台都不一樣。
請問這樣理解是否正確?
或是說有什麼唬爛到爆的神技巧?
=====================================
後來查了一下boost的網頁,的確是要編譯器幫忙。
boost還有註明編譯器版本
Compiler Compatibility: Without (some as yet unspecified) help from the
compiler, we cannot distinguish between union and class types, as a result
this type will erroneously inherit from true_type for union types. See also
is_union. Currently (May 2011) compilers more recent than Visual C++ 8,
GCC-4.3, Greenhills 6.0, Intel-11.0, and Codegear have the necessary compiler
intrinsics to ensure that this trait "just works". You may also test to see
if the necessary intrinsics are available by checking to see if the macro
BOOST_IS_CLASS is defined.
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 220.129.167.247
※ 編輯: GameHeven 來自: 220.129.167.247 (10/20 10:12)
推
10/20 10:16, , 1F
10/20 10:16, 1F
→
10/20 10:56, , 2F
10/20 10:56, 2F
→
10/20 10:56, , 3F
10/20 10:56, 3F
推
10/20 11:38, , 4F
10/20 11:38, 4F
→
10/20 13:13, , 5F
10/20 13:13, 5F
※ 編輯: GameHeven 來自: 220.129.167.247 (10/20 14:39)
→
10/20 15:01, , 6F
10/20 15:01, 6F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章