rcpputils  master
C++ API providing common utilities and data structures.
Static Public Attributes | List of all members
rcpputils::is_pointer< T > Struct Template Reference

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

#include <pointer_traits.hpp>

Static Public Attributes

static constexpr bool value
 Indicates whether this object is a pointer or smart pointer. More...
 

Detailed Description

template<class T>
struct rcpputils::is_pointer< T >

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.
}
};

Member Data Documentation

◆ value

template<class T >
constexpr bool rcpputils::is_pointer< T >::value
staticconstexpr
Initial value:
details::is_smart_pointer<typename std::remove_reference<T>::type>::value

Indicates whether this object is a pointer or smart pointer.


The documentation for this struct was generated from the following file:
rcpputils::is_pointer
Type traits for validating if T is of type pointer or smart pointer.
Definition: pointer_traits.hpp:88
std::is_pointer
rcpputils::is_pointer::value
static constexpr bool value
Indicates whether this object is a pointer or smart pointer.
Definition: pointer_traits.hpp:91