2009/2/19 Neal Becker
<ndbecker2@gmail.com>
Say I have:
template<typename in_t>
void F (in_t & in) ...
main() {
F<std::vector<int> > (...)
Suppose in_t is a templated container, such as std::vector<int>. Is there a
way within the function 'F' to get the generic container type, 'std::vector'
when F is instantiated with a specific e.g., std::vector<int>?
Maybe this will help you.
template <class Base, class Arg>
struct rebind;
template <template <class> class Base,
class T,
class Arg>
struct rebind<Base<T>, Arg> {
typedef Base<Arg> type;
};
template <class In>
void foo() {
// d is of type container<double>.
typename rebind<In, double>::type d;
}
template <class T>
struct container {};
int main() {
foo<container<int> >();
}
With vector and other STL containers it's a bit
harder, because they can have more than one
template parameter.
Roman Perepelitsa.