This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
return-value policy question
- From: Nathan Myers <ncm-nospam at cantrip dot org>
- To: libstdc++ at gcc dot gnu dot org
- Date: Mon, 28 Apr 2003 22:30:12 -0700
- Subject: return-value policy question
In much of the library implementation I find code like that in
streambuf::sputc :
int_type __ret;
if (_M_out_cur < _M_out_end)
{
*_M_out_cur = __c;
_M_move_out_cur(1);
__ret = traits_type::to_int_type(__c);
}
else
__ret = this->overflow(traits_type::to_int_type(__c));
return __ret;
instead of the simpler and more elegant
if (_M_out_cur < _M_out_end)
{
*_M_out_cur = __c;
_M_move_out_cur(1);
return traits_type::to_int_type(__c);
}
return this->overflow(traits_type::to_int_type(__c));
or the even simpler and more traditional
return (_M_out_cur < _M_out_end) ?
traits_type::to_int_type(*_M_out_cur++ = __c) :
this->overflow(traits_type::to_int_type(__c));
Is there some objective reason to prefer assigning a variable and
sharing the "return" statement, over just returning when it's time?
Is it a leftover optimization? Was it ever optimal? Is it now?
Nathan Myers
ncm-nospam at cantrip dot org