Search code examples
c++boostptr-vector

Get template parameter from boost::ptr_vector


From boost::ptr_vector<T> I am trying to get T, but boost::ptr_vector<T>::value_type seems to be T*. How can I get T?

Looking at the doc, I see:

typedef  T*                                           value_type;
typedef  T&                                           reference;
typedef  const T&                                     const_reference;

None of which help...


Solution

  • Since you're using Boost, you can use boost::remove_pointer to get the pointed-to type.

    boost::remove_pointer<boost::ptr_vector<T>::value_type>::type
    

    will evaluate to T.

    If you can use C++11 features, you could use std::remove_pointer in the same manner as Boost's version.