S
Simon Elliott
Given a template function:
template <class T>
void foo(T& value)
{
// do something with value
}
Is there any way I can tell whether the type T is an STL container?
For example I'd like, within foo(), to treat "value" differently in
these two cases.
typedef std::vector<bar> barVector;
barVector myBarVector;
foo(myBarVector);
int i13 = 13;
foo(i13);
Normally I'd do a dynamic_cast to determine the type of value, but
because foo() doesn't know the type of the STL container, I can't do it:
template <class T>
void foo(T& value)
{
std::vector<???> test = dynamic_cast<std::vector<???>>(value);
if (test)
{
// It's a vector of ???
}
}
.... but if we're writing generic code, I don't know in advance what
'???' is.
template <class T>
void foo(T& value)
{
// do something with value
}
Is there any way I can tell whether the type T is an STL container?
For example I'd like, within foo(), to treat "value" differently in
these two cases.
typedef std::vector<bar> barVector;
barVector myBarVector;
foo(myBarVector);
int i13 = 13;
foo(i13);
Normally I'd do a dynamic_cast to determine the type of value, but
because foo() doesn't know the type of the STL container, I can't do it:
template <class T>
void foo(T& value)
{
std::vector<???> test = dynamic_cast<std::vector<???>>(value);
if (test)
{
// It's a vector of ???
}
}
.... but if we're writing generic code, I don't know in advance what
'???' is.