Re: [問題] 一個有意思的問題 vector <const int>

看板C_and_CPP作者 (CA)時間14年前 (2009/12/20 00:47), 編輯推噓0(001)
留言1則, 1人參與, 最新討論串2/3 (看更多)
用 type-trait 看了一下: using std::cout; using std::endl; using std::vector; template< typename T > struct Type { private: template< typename U > struct UnConst { typedef U Result; enum { isConst = 0 }; }; template< typename U > struct UnConst< const U > { typedef U Result; enum { isConst = 1 }; }; template< typename U > struct UnConst< const U & > { typedef U & Result; enum { isConst = 1 }; }; public: typedef typename UnConst< T >::Result NonConstType; enum { isConst = UnConst< T >::isConst }; }; int main() { cout << Type< vector< const int >::value_type >::isConst << endl; return 0; } 結論是 VC 會自己把 template 去 const ... 吧 -- 自High筆記(半荒廢) http://legnaleurc.blogspot.com/ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 123.205.248.119

12/20 14:41, , 1F
可能性非常之高 @@
12/20 14:41, 1F
文章代碼(AID): #1BBGEJrK (C_and_CPP)
文章代碼(AID): #1BBGEJrK (C_and_CPP)