vendredi 30 novembre 2018

Repeated function calls with a single argument changing in C++

I have a repeated pattern in my code

enum { OUTSIDE_BSPH = 0, INSIDE_BSPH = 1 };
bool bsph = true;
//...
bool = false;

f(OUTSIDE_BSPH, arg1, arg2, arg3, arg4, arg5);
if (bsph) {
  f(INSIDE_BSPH, arg1, arg2, arg3, arg4, arg5);
}

g(OUTSIDE_BSPH, arg6, arg7, arg8);
if (bsph) {
  g(INSIDE_BSPH, arg6, arg7, arg8);
}

h(OUTSIDE_BSPH, arg3, arg4, arg5);
if (bsph) {
  h(INSIDE_BSPH, arg3, arg4, arg5);
}
// ...

that I would like to simplify. Could it be transformed into something like

caller(bsph, f, arg1, arg2, arg3, arg4, arg5);

caller(bsph, g, arg6, arg7, arg8);

caller(bsph, h, arg3, arg4, arg5);

// ...

without using pointers?

Aucun commentaire:

Enregistrer un commentaire