Well, in the simplest case scenario it could look something like this:
#include <type_traits>
#include <vector>
#include <list>
#include <cstdio>
template <typename T>
typename std::enable_if<
std::is_same<typename std::vector<typename T::value_type>::iterator, T>::value
, void>::type
do_something (T begin, T end)
{
std::printf ("Got vector iterators!\n");
}
template <typename T>
typename std::enable_if<
!std::is_same<typename std::vector<typename T::value_type>::iterator, T>::value
, void>::type
do_something (T begin, T end)
{
std::printf ("Got something other than vector iterators!\n");
}
template <typename T>
typename std::enable_if<std::is_pod<T>::value, void>::type
do_something (T begin, T end)
{
std::printf ("Got some POD iterators!\n");
}
int main()
{
std::vector<int> ivec;
std::list<int> ilist;
char cdata[64];
do_something (ivec.begin (), ivec.end ());
do_something (ilist.begin (), ilist.end ());
do_something (&cdata[0], cdata + 32);
return 0;
}
But the real problem comes when someone decides to use allocator different from default one. Since you want to check iterator against some well known type, not a well known template, then you can basically use this and possibly extend it with some allocators that you are aware of. Otherwise, a template instantiated with different types is a different type, and I am not sure if there is a way to test if a type is an instance of template specialized with some arbitrary parameter, there is probably no such way.
On the other hand, you may solve this problem differently. For example, what difference it makes whether this is std::vector<...>
iterator or not? It might make sense to check whether it is random access or not, etc.
UPDATE:
For continuously laid out memory, I'd say the best bet is to use iterator traits and check for random access tag. For example:
#include <type_traits>
#include <functional>
#include <vector>
#include <list>
#include <cstdio>
template <typename T>
struct is_random_access_iterator : std::is_same<
typename std::iterator_traits<T>::iterator_category
, std::random_access_iterator_tag>
{};
template <typename T>
typename std::enable_if<is_random_access_iterator<T>::value>::type
do_something (T begin, T end)
{
std::printf ("Random access granted!\n");
}
template <typename T>
typename std::enable_if<!is_random_access_iterator<T>::value>::type
do_something (T begin, T end)
{
std::printf ("No random access for us today!\n");
}
int main()
{
std::vector<int> ivec;
std::list<int> ilist;
char cdata[32];
do_something (ivec.begin (), ivec.end ());
do_something (ilist.begin (), ilist.end ());
do_something (&cdata[0], cdata + sizeof (cdata) / sizeof (cdata[0]));
return 0;
}
This one will be definitely simpler and even more solid than checking against std::vector
with allocators. However, even in this case someone can fool you if they really want, buy providing you random access iterator that provides seamless access to different chunks of memory, and you will have big problems once you convert that into a pointer use pointer arithmetics rather than iterator's overloaded operators. You can protect yourself against that only by comparing memory addresses while changing both raw pointer and iterator, but there is no juice.
Hope it helps.