Suppose you need to somehow allocate some small code to call it in many places a couple of functions. Actually I found for myself a couple of options - a template in a separate namespace or a good old macro.
Interested in what professional programmers think about these options and, perhaps, will advise something else?
// вариант №1 отдельное пространство имен, где собирается весь утилитарный хлам namespace makemove { template <class T> inline void SWAP(T & a, T & b) noexcept { T t = a; a = b; b = t; } } void board15::makemove(const directions & dir) { using namespace makemove; //#define SWAP(a,b) {int t = (a); (a) = (b); (b) = t;} // вариант № 2 switch (dir) { case UP: // там внутри не самые короткие выражения, нет смысла их приводить SWAP(board[/* ... */], board[/* ... */]); current_pos_y += 1; break; case DOWN: SWAP(board[/* ... */], board[/* ... */]); current_pos_y -= 1; break; case LEFT: SWAP(board[/* ... */], board[/* ... */]); current_pos_x += 1; break; case RIGHT: SWAP(board[/* ... */], board[/* ... */]); current_pos_x -= 1; break; } //#undef SWAP return; } PS in std :: swap from "utility" it is not necessary to poke, it does not concern a question.