I was wondering if it\'s possible to write a template function that can take any other arbitrary template as a parameter and properly match the template name (i.e. not just the
You must have a metafunction that rebinds the type of container. Because you cannot just replace first template parameter:
vector > input;
vector > just_replaced;
vector > properly_rebound;
So, just write such a metafunction for known set of containers.
template class rebinder;
// example for vectors with standard allocator
template class rebinder< std::vector, T > {
public:
typedef std::vector type;
};
// example for lists with arbitrary allocator
template class rebinder< std::list, T > {
typedef typename A::template rebind::other AT; // rebind the allocator
public:
typedef std::list type; // rebind the list
};
// example for arrays
template class rebinder< std::array, T > {
public:
typedef std::array type;
};
Rules of rebinding may vary for different containers.
Also you might require a metafunction that extracts value type from arbitrary container, not only std-conformant (typedef *unspecified* value_type
)
template class get_value_type {
public:
typedef typename Container::value_type type; // common implementation
};
template class get_value_type< YourTrickyContainer > {
......
public:
typedef YZ type;
};