On Sun, 05 Oct 2008 06:42:07 +0200, Chris Cason
<del### [at] deletethistoopovrayorg> wrote:
>
> If he wants brevity he could also code it like this:
>
> for (int i = 0; i < c.size(); i++)
> out.append(c[i] ? "1" : "0");
>
> which is just as valid and avoids running the if/else together.
The compiler would likely warn about the signed/unsigned comparison in the
loop condition. The proper type for the index is Codeword::size_type.
He could also skip the conditional in the loop body entirely:
typedef std::vector<bool> Codeword;
std::string codeword( Codeword const& c )
{
std::string out;
for( Codeword::size_type i = 0; i < c.size(); ++i )
out += ( '0' + int(c[i]) );
return out;
}
--
FE
Post a reply to this message
|