#include <iostream>
#include <vector>
#include <string>
using namespace std;

template <class SOMETYPE>
void swapvars (SOMETYPE &x, SOMETYPE &y)
{
    SOMETYPE temp = x;
    x = y;
    y = temp;
}

template <class T>
T twice (const T x) {
    return x + x;
}

template <class T>
T maximum (const vector<T> V) {
    if (V.size() == 0) {
        cout << "No maximum of empty vector.\n";
        return T();
    }
    T max = V[0];
    for (int i = 1; i < (int) V.size(); i++) {
    	// max contains the maximum from V[0] up to but not including V[i]
        if (V[i] > max) max = V[i];
        // max contains the maximum of v[0] through V[i]
    }
    return max;
}

int main () {
    int a = 1, b = 2;
    double A = 1.5, B = 2.5;
    string c = "one", d = "two";

    swap (a, b);
    cout << a << ", " << b << endl;
    swap (A, B);
    cout << A << ", " << B << endl;
    swap (c, d);
    cout << c << ", " << d << endl;


    cout << twice (3) << endl;
    cout << twice (2.5) << endl;
    string bye = "Bye ";
    cout << twice (bye) << endl;


    int X_init[] = {35, 2, -6, 7, 100, 12, 1, 12, -200, 0};
    vector<int> X  (X_init, X_init+10);
    cout << maximum(X) << endl;

    double Y_init[] = {3.14159, 2.71828, -100, 6.02e23, 32.0};
    vector<double> Y (Y_init, Y_init+5);
    cout << maximum(Y) << endl;

    string Z_init[] = {"hello", "goodbye"};
    vector<string> Z (Z_init, Z_init+2);
    cout << maximum(Z) << endl;

    vector <char> W;
    cout << maximum(W) << endl;

    return 0;
}

