How to get a type in C++ when its template argument is the argument
2011-08-21 17:30
726 查看
First, we can't do :
Under some certain compilers' C++ dialect:
How ever, in GCC without 0x support we can do this by:
//It's wrong. template <typename U, typename T> U TypeFunc (U<T> p);template <typename U, typename T>U<T> TypeFunc2();//either is wrong__typeof (TypeFunc(b))<int> p1;__typeof (TypeFunc2(b)) p2
Under some certain compilers' C++ dialect:
//It's ok template < template <typename T> class U, typename V> U<V> typefunc( U<T> tmpl, V type); vector<int>b; char c; __typeof (typefunc(b,c)) u; //u's type is vector<char>In C++0x
//It's simple template <typename T> using V<T> = std::vector<T>; V<int> a;
How ever, in GCC without 0x support we can do this by:
template <typename T, template <typename T> class U, typename T2> U<T2> typefunc(U<T> a, T2 b); vector <int> a; char b; __typeof (typefunc(a, b)) c; //c's type is vector<char> by adding extra function template argument T
相关文章推荐
- [eZ publish] When a ezxml embed an video, how to get the ezxml object in the video embed template?
- How to organize the Template Files in C++
- R12: How to add Microsoft Excel as Type to the Create Template List of Values in BI Publisher (Doc ID 1343225.1)
- How to get the password text in a text with password property from another process using C++ - 用C++如何从不同进程获取密码框文本
- How to know is the file exist in C++ - 在C++中如何判断文件是否存在
- HOW TO: Change the Owner of a User-Defined Data Type That Is in Use in SQL Server 2000
- How to get the size of file in C++ - 在C++中如何获取文件的大小
- TIP: when you get a message in job log user [Dr. Who] is not authorized to view the log
- How to fix the problem that the Download rate is too Slow when doing "apt-get install"
- How to organize the Template Files in C++
- when the preview menu is diabled in BO, you can add this setting to enabled it
- 错误:created a ThreadLocal with key of type ……but failed to remove it when the web application was stopped. This is very likely to create a memory leak.
- he method get(Class, Serializable) in the type HibernateTemplate is not applicable for the arguments
- Programming Basic--why we need to add ' extern "C" ' in C++ program when calling the function which is complied by C complier?
- How to grant access to SQL logins on a standby database when the guest user is disabled in SQL Serve
- Resolution to the record count increasing of the file exported from DB when ‘0A’ is included in it
- [Drupal] How to get the real path of a node, no matter it is a path or a url alias
- Resolution to the record count increasing of the file exported from DB when ‘0A’ is included in it
- Resolution to the record count increasing of the file exported from DB when ‘0A’ is included in it
- C++ How to avoid the enter key when using cin and getline