#include <iostream>
template <typename T>
class Container1
{
// some implementation.
};
template <typename T>
class Container2
{
// some implementation.
};
template <typename type, typename container>
class CreateContainer
{
container<type> createContainer()
{
return container<type>();
}
container<const type> createConstContainer()
{
return container<const type>();
}
};
int main()
{
// doesn't compile.
CreateContainer<int, Container1> createContainer1;
CreateContainer<int, Container2> createContainer1;
// don't wanna do that:
// CreateContainer<Container2<int>, Container2<const int>, int> createContainer1;
// I might need to know the type inside the container (the int) so it's passed as well.
}
Consider this code, I'm creating a factory class that creates a normal containers as long as containers with const elements. Thats just an example. What I'm actually doing is that I want to return an iterator to some container and a const iterator to the same container. But the most of the code is not relevant to the problem so I made up an example. I wanna pass the containers as a template argument and then specify inside the factory class what arguments to pass to the container. If I don't pass the containers without their argument list, I'll have to pass the type inside the container, the normal container type and the const container type in the argument list of the factory class which is redundant.