1

I need to categorise a template type in c++. One thing which I need to determine is whether a given type is a pointer - I was wondering if std::type_info::name() would be a suitable way to determine something like that.

This:

std::cout << typeid(T).name();

Appears to work - it appears a P is added before the object class-type, but is this a reliable (and correct) way to implement such a system?

Gamaray
  • 51
  • 8
  • 1
    `std::is_pointer`? (Although it has some limitations) – Paul Sanders Mar 24 '23 at 17:42
  • If you want to query information of the type, use the [``](https://en.cppreference.com/w/cpp/header/type_traits) library – NathanOliver Mar 24 '23 at 17:42
  • 1
    No, it's almost never correct to use `type_info`. It's more of a compiler debugging feature than something you should use in production code. It's non-portable and implementation defined, not guaranteed to stay the same between versions. You are already using templates, use proper mechanisms from `` – Yksisarvinen Mar 24 '23 at 17:44

0 Answers0