#include #include #include #include #include #include #include using namespace std; //----------------------------------------------- // A range for simplifies the code //----------------------------------------------- template void dumpContainer(const T c) { for (auto el : c) { cout << el << ' '; } cout << endl; } //----------------------------------------------- // A function templated with a constant //----------------------------------------------- template void dumpNativeArray(const T c[]) { for (int i=0; i stringVec = {"one", "two", "three"}; deque intDeque = {1, 2, 3}; list floatList = {1.0, 2.0, 3.0}; forward_list doubleForwardList = {1.0, 2.0, 3.0}; dumpContainer(str); dumpContainer(stringVec); dumpContainer(intDeque); dumpContainer(floatList); dumpContainer(doubleForwardList); //---------------------------------------------------------------- // The array class solves the looping in a subroutine issue //---------------------------------------------------------------- array arrayArray = {1, 2, 3}; // The templated procedure will know the inferred type, // array, and so will know the length of the array dumpContainer(arrayArray); //---------------------------------------------------------------- // A related templating trick... //---------------------------------------------------------------- int nativeArray[3] = {1,2,3}; dumpNativeArray(nativeArray); return 0; }