Template Struct is_pointer

Struct Documentation

template<class T>
struct is_pointer

Type traits for validating if T is of type pointer or smart pointer.

In comparison to the existing type trait for pointer in the stdlib std::is_pointer<T> https://en.cppreference.com/w/cpp/types/is_pointer this trait is enhancing it for checking of smart pointer types as well. The valid pointer types are T*, std::shared_pointer<T> and std::unique_ptr<T>

Potential use cases are for static assert when passing a template parameter requiring this parameter to be of type pointer without specifying which type of pointer (raw, smart).

class MyType
{
  template<class T>
  MyType(T && arg)
  {
    static_assert(rcpputils::is_pointer<decltype(arg)>::value, "arg has to be a pointer");

    arg->do_stuff();  // with the assert above, this call is guaranteed to work.
  }
};

Public Static Attributes

static constexpr bool value = std::is_pointer<typename std::remove_reference<T>::type>::value || details::is_smart_pointer<typename std::remove_reference<T>::type>::value

Indicates whether this object is a pointer or smart pointer.