How would I define a function that takes as input an iterator over any type of STL container, but only to those of a specific templated type. For example:
Any iterator o
You could use a SFINAE construct such as boost::enable_if which verifies if the nested typedef iterator::value_type
is indeed of the appropriate type.
template
typename boost::enable_if >::type
f(Iterator i)
{
/* ... */
}
int main()
{
std::list l;
std::vector v;
f(l.begin()); // OK
f(v.begin()); // OK
std::vector v2;
f(v2.begin()); /* Illegal */
}
This is what I understand from "a function that takes as input an iterator over any type of STL container, but only to those of a specific templated type", but my interpretation might be wrong.