To check for a pointer, you can use std::is_pointer
. To check for an iterator, you can define your own is_iterator
trait as described in this answer. If you combine these two, you get:
#include <type_traits>
#include <iterator>
template<typename T, typename = void>
struct is_iterator
{
static constexpr bool value = false;
};
template<typename T>
struct is_iterator<T, typename std::enable_if<
!std::is_same<typename std::iterator_traits<T>::value_type, void>::value>::type>
{
static constexpr bool value = true;
};
template<class T>
void test(T t) {
static_assert(std::is_pointer<T>::value || is_iterator<T>::value,
"T must be pointer or iterator");
}