C++ Get name of type in template

后端 未结 10 2128
天涯浪人
天涯浪人 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 12:21

    As a rephrasing of Andrey's answer:

    The Boost TypeIndex library can be used to print names of types.

    Inside a template, this might read as follows

    #include 
    #include 
    
    template
    void printNameOfType() {
        std::cout << "Type of T: " 
                  << boost::typeindex::type_id().pretty_name() 
                  << std::endl;
    }
    

提交回复
热议问题