0
假設我有一個由表達式typeid(int(&(*)())[10]).raw_name()
返回的字符串。在Visual C++中,它返回.P6AAAY09HXZ
。我怎樣才能獲得原始的類型表達式,或者至少可以接近它?我已經試過UnDecorateSymbolName,但它返回輸入。看起來這個函數只適用於裝飾函數名稱。是否有可能修改返回的代碼,以便函數可以接受它?從type_info.raw_name解除字符串
假設我有一個由表達式typeid(int(&(*)())[10]).raw_name()
返回的字符串。在Visual C++中,它返回.P6AAAY09HXZ
。我怎樣才能獲得原始的類型表達式,或者至少可以接近它?我已經試過UnDecorateSymbolName,但它返回輸入。看起來這個函數只適用於裝飾函數名稱。是否有可能修改返回的代碼,以便函數可以接受它?從type_info.raw_name解除字符串
您可以使用boost::core::demangle
或boost::typeindex
:
#include <boost/core/demangle.hpp>
#include <boost/type_index.hpp>
using type = int(&(*)())[10];
auto name = typeid(type).name();
std::cout << boost::core::demangle(name) << '\n';
std::cout << boost::typeindex::type_id<type>().pretty_name() << '\n';
當然有趣,但你知道它會爲Visual C++修飾的名工作?根據Boost的資料,函數使用「cxxabi.h」,這在Visual C++實現中可能會丟失。 – IllidanS4