vendredi 9 janvier 2015

Same outer structure only one difference between functions

I have many functions that do roughly the same apart from the what variable the modify



struct example
{
std::string name;
std::string category;
};

bool updateName(const ObjName &oldname, const ObjName& newName) ...
bool updateCategory(const ObjName &name, Category &cat)
{
// boost optional pointing to struct reference
auto obj = findOjb(name);
if (rule)
{
rule.get().category = cat; // variable name changes
return true;
}
return false;
}


What I am wondering is what I can do to combine the code ? I suspect it will involve templates maybe traites/functors but I am unsure of how to approach it any ideas ?


Aucun commentaire:

Enregistrer un commentaire