Hi I'm wondering how you would write a function that could iterate through any stl container so it didn't matter what you were using e.g list, vector, deque and found an item that matched in that list so the function declaration would look something like this
template <class TypeList, class Type> Type findInContainer( TypeList< Type > list, Type item ) //where the return value is the index of where it was found template <class TypeList, class Type> int findInContainer( TypeList< Type > list, Type item, Type& itemFound ) //My code later on both filled with values std::deque< int > dequeContainer; std::vector< std::string > vectorContainer int foundNumber = -1; int index = findInContainer( dequeContainer, 20, foundNumber );
I was wondering how this is achieved using templates.
Returning the item found would be used for some property in the item lets say it was a list of objects that have an id and it was trying to find the item based on the id
Any help would be appreciated.
Edited 4 Years Ago by _Nestor: n/a