所以如果 code 有到的話
目前過渡期解法就在 Compile Flag 加個 `-Dtypeof=decltype` 吧
範例:
g++ -std=c++0x -Dtypeof=decltype foo.cpp g++ -std=c++11 -Dtypeof=decltype foo.cpp
但如果 compiler 跟你抱怨 rvalue 不能轉 T& 的話...就用下面這有點邪門的解法吧
首先先在 code 頂端或著某個一定會 include 的 header 檔加入以下的 code
template<class T> struct unref { typedef T type; }; template<class T> struct unref<T&> { typedef T type; };
然後編譯選項換成下面這樣
g++ -std=c++0x -Dtypeof\(x\)="unref<decltype(x)>::type" foo.cpp g++ -std=c++11 -Dtypeof\(x\)="unref<decltype(x)>::type" foo.cpp
c++ 真的是越來越難學易用了XD...