'Can I assign and return without a utility routine?

Is there a way to "assign and return" without creating a utility routine? Here's my code:

static int& do_work_(const int* p, int& result)
{
   result = (*p) * 10;
   return result;
}

template<typename T>
T& assign(const T* p, T& result)
{
   result = *p;
   return result;
}

int& do_work(const int* p, bool cond, int& result)
{
   return cond ? do_work_(p, result) : assign(p, result);
}

Can I implement do_work() without the assign() utility?


The reason for the do_work() signature is that it's a nice convenience:

const int value=1;
int i, j;
if (do_work(&value, true, i) == do_work(&value, false, j)) {}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source