只上代码了,尽在不言中吧:
#include <iostream>
#include <vector>
#include <map>
#include <typeinfo>
using namespace std;
template<typename T>
struct decltype_t
{
typedef T type;
};
#define DECLTYPE(expr) decltype_t<typeof(expr)>::type
int main()
{
std::map<int, int> m;
DECLTYPE(m) n;
DECLTYPE(m)::iterator it;
vector<int> intVtrA;
vector<DECLTYPE(intVtrA)::value_type> intVtrB;
cout<<typeid(intVtrA).name()<<endl;
cout<<typeid(intVtrB).name()<<endl;
return 1;
}
当然,最新的g++已经支持decltype的上述用法了。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)