mercredi 1 juillet 2015

Make template function for nested container

I'm trying to make a generic test function that takes a container such as list, set or vector, and returns nested container: list of lists, set of sets, vector of vectors. Non-generic functions look like this:

vector<vector<string>> test(vector<string>& in_container)
{
    vector<vector<string>> out_continer;

    // out_continer will be filed using values from in_container

    return out_continer;
}

list<list<int>> test(list<int>& in_container)
{
    list<list<int>> out_continer;

    // out_continer will be filed using values from in_container

    return out_continer;
}

set<set<float>> test(set<float>& in_container)
{
    set<set<float>> out_continer;

    // out_continer will be filed using values from in_container

    return out_continer;
}

But I dont know how to make one template test function that would be equivalent to these separate test examples.

Aucun commentaire:

Enregistrer un commentaire