I think about overloading std::is_pointer
in C++11 to yield true for std::shared_ptr<T>
as well, since the latter behaves very much as a T*
.
#include <type_traits>
namespace std {
template <typename T> struct is_pointer<shared_ptr<T>> : std::true_type {};
template <typename T> struct is_pointer<shared_ptr<T const>> : std::true_type {};
}
I wonder why this overload has not already been included in the standard implementation. Is there a pitfall that I'm overlooking?
As an alternative one could of course introduce a new trait is_shared_ptr<T>
.
Actually, I tried the following code in the first place:
template <typename T>
struct is_pointer<shared_ptr<typename std::remove_cv<T>::type>>
: std::true_type
{};
which does not compile with GCC 4.7 due to
error: template parameters not used in partial specialization:
error: ‘T’