This is one way to do what you want. I took liberties of using variadics in the template parameters to save myself some typing, but ultimately the premise should hopefully be obvious:
#include <iostream>
#include <vector>
#include <cstdlib>
// forward declaration of template class
template <class T, template<class, class...> class Cont = std::vector, class... Args>
class VehiclesContainer;
// generic template for all T and all container types
template<class T, template<class, class...> class Cont = std::vector, class... Args>
std::ostream& operator <<(std::ostream&, const VehiclesContainer<T,Cont,Args...>&);
// specific template for only int and all container types
template<template<class, class...> class Cont = std::vector, class... Args>
std::ostream& operator << (std::ostream& os, const VehiclesContainer<int,Cont,Args...>& obj);
template <class T, template<class, class...> class Cont, class... Args>
class VehiclesContainer
{
public:
VehiclesContainer(std::initializer_list<T> l)
: container(l)
{};
// friend overloaded to `int` type
friend std::ostream& operator << <T,Cont,Args...>(std::ostream&,
const VehiclesContainer<T,Cont,Args...>&);
friend std::ostream& operator << <Cont, Args...>(std::ostream&,
const VehiclesContainer<int,Cont,Args...>&);
private:
Cont<T,Args...> container;
};
template<class T, template<class, class...> class Cont, class... Args>
std::ostream& operator <<(std::ostream& os, const VehiclesContainer<T,Cont,Args...>& obj)
{
if (obj.container.size() > 0)
{
os << obj.container.front();
for (auto it = std::next(obj.container.begin()); it != obj.container.end(); ++it)
os << ' ' << *it;
}
return os;
}
template<template<class, class...> class Cont, class... Args>
std::ostream& operator << (std::ostream& os, const VehiclesContainer<int,Cont,Args...>& obj)
{
if (obj.container.size() > 0)
{
os << obj.container.front();
for (auto it = std::next(obj.container.begin()); it != obj.container.end(); ++it)
os << '-' << *it;
}
return os;
}
int main()
{
VehiclesContainer<std::string> vcString { "Camero", "Corvette" };
VehiclesContainer<int> vcInt { 1,2,3 };
std::cout << vcString << '\n';
std::cout << vcInt << '\n';
return 0;
}
Output
Camero Corvette
1-2-3