C++ Get name of type in template

后端 未结 10 2130
天涯浪人
天涯浪人 2020-11-27 11:28

I\'m writing some template classes for parseing some text data files, and as such it is likly the great majority of parse errors will be due to errors in the data file, whic

10条回答
  •  再見小時候
    2020-11-27 11:56

    If you'd like a pretty_name, Logan Capaldo's solution can't deal with complex data structure: REGISTER_PARSE_TYPE(map) and typeid(map).name() gives me a result of St3mapIiiSt4lessIiESaISt4pairIKiiEEE

    There is another interesting answer using unordered_map or map comes from https://en.cppreference.com/w/cpp/types/type_index.

    #include 
    #include 
    #include 
    #include 
    using namespace std;
    unordered_map types_map_;
    
    int main(){
        types_map_[typeid(int)]="int";
        types_map_[typeid(float)]="float";
        types_map_[typeid(map)]="map";
    
        map mp;
        cout<)]<

提交回复
热议问题