[問題] C++11的type_traits如何實做?

看板C_and_CPP (C/C++)作者 (Mark Williams)時間12年前 (2013/10/20 09:58), 編輯推噓2(204)
留言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
應該都是compiler實作無誤
10/20 11:38, 4F

10/20 13:13, , 5F
type_traits是boost就有提供,或許上面的都可在boost找到
10/20 13:13, 5F
※ 編輯: GameHeven 來自: 220.129.167.247 (10/20 14:39)

10/20 15:01, , 6F
部分的type_trait都是透過編譯器實作
10/20 15:01, 6F
文章代碼(AID): #1IOpYqqg (C_and_CPP)
文章代碼(AID): #1IOpYqqg (C_and_CPP)