In a couple of places, I am passing std::vector<LOCATION> or std::vector<map_id> into functions I write. For example:
void CreateBlastedTiles(const std::vector<LOCATION> &locs)
{
for (LOCATION loc : locs)
{
CreateBlastedTile(loc);
}
}
What I would prefer is to allow the function to accept any enumerable collection (vector, list, array, etc). This way the consumer of the function does not have to format their data into the arbitrary collection that I choose. However, I do want to constrain the function to only take collections of LOCATION.
In c#, I would use the Ienumerable interface like below:
void CreateBlastedTiles(IEnumerable<LOCATION> locs)
{
foreach (LOCATION loc in locs)
{
CreateBlastedTile(loc);
}
}
Online examples of using C++ templates are making my head spin and the book I was using doesn't cover them, since it is more of an intro to programming using C++. Some help would be appreciated, or you can tell me I just need to go buy an intermediate/advanced C++ book.