I wrote a template function
template <class T>
size_t get_size(T const &vec)
{
if constexpr (std::is_pointer<T>::value)
{
std::cout << "pointer" << std::endl;
return vec->size();
}
else
{
std::cout << "not pointer" << std::endl;
return vec.size();
}
}
which determines the size of either the vec, or first references the underlying data and then calles size upon it. Now I wanted to add the case that vec is actually a shared_pointer. But how can I figure that out? Executing
std::shared_ptr<Vector> vec = std::make_shared<Vector>(Vector({1, 2, 3}));
std::cout << typeid(vec).name() << std::endl;
gives me St10shared_ptrISt6vectorIiSaIiEEE
as an output.
My idea was to somehow destructure the type to access the outermoste layer of the type. In that case I could add a if else case
using the is_same
function.
Thanks for your help!