Я считаю, что это синтаксис, который вы ищете
/* pass parameter by reference in case you wanna change it */
inline void do_something(some_type &x/* , other parameters that any of the functions might need */)
{
++x; /* example, you can do anything */
}
inline void do_something(some_other_type &y/* , other parameters that any of the functions might need */)
{
y = y * y; /* example, you can do anything */
}
template<typename T> void very_large_function(T t)
{
// ... common code ...
do_something(t);
// ... more common code ...
}
, если ваши if
операторы также имеют else
, вы можете сделать это вместо
// final else
template<typename T>
inline void do_something(T &t) {
t = t * 2; // example
}
inline void do_something(some_type &x)
{
++x; // example
}
inline void do_something(some_other_type &y)
{
y = y * y; // example
}
template<typename T> void very_large_function(T t)
{
// ... common code ...
do_something(t);
// ... more common code ...
}