c++templatestype-traitsconcept

How Can I Get Value_Type on both value and pointer by using template in c++?


template<class T>
    struct TypeInfo {
        using value_type = is_pointer<T>::value ? T * : T;
    };

This code is just pseudocode. I wanna find value type for each pointer and value. I'll using this like sizeof(TypeInfo<something>::value_type ). Can you help me?


Solution

  • You can do it like this:

    template<class T>
    struct TypeInfo {
        using value_type = std::remove_pointer_t<T>;
    };