jeudi 14 mai 2020

c++ Replace macro fuction that calls a method of an object

I am working on a code that can't be rewritten completely. Somewhere in the code I have this snippet

#define ITERATE_AND_CALL(vectorOfObjs, function)\
    do\
        for(auto & v : vectorOfObjs)\
        {\
            v.function();\
        }\
    while(false)\

later on in the code it is called like this in several places

std::vector<Foo> vecOfFoos;
ITERATE_AND_CALL(vecOfFoos, foo)

Is there anyway to do this without macros?

Aucun commentaire:

Enregistrer un commentaire